using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (h, w) = (c[0], c[1]); var g = SList(h); var m = new char[h][]; for (var i = 0; i < h; ++i) m[i] = g[i].ToCharArray(); var visited = new int[h][]; for (var i = 0; i < h; ++i) visited[i] = new int[w]; var vid = 1; for (var i = 0; i < h; ++i) for (var j = 0; j < w; ++j) { if (visited[i][j] != 0) continue; if (m[i][j] == '.') continue; visited[i][j] = vid; ++vid; var size = DFS(m, i, j, visited); WriteLine($"{i} {j} {size}"); if (size >= 4) DFS2(m, i, j, visited); } WriteLine(string.Join("\n", m.Select(mi => string.Concat(mi)))); } static int[] mx = new int[] { 0, 0, -1, 1 }; static int[] my = new int[] { -1, 1, 0, 0 }; static int DFS(char[][] m, int x, int y, int[][] visited) { var size = 1; for (var i = 0; i < 4; ++i) { var nx = x + mx[i]; var ny = y + my[i]; if (nx < 0 || nx >= m.Length || ny < 0 || ny >= m[0].Length) continue; if (m[x][y] != m[nx][ny]) continue; if (visited[nx][ny] != 0) continue; visited[nx][ny] = visited[x][y]; size += DFS(m, nx, ny, visited); } return size; } static void DFS2(char[][] m, int x, int y, int[][] visited) { m[x][y] = '.'; for (var i = 0; i < 4; ++i) { var nx = x + mx[i]; var ny = y + my[i]; if (nx < 0 || nx >= m.Length || ny < 0 || ny >= m[0].Length) continue; if (visited[x][y] != visited[nx][ny]) continue; if (m[nx][ny] == '.') continue; DFS2(m, nx, ny, visited); } } }