Palindromic DNA
A
G
T
C
A
A DNA sequence is composed of a series of four possible nucleobases, namely Adenine, Guanine, Thymine and Cytosine; we will refer to each of these bases by their initial. For our purposes, nucleobases have an associated cyclic "order": is followed by , which in turn is followed by , which is followed by , which is followed by again. State-of-the-art research in genomics has revealed the startling fact 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 S and a series of subsets P_1,..., P_t of indices to characters (nucleobases) in S, and transform S so that each of the restrictions of the resulting string to P_1,..., P_t are palindromic. (The restriction of S to a subset P = {i_1, i_2,..., i_k} of indices, where 0 ≤ i_1 < i_2 <...< i_k < | S|, is the string S_i1S_i2...S_ik). It is possible to inspect any base of S at will, but only three transformations can be applied to a base:
Leave it unaltered.
Increase it by 1 in the cyclic order of nucleobases (e.g. turn
C
into
A
).
Decrease it by 1 (e.g. turn
T
into
G
).
Moreover, owing to limitations of current technology, it is impossible to modify two bases in consecutive positions of the sequence. Is our goal achievable?
AGTAT
GG
GG
GTG
By way of example, consider DNA sequence . Number positions starting from 0, and suppose we have the three subsets P_1 = {1, 4}, P_2 = {0, 1} and 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 and P_3 are , and , respectively; all of them are palindromic.
CATGC
T
One case where no solution is possible is when the string is , and we require the subsequences determined by positions {0, 3} and {3, 4} be palindromic. Here, characters 3, 0 and 4 would all need to become a . But this entails modifying consecutive characters 3 and 4, which is not allowed.
Input
ACGT
The first line of each test case has two integers N and T (1 ≤ N ≤ 10 000, 1 ≤ T ≤ 6 000), the sequence length and number of subsets to consider. The next line contains the DNA sequence of length N, all of whose characters are in . The subsets are described by the following T lines. Each line starts by "L:", where L (0 ≤ L ≤ N) is the number of positions in the subset, and is followed by T distinct integers between 0 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'.
Output
In a single line per test case, print 'YES' if the task is solvable and 'NO' otherwise.