#include<bits/stdc++.h>
#define pf printf
#define sf scanf
#define DBG cout << "DEBUG " << endl;
using namespace std;
long n,m,c,d;
int grid[123][123],moves[123][123];
int dx[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int dy[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
bool isOk(int i, int j){
return (i>=0 && i<n && j>=0 && j < m && grid[i][j] != -5 && moves[i][j]>0);
}
void init(){
for(int i=0; i<=n; i++ ){
for(int j=0; j<=m; j++ ){
moves[i][j] = 2;
grid[i][j] = 0;
}
}
}
void dfs(int x, int y){
for( int i=0; i<8; i++){
int X = x + dx[i];
int Y = y + dy[i];
if(X == Y && X == 0 && !moves[X][Y])return;
cout << X << " " << Y << " " << isOk(X,Y) << endl;
if( isOk(X,Y) && ((abs(X-x) == c && abs(Y-y) == d) || ((abs(X-x) == d && abs(Y-y) == c))) ){
DBG
grid[X][Y]++;
moves[X][Y]--;
dfs(X,Y);
}
}
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","rt",stdin);
// freopen("out.txt","wt",stdout);
#endif
long kase;
cin >> kase;
for( int k=1; k<=kase; k++ ){
cin >> n >> m >> c >> d;
init();
int w; cin >> w;
for( int i=1; i<=w; i++ ){
int x,y; cin >> x >> y;
grid[x][y] = -5;
}
dfs(0,0);
cout << endl << endl;
for(int i=0; i<n; i++){
for(int j=0; j<m; j++ ){
cout << grid[i][j] << " " ;
}
cout << endl;
}
}
return 0;
}