-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1421B Putting Bricks in the Wall.cpp
83 lines (80 loc) · 2.01 KB
/
1421B Putting Bricks in the Wall.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
author : MishkatIT
created : Tuesday 2023-06-20-19.48.21
*/
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(_) cout << #_ << " is " << _ << '\n';
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll N = 1e5 + 10;
const ll inf = 1e9;
const ll linf = 1e18;
int main()
{
fio;
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
char arr[n + 10][n + 10];
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
cin >> arr[i][j];
}
}
int s = 0, f = 0;
vector<pair<int, int>> ans;
if(arr[1][2] != arr[2][1])
{
if(arr[n][n - 1] != arr[n - 1][n])
{
cout << 2 << '\n';
arr[1][2] = arr[2][1];
cout << "1 2" << '\n';
if(arr[n][n - 1] == arr[1][2])
cout << n << ' ' << n - 1 << '\n';
else
cout << n - 1 << ' ' << n << '\n';
}
else
{
cout << 1 << '\n';
if(arr[1][2] == arr[n][n - 1])
cout << "1 2" << '\n';
else
cout << "2 1" << '\n';
}
}
else
{
if(arr[n][n - 1] != arr[n - 1][n])
{
cout << 1 << '\n';
if(arr[n][n - 1] == arr[1][2])
cout << n << ' ' << n - 1 << '\n';
else
cout << n - 1 << ' ' << n << '\n';
}
else
{
if(arr[1][2] == arr[n][n - 1])
{
cout << 2 << '\n';
cout << "1 2" << '\n';
cout << "2 1" << '\n';
}
else
{
cout << 0 << '\n';
}
}
}
}
return 0;
}