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.
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:
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.
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.
23 4 5 6 7 3 4 5 6 7 2 2 2 2 SJ BJ A2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 7
5 0
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$$$.