#K47122. Palindrome Queries

    ID: 28129 Type: Default 1000ms 256MiB

Palindrome Queries

Palindrome Queries

You are given two strings A and B, and a set of queries. Each query is a two‐character string that determines how you concatenate A and B. The query can be one of the following:

AA: Concatenate A with A. • AB: Concatenate A with B. • BA: Concatenate B with A. • BB: Concatenate B with B.

A string is considered a palindrome if it reads the same backward as forward, i.e., ( s = s^{R} ). For each query, output "YES" if the concatenated string is a palindrome, and "NO" otherwise.

For example, if A = "abc" and B = "cba", then for the query AB (which forms "abccba"), the output is "YES".

inputFormat

The input is read from stdin and consists of multiple lines as follows:

  1. The first line contains the string A.
  2. The second line contains the string B.
  3. The third line contains an integer Q, representing the number of queries.
  4. The next Q lines each contain a query, which is one of "AA", "AB", "BA", or "BB".

outputFormat

For each query, print a line to stdout with either "YES" or "NO" indicating whether the resulting concatenated string is a palindrome.## sample

abc
cba
4
AA
AB
BA
BB
NO

YES YES NO

</p>