#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
#define MAXN 100
char map[MAXN][MAXN];
int R, C, N;
int dx[] = { 0,0,-1,1 };
int dy[] = { 1,-1,0,0 };
bool visited[MAXN][MAXN];
bool is_range(int x, int y) {
return (x >= 0 && y >= 0 && x < R && y < C);
}
int max_x;
bool flag;
vector<pair<int, int> > v;
void dfs(int x, int y) {
if (x == R - 1) {
flag = true;
}
v.push_back({ x,y });
visited[x][y] = true;
for (int k = 0; k < 4; k++) {
int nx = x + dx[k];
int ny = y + dy[k];
if (!is_range(nx, ny)) continue;
if (visited[nx][ny]) continue;
if (map[nx][ny] == 'x') dfs(nx, ny);
}
}
void drop(vector<pair<int,int> >& cluster) {
bool possible = true;
while (possible) {
for (int i = 0; i < cluster.size(); i++) {
map[cluster[i].first][cluster[i].second] = '.';
}
for (int i = 0; i < cluster.size(); i++) {
int tmp_x = cluster[i].first;
tmp_x++;
if (map[tmp_x][cluster[i].second] == 'x' || tmp_x == R) {
possible = false;
break;
}
}
if (possible) {
for (int i = 0; i < cluster.size(); i++) {
cluster[i].first += 1;
map[cluster[i].first][cluster[i].second] = 'x';
}
}
else {
for (int i = 0; i < cluster.size(); i++) {
map[cluster[i].first][cluster[i].second] = 'x';
}
}
}
}
void go(int idx, int i) {
memset(visited, false, sizeof(visited));
//왼쪽부터
if (idx % 2 == 0) {
for (int j = 0; j < C; j++) {
if (map[i][j] == 'x') {
map[i][j] = '.';
for (int k = 0; k < 4; k++) {
if ((idx + 1) % 2 == k) continue;
int nx = i + dx[k];
int ny = j + dy[k];
if (!is_range(nx, ny)) continue;
if (visited[nx][ny] || map[nx][ny] == '.') continue;
flag = false;
v.clear();
dfs(nx, ny);
if (!flag) {
drop(v);
}
}
break;
}
}
}
else {
for (int j = C - 1; j >= 0; j--) {
if (map[i][j] == 'x') {
map[i][j] = '.';
for (int k = 0; k < 4; k++) {
if ((idx + 1) % 2 == k) continue;
int nx = i + dx[k];
int ny = j + dy[k];
if (!is_range(nx, ny)) continue;
if (visited[nx][ny]||map[nx][ny]=='.') continue;
flag = false;
v.clear();
dfs(nx, ny);
if (!flag) {
drop(v);
}
}
break;
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> R >> C;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
cin >> map[i][j];
}
}
cin >> N;
for (int i = 0; i < N; i++) {
int idx;
cin >> idx;
idx = R - idx;
go(i, idx);
}
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
cout << map[i][j];
}
cout << "\n";
}
return 0;
}