Given an image as a matrix of colored cells. Each cell has a value ranging from 0 to 65535 denoting its color. You have to apply flood-fill to a particular cell of the matrix with color c.
Two cells are considered as part of the same connected component if they have a common side and the same color value.
When you apply flood-fill to a particular cell, all its connected components are also applied the same color.
The first line contains an integer ‘T’, denoting the number of test cases.
For each test case the input has the following lines:
For each test case, the output contains n lines containing m space-separated integers denoting the resultant image.
4
2 2
1 0
0 0
1 1
2
3 3
1 1 0
1 1 1
1 1 1
0 0
3
4 4
1 2 1 2
2 2 2 1
1 2 2 1
2 1 2 1
0 1
3
2 2
1 2
2 1
0 1
3
1 2
2 2
3 3 0
3 3 3
3 3 3
1 3 1 2
3 3 3 1
1 3 3 1
2 1 3 1
1 3
2 1
1 <= T <= 10
1 <= n, m <= 500
0 <= color value <= 65535
0 <= x < n
0 <= y < m
0 <= c <= 65535