시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 256 MB50211982.609%

문제

You are working for an agency that selects the best software engineers from Belgium, the Netherlands and Luxembourg for employment at various international companies. Given the very large number of excellent software engineers these countries have to offer, the agency has charged you to develop a tool that quickly selects the best candidates available from the agency’s files.

Before a software engineer is included in the agency’s files, he has to undergo extensive testing. Based on these tests, all software engineers are ranked on three essential skills: communication skills, programming skills, and algorithmic knowledge. The software engineer with rank one in the category algorithmic knowledge is the best algorithmic expert in the files, with rank two the second best, etcetera.

For potential customers, your tool needs to process the agency’s files and produce a shortlist of the potentially most interesting candidates. A software engineer is a potential candidate that is to be put on this shortlist if there is no other software engineer in the files that scores better on all three skills. That is, an engineer is to be put on the shortlist if there is no other software engineer that has better communication skills, better programming skills, and more algorithmic knowledge.

입력

On the first line one positive number: the number of test cases, at most 100. After that per test case:

  • one line with a single integer n (1 ≤ n ≤ 100 000): the number of software engineers in the agency’s files.
  • n lines, each with three space-separated integers r1, r2 and r3 (1 ≤ r1, r2, r3 ≤ n): the rank of each software engineer from the files with respect to his communication skills, programming skills and algorithmic knowledge, respectively.

For each skill s and each rank x between 1 and n, there is exactly one engineer with rs = x.

출력

Per test case:

  • one line with a single integer: the number of candidates on the shortlist.

예제 입력 1

3
3
2 3 2
3 2 3
1 1 1
3
1 2 3
2 3 1
3 1 2
10
1 7 10
3 9 7
2 2 9
5 10 8
4 3 5
7 5 2
6 1 3
9 6 6
8 4 4
10 8 1

예제 출력 1

1
3
7