#define _CRT_SECURE_NO_WARNiINGS #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define eps 0.000000001 #define LONG_INF 10000000000000000 #define GOLD 1.61803398874989484820458 #define MAX_MOD 1000000007 #define REP(i,n) for(long long i = 0;i < n;++i) #define cycle_per_sec 2806192512 tuple ans[1000]; vector gea[30]; int griding[100][100] = {}; int main() { int n, k; cin >> n >> k; REP(i, k) { int a; cin >> a; gea[a].push_back(i); } for (int i = 0; i < n; ++i) { string s; cin >> s; for (int q = 0; q < n; ++q) { griding[i][q] = s[q] - '0'; } } for (int i = 25; i >= 0; --i) { for (int tew = 0; tew < gea[i].size(); ++tew) { int a, b, c, d; int now_ans = -1000; for (int q = 0; q < n; ++q) { int pre_ans = 0; for (int j = 0; j < n; ++j) { if (griding[q][j] == 0) pre_ans--; else pre_ans++; if (j >= i) { if (griding[q][j - i] == 0) pre_ans++; else pre_ans--; } if (j+1 >= i) { if (pre_ans > now_ans) { now_ans = pre_ans; a = q; b = j - i + 1; c = q; d = j; } } } } for (int q = 0; q < n; ++q) { int pre_ans = 0; for (int j = 0; j < n; ++j) { if (griding[j][q] == 0) pre_ans--; else pre_ans++; if (j >= i) { if (griding[j - i][q] == 0) pre_ans++; else pre_ans--; } if (j + 1 >= i) { if (pre_ans > now_ans) { now_ans = pre_ans; a = j - i + 1; b = q; c = j; d = q; } } } } ans[gea[i][tew]] = make_tuple(a, b, c, d); } } for (int i = 0; i < k; ++i) { cout << get<0>(ans[i])+1 << " " << get<1>(ans[i])+1 << " " << get<2>(ans[i])+1 << " " << get<3>(ans[i])+1 << endl; } return 0; }