Flat Organization#11102

Flat Organization

3 seconds
128 megabytes
Hard

The company you are currently working for has decided to push the idea of flat organizational structure to its limits: for every pair of employees and , either has been assigned to directly supervise 's work or has been assigned to directly supervise 's work. Of course, it means that one might now have quite a lot of direct supervisors... which is great, because it makes an employee feel that their work truly is important to so many people rather than just to a single manager, the executives say.

There is always room for improvement, though. As the corporate goal for this year, the hierarchy will be revised to ensure that whenever a person is directly supervised by a person , then is also indirectly supervised by at the same time (we say that is indirectly supervised by if there exists n > 2 and a sequence c_1, \ldots, c_n such that c_1 = A, c_n = B and for each i < n, c_i is a direct supervisor of c_{i+1}).

It will ensure that any employee would think twice before deciding to abuse their position of power over anyone else, the executives say.

It should not come off as a surprise, though, that one might get somewhat annoyed if they learn that their supervisee has suddenly been appointed as their supervisor. And some such decisions might cause more resentment than others. Your task is to fulfill the corporate goal by reversing some of the dependencies between employees in such a way that the sum of resentments over these changes is as small as possible.

Input

The first line contains the number of test cases (1 \le z \le 100). The descriptions of the test cases follow.

The first line of every test case contains a single integer (1 \le n \le 2000) - the number of employees. The employees are numbered from to .

Then follow lines, containing integers d_{i,j} each (0 \le d_{i,j} \le 2 \cdot 10^9). If the employee is a direct supervisor of employee , then d_{i,j} > 0 describes the resentment that would feel if this dependency got reversed. Otherwise (that is, if is a direct supervisor of or if i = j), d_{i,j} = 0.

The total number of employees in all test cases does not exceed .

Output

For each test case, produce a solution which ensures that, for any pair of employees , (1 \le i, j \le n, i \ne j), either will be a direct supervisor of and will be an indirect supervisor of , or vice versa. Your solution should minimize the sum of resentments the employees will feel. If more than one such solution exists, you can print any of them.

If no solution exists, you should output a single line containing the word **"NO"**.

Otherwise, in the first line output a single word **"YES"**. In the second line, print two integers and - the number of dependencies between employees which you intend to reverse and the achieved sum of resentments, respectively. Note that you do not need to minimize .

Then output lines, each containing two integers - the identifiers of employees , (1 \le a, b \le n, a \ne b) such that is currently a direct supervisor of and their relationship should get reversed. You should never output the same pair of employees more than once.

Examples

Example 1

Loading
Loading