CF1462B.Last Year's Substring

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Last Year's Substring

Polycarp has a string s[1n]s[1 \dots n] of length nn consisting of decimal digits. Polycarp performs the following operation with the string ss no more than once (i.e. he can perform operation 00 or 11 time):

  • Polycarp selects two numbers ii and jj (1ijn1 \leq i \leq j \leq n) and removes characters from the ss string at the positions i,i+1,i+2,,ji, i+1, i+2, \ldots, j (i.e. removes substring s[ij]s[i \dots j]). More formally, Polycarp turns the string ss into the string $s_1 s_2 \ldots s_{i-1} s_{j+1} s_{j+2} \ldots s_{n}$.

For example, the string s=s ="20192020" Polycarp can turn into strings:

  • "2020" (in this case (i,j)=(3,6)(i, j)=(3, 6) or (i,j)=(1,4)(i, j)=(1, 4));
  • "2019220" (in this case (i,j)=(6,6)(i, j)=(6, 6));
  • "020" (in this case (i,j)=(1,5)(i, j)=(1, 5));
  • other operations are also possible, only a few of them are listed above.

Polycarp likes the string "2020" very much, so he is wondering if it is possible to turn the string ss into a string "2020" in no more than one operation? Note that you can perform zero operations.

Input

The first line contains a positive integer tt (1t10001 \leq t \leq 1000) — number of test cases in the test. Then tt test cases follow.

The first line of each test case contains an integer nn (4n2004 \leq n \leq 200) — length of the string ss. The next line contains a string ss of length nn consisting of decimal digits. It is allowed that the string ss starts with digit 0.

Output

For each test case, output on a separate line:

  • "YES" if Polycarp can turn the string ss into a string "2020" in no more than one operation (i.e. he can perform 00 or 11 operation);
  • "NO" otherwise.

You may print every letter of "YES" and "NO" in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Note

In the first test case, Polycarp could choose i=3i=3 and j=6j=6.

In the second test case, Polycarp could choose i=2i=2 and j=5j=5.

In the third test case, Polycarp did not perform any operations with the string.

Samples

6
8
20192020
8
22019020
4
2020
5
20002
6
729040
6
200200
YES
YES
YES
NO
NO
NO

在线编程 IDE

建议全屏模式获得最佳体验