//
// Stvoreno ENERGom o 11.04.24. 14:31:54
//
#include <bits/stdc++.h>
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define F first
#define fir first
#define S second
#define sec second
#define mp make_pair
#define MP make_pair
#define pb push_back
#define PB push_back
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
#ifdef Energy
#define DEBUG for (int _____DEBUG=1;_____DEBUG;_____DEBUG=0)
template<class ...Ts>
auto &PRNT(Ts ...ts) { return ((cerr << ts << " "), ...); }
#define LOG(...) PRNT(#__VA_ARGS__" ::",__VA_ARGS__)<<endl
#else
#define DEBUG while (0)
#define LOG(...)
#endif
const int max_n = 1e3+10, inf = 1000111222;
const int max_k=10;
int n,m,k;
bool f[max_k][max_n][max_n];
int dx[max_k];
int dy[max_k];
int known[max_n][max_n];
bool used[max_n][max_n];
inline bool ok_pos(int x,int y)
{
return 0<=x && x<n && 0<=y && y<m;
}
void dfs(int x,int y)
{
assert(known[x][y]!=-1);
used[x][y]=1;
for (int i=0;i<k;i++){
if (ok_pos(x+dx[i],y+dy[i]) && known[x][y]==0 && known[x+dx[i]][y+dy[i]]==-1 && !f[i][x+dx[i]][y+dy[i]]){
known[x+dx[i]][y+dy[i]]=0;
dfs(x+dx[i],y+dy[i]);
}
if (ok_pos(x-dx[i],y-dy[i]) && known[x][y]==1 && known[x-dx[i]][y-dy[i]]==-1 && !f[i][x][y]){
known[x-dx[i]][y-dy[i]]=1;
dfs(x-dx[i],y-dy[i]);
}
}
}
int main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m>>k;
for (int i=0;i<k;i++){
cin>>dx[i]>>dy[i];
// dx[i]*=-1;
// dy[i]*=-1;
int s;
cin>>s;
while (s--){
int a,b;
cin>>a>>b;
a--;
b--;
f[i][a][b]=1;
}
}
memset(known,-1,sizeof(known));
for (int i=0;i<k;i++){
for (int x=0;x<n;x++){
for (int y=0;y<m;y++){
if (ok_pos(x+dx[i],y+dy[i])){
if (f[i][x+dx[i]][y+dy[i]]){
known[x+dx[i]][y+dy[i]]=1;
known[x][y]=0;
}
}
if (f[i][x][y]){
known[x][y]=1;
if (ok_pos(x-dx[i],y-dy[i])){
known[x-dx[i]][y-dy[i]]=0;
}
}
}
}
}
for (int x=0;x<n;x++){
for (int y=0;y<m;y++){
if (known[x][y]!=-1 && !used[x][y]){
dfs(x,y);
}
}
}
for (int iter=0;iter<2;iter++){
for (int y=0;y<m;y++){
for (int x=0;x<n;x++){
int res=(known[x][y]==-1 ? iter : known[x][y]);
assert(res==0 || res==1);
cout<<(res==0?'.':'#');
}
cout<<"\n";
}
cout<<"\n";
}
exit(0);
}
/home/icpc/workspace/WF/WF21/cmake-build-debug/WF21
5 4 2
1 0 6 1 1 4 1 2 2 5 2 2 3 3 4
0 -1 7 1 1 4 1 5 2 2 3 3 4 4 4 5 4
#..#.
.#..#
.#...
..###
##.##
.##.#
.###.
#.###
Process finished with exit code 0