L. Straight
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

Dou Di Zhu (Fight the Landlord) is one of the most popular card games in China. The game uses a standard 54-card deck (52 regular cards + 2 jokers).

In Dou Di Zhu, a straight is a hand of at least 5 cards with consecutive ranks. The ranks in ascending order are: 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A. Note that 2 and the jokers cannot appear in a straight.

$$$tarjen$$$ currently holds 17 cards and loves straights. He wants to know the length of the longest straight he can play. Can you help him?

If no straight can be played, output 0.

Input

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases.

The next $$$t$$$ lines each contain 17 space-separated strings representing 17 cards. Each card is represented as follows:

  • 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A: the card of the corresponding rank
  • 2: the card ranked 2
  • SJ: the small joker
  • BJ: the big joker

Each regular card (A, 2$$$\sim$$$10, J, Q, K) appears at most 4 times per test case. The small and big jokers each appear at most once.

Output

For each test case, output a single integer — the length of the longest straight that can be played. If no straight exists (i.e., there is no consecutive rank sequence of length $$$\ge 5$$$), output 0.

Example
Input
2
3 4 5 6 7 3 4 5 6 7 2 2 2 2 SJ BJ A
2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 7
Output
5
0
Note

The ranks available for a straight are 3, 4, 5, 6, 7, and A. The longest consecutive sequence is $$$3, 4, 5, 6, 7$$$, with length $$$5$$$.