A DNA sequence consists of a series of four possible nucleobases: Adenine, Guanine, Thymine, and Cytosine. We will refer to each base by its initial letter. For our purposes, the nucleobases have an associated cyclic order: is followed by , then , then , and then again .
Recent research in genomics has revealed that many diseases are caused by certain subsequences of bases not forming a palindromic sequence! Your mission as a leading researcher at ICPC laboratories is to take a DNA string and a series of subsets P_1, \ldots, P_t of indices of characters (nucleobases) in , and transform so that each of the restrictions of the resulting string to P_1, \ldots, P_t are palindromic. (The restriction of to a subset P = \{i_1, i_2, \ldots, i_k\} of indices, where 0 \leq i_1 < i_2 < \ldots < i_k < |S|, is the string S_{i_1} S_{i_2} \ldots S_{i_k}.)
It is possible to inspect any base of at will, but only three transformations can be applied to a base:
Leave it unaltered.
Increase it by in the cyclic order of nucleobases (e.g., turn into ).
Decrease it by in the cyclic order (e.g., turn into ).
Moreover, due to the limitations of current technology, it is impossible to modify two bases in consecutive positions of the sequence. Is our goal achievable?
The first line of each test case contains two integers and (1 \leq N \leq 10\,000, 1 \leq T \leq 6\,000), the sequence length and number of subsets to consider. The next line contains the DNA sequence of length , all of whose characters are in , , , .
The subsets are described by the following lines. Each line starts by "", where (0 \leq L \leq N) is the number of positions in the subset, followed by distinct integers between and N-1 in increasing order. Subsets may overlap partially or totally.
A blank line separates different test cases. The input file is terminated by a line containing 0 0.
For each test case, print in a single line YES if the task is solvable and NO otherwise.
AGTAT
P_1 = \{1, 4\}, P_2 = \{0, 1\}, P_3 = \{0, 2, 4\}
One solution is to increase the first character and decrease the last, yielding S' = GGTAG. The restrictions of S' to P_1, P_2, P_3 are GG, GG, GTG respectively; all are palindromic.
A case where no solution is possible: for CATGC and requiring subsequences at positions and to be palindromic. Here, characters , , and would all need to become . But this entails modifying consecutive characters and , which is not allowed.
Example 1