Alice has a chess board with n rows and m columns. There are k obstacles on the board placed exactly in cells. Two different rooks form a bad pair if they stay in one row or in one column and there are no obstacles between them.
Alice want to know a maximal number of rooks which she can put on the board without bad pairs. Help her calculate this number.
You have to solve this problem for several test cases.
INPUT
The first line of the input contains a single integer tests - a number of test cases.
Each test case is given in the following format:
The first line contains a three integers n, m and k (1≤n,m≤500, 0≤k<n⋅m) - a number of rows, a number of columns and a number of obstacles.
Then follow k lines with obstacles description. The i-th of these lines contains two integers ri and ci (1≤ri≤n, 1≤ci≤m) - a row number of i-th obstacle and a column number of i-th obstacle.
Guaranteed that all obstacles are placed in the different cells.
Guaranteed that ∑testsi=1ni⋅mi≤250000.
OUTPUT
For each test case print a single integer number - an answer of the problem.