Duplicates
시간 제한2초메모리 제한1024 MB
각 값이 1부터 n인 n x n 행렬이 주어질 때, 모든 행과 열이 같은 값을 두 번 이상 포함하도록 고쳐야 하는 최소 항목 수를 구한다.
문제
We say that a number sequence contains duplicates if there is an element that appears more than once in the sequence. Formally, a sequence contains duplicates if there exist two indices and such that and .
You are given an matrix . Each entry in is an integer between and , inclusive. You can modify zero or more entries in to arbitrary integers between and , inclusive. Different entries can be modified to different integers.
Your task is to make modifications to entries of such that all of the following hold:
- For each row , the sequence contains duplicates.
- For each column , the sequence contains duplicates.
Compute the minimum number of entries that need to be modified to achieve this. Also, find one possible set of modifications to do it. For each modification, you have to specify which entry will be modified and to what value. Note that the minimum number of entries to be modified can be zero when the given matrix already satisfies the conditions above.
입력
The first line of input contains one integer () representing the number of test cases. After that, test cases follow. Each of them is presented as follows.
The first line of a test case contains one integer (). Each of the next lines contains integers. The -th integer in the -th line denotes ().
The sum of across all test cases in one input file does not exceed .
출력
For each test case, output a set of modifications in the following format.
On the first line, output an integer representing the minimum number of entries that need to be modified. On each of the next lines, output three integers , , and . This represents a single modification where the entry will be modified to . All of the three integers must be between and , inclusive.
If there are multiple solutions, you can output any of them.