Boss Rush

No attempts yetTime limit1sMemory limit256 MB

Problem

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 MM such that you can defeat bosses 11 through MM in order. The game ends at the first boss you cannot defeat.

Input

The first line contains one integer TT, the number of test cases. Each test case begins with a line containing one integer NN, the number of bosses. Then NN groups of 3 lines follow, 3N3N lines in total. The three lines of group ii list the laser, rocket and psiotic weapons that work against boss ii, in that order. Each line starts with an integer WijW_{ij}, the number of weapons in category jj that work against boss ii, followed by WijW_{ij} weapon names separated by spaces.

  • 0<T1000 < T \le 100
  • 0<N1000 < N \le 100
  • 0<Wij100 < W_{ij} \le 10
  • Every weapon name has length 1 to 32.
  • A weapon name consists of uppercase and lowercase letters a to z only.
  • A weapon name always belongs to the same category.

Output

For each test case, print on one line the maximum number of bosses MM you can defeat.