#include<string>
#include<iostream>
#include<cstdlib>

typedef struct paper
{
	int mat[32][32];
	int w;
	int h;
} Paper;

void initPaper(int m, int n, Paper *p);
void copyPaper(Paper *ps, Paper *pt);
void printPaper(Paper *p);
int getHole(int x, int y, Paper *p);
void reversePaper(int vh, Paper *p);

void initPaper(int m, int n, Paper *p, int initNum)
{
	int i = 0, j = 0;
	p->w = m;
	p->h = n;
	for(j = 0;j < p->h;j++)
	{
		for(i = 0;i < p->w;i++)
		{
			p->mat[i][j] = initNum;
		}
	}
	return;
}

void copyPaper(Paper *ps, Paper *pt)
{
	int i, j;
	pt->w = ps->w;
	pt->h = ps->h;
	for(i = 0; i < ps->w; i++)
		for(j = 0; j < ps->h; j++)
			pt->mat[i][j] = ps->mat[i][j];
	return;
}

void printPaper(Paper *p)
{
	int i, j;
	for(j = 0; j < p->h; j++)
	{
		for(i = 0; i < p->w; i++)
			std::cout << p->mat[i][(p->h)-1-j] << " ";
		std::cout << std::endl;
	}
	return;
}

int getHole(int x, int y, Paper *p)
{
	return p->mat[x][y];
}

void reversePaper(int vh, Paper *p)
{
	int i, j, tmp;
	for(i = 0; (vh == 1?i*2:i) < p->w;i++)
		for(j = 0; (vh == 2?j*2:j) < p->h; j++)
		{
			tmp = p->mat[i][j];
			p->mat[i][j] = p->mat[(vh == 1?(p->w)-i-1:i)][(vh == 2?(p->h)-j-1:j)];
			p->mat[(vh == 1?(p->w)-i-1:i)][(vh == 2?(p->h)-j-1:j)] = tmp;
		}
	return;
}
void foldPaper(int vh, int n, Paper *p)
{
	int i, j;
	Paper tmp;
	if(vh == 1)
	{
		initPaper(((p->w)-n > n? (p->w)-n:n), p->h, &tmp, 1);
		for(j = 0; j < p->h; j++)
			for(i = 0; i < p->w; i++)
			{
				if(i < n)
					tmp.mat[n-i-1][j] = p->mat[i][j]+ ((n-i)+n-1 >= (p->w)?0:p->mat[2*n-i-1][j]);
				else 
					tmp.mat[i][j] = p->mat[n+i][j];
			}
	}
	if(vh == 2)
	{
		initPaper(p->w, ((p->h)-n > n? (p->h)-n:n), &tmp, 1);
		for(j = 0; j < p->h; j++)
			for(i = 0; i < p->w; i++)
			{
				if(j < n)
					tmp.mat[i][n-j-1] = p->mat[i][j]+ ((n-j)+n-1 >= (p->h)?0:p->mat[i][2*n-j-1]);
				else
					tmp.mat[i][j] = p->mat[i][n+j];
			}
	}
	copyPaper(&tmp, p);
}

int main()
{
	Paper p1;
	int foldn = 0, holen = 0, x, y, w, h, i, mode, foldL;
	std::string property;
	do
	{
		std::getline(std::cin, property);
		w = std::stoi(property.substr(0, property.find_first_of(" ")));
		property = property.substr(property.find_first_of(" ")+1,property.size()-property.find_first_of(" "));
		h = std::stoi(property.substr(0, property.find_first_of(" ")));
		property = property.substr(property.find_first_of(" ")+1,property.size()-property.find_first_of(" "));
		foldn = std::stoi(property.substr(0, property.find_first_of(" ")));
		property = property.substr(property.find_first_of(" ")+1,property.size()-property.find_first_of(" "));
		holen = std::stoi(property.substr(0, property.find_first_of(" ")));
		property = property.substr(property.find_first_of(" ")+1,property.size()-property.find_first_of(" "));
		initPaper(w, h, &p1, 1);
		for(i = 0; i < foldn; i++)
		{
			std::getline(std::cin, property);
			mode = std::stoi(property.substr(0, property.find_first_of(" ")));
			property = property.substr(property.find_first_of(" ")+1,property.size()-property.find_first_of(" ")); 
			foldL = std::stoi(property.substr(0, property.find_first_of(" ")));
			foldPaper(mode, foldL, &p1);
			//printPaper(&p1);
			//std::cout << std::endl;
		}
		for(i = 0; i < holen; i++)
		{
			std::getline(std::cin, property);
			x = std::stoi(property.substr(0, property.find_first_of(" ")));
			property = property.substr(property.find_first_of(" ")+1,property.size()-property.find_first_of(" ")); 
			y = std::stoi(property.substr(0, property.find_first_of(" ")));
			property = property.substr(property.find_first_of(" ")+1,property.size()-property.find_first_of(" ")); 
			std::cout << getHole(x, y, &p1) << std::endl;
		}
	}while(!(p1.w==0 && p1.h==0 && foldn==0 && holen==0));
	return 0;
}



Measured memory_bytes: 3172