using System; using System.Collections.Generic; using System.Linq; using static System.Console; class Program { static void Main() { ReadLine(); var N = 60; var K = 500; var L = ReadLine().Split().Select(int.Parse).ToArray(); var map = new bool[N, N]; for (int i = 0; i < N; i++) { var line = ReadLine(); for (int j = 0; j < N; j++) { map[i, j] = line[j] == '0'; } } var cmd = new int[K, 4]; for (int k = 0; k < K; k++) { var x = 0; var a = 0; var b = 0; var c = 0; var d = 0; for (int i = 0; i < N; i++) { var n = 0; for (int l = 0; l < L[k]; l++) { n += map[i, l] ? 0 : 1; } if (x < n) { x = n; a = c = i; b = 0; d = L[k] - 1; } for (int j = 0; j < N - L[k]; j++) { n -= map[i, j] ? 0 : 1; n += map[i, j + L[k]] ? 0 : 1; if (x < n) { x = n; a = c = i; b = j + 1; d = j + L[k]; } } } for (int j = 0; j < N; j++) { var n = 0; for (int l = 0; l < L[k]; l++) { n += map[l, j] ? 0 : 1; } if (x < n) { x = n; b = d = j; a = 0; c = L[k] - 1; } for (int i = 0; i < N - L[k]; i++) { n -= map[i, j] ? 0 : 1; n += map[i + L[k], j] ? 0 : 1; if (x < n) { x = n; b = d = j; a = i + 1; c = i + L[k]; } } } cmd[k, 0] = a; cmd[k, 1] = b; cmd[k, 2] = c; cmd[k, 3] = d; Act(map, a, b, c, d); } for (int i = 0; i < K; i++) { var a = cmd[i, 0]; var b = cmd[i, 1]; var c = cmd[i, 2]; var d = cmd[i, 3]; WriteLine($"{a + 1} {b + 1} {c + 1} {d + 1}"); } } static int BlackCount(bool[,] map, int a, int b, int c, int d) { var w = 0; if (a == c) { var x = Math.Min(b, d); var r = x + Math.Abs(b - d) + 1; for (int j = x; j < r; j++) { if (!map[a, j]) w++; } return w; } else { var y = Math.Min(a, c); var r = y + Math.Abs(a - c) + 1; for (int j = y; j < r; j++) { if (!map[j, b]) w++; } return w; } } static void Act(bool[,] map, int a, int b, int c, int d) { if (a == c) { var x = Math.Min(b, d); var r = x + Math.Abs(b - d) + 1; for (int j = x; j < r; j++) { map[a, j] = !map[a, j]; } } else { var y = Math.Min(a, c); var r = y + Math.Abs(a - c) + 1; for (int j = y; j < r; j++) { map[j, b] = !map[j, b]; } } } }