F. Apple
time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
Example
Input
2
5
1 2
3 4
5 3
3 2
4
3 4
5 1
4 4
1 3
3
1 2
1 3
3
1 1
2 3
3 1
Output
2
2
1
4
4
1
2