You are playing the new game Mega Man XIII-2. The boss fights are extremely hard. Your arsenal includes weapons such as the PowerLaser, the EvilRocket and the PsychTerror, and every weapon belongs to exactly one of three categories: laser, rocket and psiotic. To defeat one boss you must use three weapons, one from each category. Each boss is vulnerable only to some of the weapons, and you studied every boss in advance, so you know which weapons work against which boss.
You start the game with two copies of every weapon. The bosses appear in a fixed order. In each boss fight you choose one weapon from each category, and after the fight those three copies are worn out and cannot be used again.
Spending a weapon on an early boss can leave you stuck later, so choose carefully. Find the largest M such that you can defeat bosses 1 through M in order. The game ends at the first boss you cannot defeat.
The first line contains one integer T, the number of test cases. Each test case begins with a line containing one integer N, the number of bosses. Then N groups of 3 lines follow, 3N lines in total. The three lines of group i list the laser, rocket and psiotic weapons that work against boss i, in that order. Each line starts with an integer Wij, the number of weapons in category j that work against boss i, followed by Wij weapon names separated by spaces.
For each test case, print on one line the maximum number of bosses M you can defeat.