CF2182A.New Year String

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

New Year String

We will call a string consisting of characters 0, 2, 5, and/or 6 a New Year string if at least one of the two conditions is met:

  • it contains the string 2026 as a continuous substring;
  • it does not contain the string 2025 as a continuous substring.

For example, the strings 20252026, 21026, 20262026, 000 are New Year strings. The strings 2025, 20256, 20252025, 000202500020226 are not New Year strings.

You are given a string ss. You can perform the following operation any number of times (possibly zero):

  • choose a character in the string ss and replace it with 0, 2, 5, or 6 (you can choose any one of these four characters).

Calculate the minimum number of operations needed to make the string ss a New Year string.

Input

The first line contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases.

Each test case consists of two lines:

  • the first line contains one integer nn (4n204 \le n \le 20) — the number of characters in ss;
  • the second line contains ss — a sequence of nn characters 0, 2, 5, and/or 6.

Output

For each test case, output one integer — the minimum number of operations needed to make the string ss a New Year string.

Note

In the second example from the statement, you can replace the 22-nd character of the string with 2. Then the string will become 2225.

In the fifth example from the statement, you can replace the 44-th character with 6. Then the string will become 20262025.

In the sixth example from the statement, you can replace the 88-th character with 6. Then the string will become 202520266.

Samples

7
4
0000
4
2025
4
2026
8
20252026
8
20252025
9
202520256
9
202520265
0
1
0
0
1
1
0

在线编程 IDE

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