#include<bits/stdc++.h>
using namespace std;
const int N = 510;
//bool a[N][N];
struct node
{
int x;
int y;
int time;
};
struct node2
{
bool is;
int id;
}boss[N][N];
int n,m,virus,a;
queue<node>q;
bool vis[N][N],origin[N][N];
int res[25010];
int dx[5] = {0,0,0,1,-1};
int dy[5] = {0,1,-1,0,0};
int main()
{
memset(res,0x3f3f3f3f,sizeof res);
scanf("%d %d %d %d",&n,&m,&virus,&a);
for(int i(1);i <= virus; ++ i)
{
int x,y;
scanf("%d %d",&x,&y);
q.push({x,y,1});
origin[x][y] = true;
}
for(int i(1);i <= a; ++ i)
{
int x,y;
scanf("%d %d",&x,&y);
boss[x][y] = {true,i};
if(origin[x][y])
res[i] = 0;
}
while(!q.empty())
{
node cur = q.front();
q.pop();
for(int i(1);i <= 4; ++ i)
{
int xx = cur.x + dx[i];
int yy = cur.y + dy[i];
int t = cur.time;
if(xx <= n and xx >= 1 and yy <= m and yy >= 1 and !vis[xx][yy])
{
if(boss[xx][yy].is)
res[boss[xx][yy].id] = min(res[boss[xx][yy].id],t);
q.push({xx,yy,t + 1});
vis[xx][yy] = true;
}
}
}
for(int i(1);i <= a; ++ i)
{
printf("%d",res[i]);
putchar('\n');
}
return 0;
}
qwq谢谢大家