#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define siz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define debug_arr(x,len) for(int _=1; _<=len; _++) cout<<x[_]<<" "; cout<<'\n';
#define debug(x) cout<<'\n'<<#x<<": "<<x<<'\n';
const int maxN=1e7+5, maxM=1e3+5;
int n, m, k, q, good[maxN], a[maxM][maxM], check[maxM][maxM], pref[maxM][maxM];
vector<int>snt;
void sieve()
{
for(int i=2; i<=1e7; i+=1) good[i]=1;
for(int i=2; i<=1e7; i+=1)
{
if(good[i])
{
for(int j=i*2; j<=1e7; j+=i) good[j]=0;
}
}
for(int i=2; i<=1e7; i+=1)
{
if(good[i]) snt.push_back(i);
}
}
void solve()
{
int row1=1, col1=n, row2=1, col2=m, dem=-1;
while(row1<=col1 && row2<=col2)
{
for(int i=row2; i<=col2; i+=1)
{
if(!check[row1][i] && !a[row1][i]) a[row1][i]=snt[++dem];
// cout<<row1<<" "<<i<<'\n';
}
row1++;
for(int i=row1; i<=col1; i+=1)
{
if(!check[i][col2] && !a[i][col2]) a[i][col2]=snt[++dem];
// cout<<i<<" "<<col2<<'\n';
}
col2--;
for(int i=col2; i>=row2; i-=1)
{
if(!check[col1][i] && !a[col1][i]) a[col1][i]=snt[++dem];
// cout<<col1<<" "<<i<<'\n';
}
col1--;
for(int i=col1; i>=row1; i-=1)
{
if(!check[i][row2] && !a[i][row2]) a[i][row2]=snt[++dem];
// cout<<i<<" "<<row2<<'\n';
}
row2++;
}
// for(int i=1; i<=n; i+=1)
// {
// for(int j=1; j<=m; j+=1) cout<<a[i][j]<<" "; cout<<'\n';
// }
for(int i=1; i<=n; i+=1)
{
for(int j=1; j<=m; j+=1)
{
pref[i][j]=pref[i-1][j]+pref[i][j-1]-pref[i-1][j-1]+a[i][j];
}
}
for(int i=1; i<=q; i+=1)
{
int x1, y1, x2, y2;
cin>>x1>>y1>>x2>>y2;
int ans=pref[x2][y2]-pref[x1-1][y2]-pref[x2][y1-1]+pref[x1-1][y1-1];
cout<<ans<<'\n';
}
}
int32_t main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
sieve();
cin>>n>>m>>k>>q;
for(int i=1; i<=k; i+=1)
{
int x,y; cin>>x>>y;
check[x][y]=1;
}
solve();
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBpbnQgbG9uZyBsb25nCiNkZWZpbmUgZmkgZmlyc3QKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBzaXooeCkgKGludCkoeC5zaXplKCkpCiNkZWZpbmUgYWxsKHgpIHguYmVnaW4oKSwgeC5lbmQoKQojZGVmaW5lIGRlYnVnX2Fycih4LGxlbikgZm9yKGludCBfPTE7IF88PWxlbjsgXysrKSBjb3V0PDx4W19dPDwiICI7IGNvdXQ8PCdcbic7CiNkZWZpbmUgZGVidWcoeCkgY291dDw8J1xuJzw8I3g8PCI6ICI8PHg8PCdcbic7CmNvbnN0IGludCBtYXhOPTFlNys1LCBtYXhNPTFlMys1OwoKaW50IG4sIG0sIGssIHEsIGdvb2RbbWF4Tl0sIGFbbWF4TV1bbWF4TV0sIGNoZWNrW21heE1dW21heE1dLCBwcmVmW21heE1dW21heE1dOwp2ZWN0b3I8aW50PnNudDsKCnZvaWQgc2lldmUoKQp7CiAgICBmb3IoaW50IGk9MjsgaTw9MWU3OyBpKz0xKSBnb29kW2ldPTE7CiAgICBmb3IoaW50IGk9MjsgaTw9MWU3OyBpKz0xKQogICAgewogICAgICAgIGlmKGdvb2RbaV0pCiAgICAgICAgewogICAgICAgICAgICBmb3IoaW50IGo9aSoyOyBqPD0xZTc7IGorPWkpIGdvb2Rbal09MDsKICAgICAgICB9CiAgICB9CiAgICBmb3IoaW50IGk9MjsgaTw9MWU3OyBpKz0xKQogICAgewogICAgICAgIGlmKGdvb2RbaV0pIHNudC5wdXNoX2JhY2soaSk7CiAgICB9Cn0KCnZvaWQgc29sdmUoKQp7CiAgICBpbnQgcm93MT0xLCBjb2wxPW4sIHJvdzI9MSwgY29sMj1tLCBkZW09LTE7CiAgICB3aGlsZShyb3cxPD1jb2wxICYmIHJvdzI8PWNvbDIpCiAgICB7CiAgICAgICAgZm9yKGludCBpPXJvdzI7IGk8PWNvbDI7IGkrPTEpCiAgICAgICAgewogICAgICAgICAgICBpZighY2hlY2tbcm93MV1baV0gJiYgIWFbcm93MV1baV0pIGFbcm93MV1baV09c250WysrZGVtXTsKICAgICAgICAgICAgLy8gY291dDw8cm93MTw8IiAiPDxpPDwnXG4nOwogICAgICAgIH0KICAgICAgICByb3cxKys7CiAgICAgICAgZm9yKGludCBpPXJvdzE7IGk8PWNvbDE7IGkrPTEpCiAgICAgICAgewogICAgICAgICAgICBpZighY2hlY2tbaV1bY29sMl0gJiYgIWFbaV1bY29sMl0pIGFbaV1bY29sMl09c250WysrZGVtXTsKICAgICAgICAgICAgLy8gY291dDw8aTw8IiAiPDxjb2wyPDwnXG4nOwogICAgICAgIH0KICAgICAgICBjb2wyLS07CiAgICAgICAgZm9yKGludCBpPWNvbDI7IGk+PXJvdzI7IGktPTEpCiAgICAgICAgewogICAgICAgICAgICBpZighY2hlY2tbY29sMV1baV0gJiYgIWFbY29sMV1baV0pIGFbY29sMV1baV09c250WysrZGVtXTsKICAgICAgICAgICAgLy8gY291dDw8Y29sMTw8IiAiPDxpPDwnXG4nOwogICAgICAgIH0KICAgICAgICBjb2wxLS07CiAgICAgICAgZm9yKGludCBpPWNvbDE7IGk+PXJvdzE7IGktPTEpCiAgICAgICAgewogICAgICAgICAgICBpZighY2hlY2tbaV1bcm93Ml0gJiYgIWFbaV1bcm93Ml0pIGFbaV1bcm93Ml09c250WysrZGVtXTsKICAgICAgICAgICAgLy8gY291dDw8aTw8IiAiPDxyb3cyPDwnXG4nOwogICAgICAgIH0KICAgICAgICByb3cyKys7CiAgICB9CiAgICAvLyBmb3IoaW50IGk9MTsgaTw9bjsgaSs9MSkKICAgIC8vIHsKICAgIC8vICAgICBmb3IoaW50IGo9MTsgajw9bTsgais9MSkgY291dDw8YVtpXVtqXTw8IiAiOyBjb3V0PDwnXG4nOwogICAgLy8gfQogICAgZm9yKGludCBpPTE7IGk8PW47IGkrPTEpCiAgICB7CiAgICAgICAgZm9yKGludCBqPTE7IGo8PW07IGorPTEpIAogICAgICAgIHsKICAgICAgICAgICAgcHJlZltpXVtqXT1wcmVmW2ktMV1bal0rcHJlZltpXVtqLTFdLXByZWZbaS0xXVtqLTFdK2FbaV1bal07CiAgICAgICAgfQogICAgfQogICAgZm9yKGludCBpPTE7IGk8PXE7IGkrPTEpCiAgICB7CiAgICAgICAgaW50IHgxLCB5MSwgeDIsIHkyOwogICAgICAgIGNpbj4+eDE+PnkxPj54Mj4+eTI7CiAgICAgICAgaW50IGFucz1wcmVmW3gyXVt5Ml0tcHJlZlt4MS0xXVt5Ml0tcHJlZlt4Ml1beTEtMV0rcHJlZlt4MS0xXVt5MS0xXTsKICAgICAgICBjb3V0PDxhbnM8PCdcbic7CiAgICB9Cn0KCmludDMyX3QgbWFpbigpCnsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7IGNpbi50aWUoMCk7CiAgICBzaWV2ZSgpOwogICAgY2luPj5uPj5tPj5rPj5xOwogICAgZm9yKGludCBpPTE7IGk8PWs7IGkrPTEpCiAgICB7CiAgICAgICAgaW50IHgseTsgY2luPj54Pj55OwogICAgICAgIGNoZWNrW3hdW3ldPTE7CiAgICB9CiAgICBzb2x2ZSgpOwp9Cg==