SP1442 CHAIN - Strange Food Chain

Description

There are 3 kinds of animals A,B and C. A can eat B,B can eat C,C can eat A. It's interesting,isn't it? Now we have n animals,numbered from 1 to n. Each of them is one of the 3 kinds of animals:A,B,C. Today Mary tells us k pieces of information about these n animals. Each piece has one of the two forms below: - 1 x y: It tells us the kind of x and y are the same. - 2 x y: It tells us x can eat y. Some of these k pieces are true, some are false. The piece is false if it satisfies one of the 3 conditions below, otherwise it's true. - X or Y in this piece is larger than n. - This piece tells us X can eat X. - This piece conflicts to some true piece before.

Input Format

The first line contains a single integer t.t blocks follow. To every block,the first line contains two integers n(1

Output Format

t lines,each contains a single integer - the number of false pieces in the corresponding block.

Explanation/Hint

Hint: The false pieces are the 1st,the 4th and the 5th ones. **Warning: large Input/Output data, be careful with certain languages.**