#K49352. Substring Palindrome Rearrangement

    ID: 28623 Type: Default 1000ms 256MiB

Substring Palindrome Rearrangement

Substring Palindrome Rearrangement

Given a string s composed of lowercase English letters and several queries, your task is to determine whether the substring s[l:r] (1-indexed) can be rearranged to form a palindrome.

A string is a palindrome if it reads the same backwards as forwards. A rearrangement is possible if and only if at most one character appears an odd number of times. In mathematical terms, if we denote by $f(c)$ the frequency of character $c$ in the substring, then the substring can be rearranged into a palindrome if

$$\sum_{c='a'}^{c='z'} \left[f(c) \bmod 2\right] \leq 1 $$

For each query, print YES if the substring can be rearranged into a palindrome, and NO otherwise.

inputFormat

The input consists of multiple test cases. The first line contains an integer T ($T \ge 1$), the number of test cases. For each test case, the first line contains two integers n and q where n is the length of the string and q is the number of queries. The next line contains the string s of length n. Each of the following q lines contains two integers l and r, representing the boundaries of the substring (1-indexed).

outputFormat

For each test case, output the result for each query on a new line. Print YES if the substring can be rearranged into a palindrome, and NO otherwise.

## sample
2
7 3
aabbcce
1 7
2 4
1 4
5 1
abcde
1 5
YES

YES YES NO

</p>