#C8754. Palindrome Substring Queries

    ID: 52771 Type: Default 1000ms 256MiB

Palindrome Substring Queries

Palindrome Substring Queries

You are given a string S and several queries. For each query, you are given two integers L and R. Your task is to determine whether the substring of S starting from index L and ending at index R (1-indexed) forms a palindrome.

A string is a palindrome if it reads the same forwards and backwards. In other words, a substring S[L...R] is a palindrome if and only if \[ S[L] S[L+1] \ldots S[R-1] S[R] = S[R] S[R-1] \ldots S[L+1] S[L] \]

For each query, print "Yes" if the corresponding substring is a palindrome, and "No" otherwise.

inputFormat

The first line contains an integer T, the number of test cases.

For each test case, the input is as follows:

  • A single line containing the string S.
  • A line containing an integer Q, the number of queries.
  • Then, Q lines follow, each containing two space-separated integers L and R, representing the indices of the substring.

Note: The indices are 1-indexed.

outputFormat

For each test case, output a single line with the results of the queries. For each query, print "Yes" if the substring is a palindrome, otherwise print "No". The answers for each test case should be printed on a separate line and the responses within a test case should be space-separated.

## sample
3
abacaba
3
1 3
2 4
1 7
level
2
1 5
2 4
abcd
2
1 2
1 4
Yes No Yes

Yes Yes No No

</p>