/* coder: ACboy date: 2010-3-16 result: 1A description: UVa 784 Maze Exploration */ #include <iostream> using namespace std; char data[40][90]; int vis[40][90]; int dx[] = {0, 0, 1, 1, -1, -1, 1, 0, -1}; int dy[] = {0, 1, 0, 1, -1, 1, -1, -1, 0}; void dfs(int x, int y) { data[x][y] = '#'; for (int i = 0; i < 9; ++i) { int newx = x + dx[i]; int newy = y + dy[i]; if (data[newx][newy] - '0' != 0 && newx >= 0 && newx < 40 && newy >= 0 && newy < 90 && data[newx][newy] == ' ' && !vis[newx][newy]) { data[newx][newy] = '#'; vis[newx][newy] = 1; dfs(newx, newy); } } } int main() { int n; #ifndef ONLINE_JUDGE freopen("784.txt", "r", stdin); #endif scanf("%d/n", &n); int i, j; for (i = 0; i < n; i++) { int count = 0; int c = 0; int pos[100][2]; memset(data, 0, sizeof(data)); memset(vis, 0, sizeof(vis)); while (gets(data[count++])) { if (data[count - 1][0] == '_') break; int len = strlen(data[count - 1]); for (j = 0; j < len; ++j) { if (data[count - 1][j] == '*') { pos[c][0] = count - 1; pos[c][1] = j; c++; } } } for (j = 0; j < c; ++j) { dfs(pos[j][0], pos[j][1]); } for (j = 0; j < count; ++j) { cout << data[j] << endl; } } return 0; }