sealed class ImmutableList<out T>{
    data class Cons<T>(val head:T, val tail: ImmutableList<T>): ImmutableList<T>()
    object Nil: ImmutableList<Nothing>()
}
class UnionFindTree{
    private var mParent: UnionFindTree? = null
    private var mSize = 1
    val size: Int
        get() = parent().mSize
    private fun parent(): UnionFindTree {
        mParent = mParent?.parent()
        return mParent ?: this
    }
    private fun isSameUnion(that:UnionFindTree): Boolean{
        return parent() == that.parent()
    }
    fun union(that:UnionFindTree): Unit {
        if (!isSameUnion(that)){
            that.parent().mSize += this.parent().mSize
            parent().mParent = that
        }
    }
}
class Paper(val width:Int, val height:Int){
    private val mArray = Array(height){Array(width){ UnionFindTree()}}
    private var mTop = 0
    private var mBottom= height - 1
    private var mLeft = 0
    private var mRight = width - 1
    private var mIsVerticalFlipped = false
    private var mIsHorizontalFlipped = false
    fun foldHorizontal(cutPos: Int): Unit {
        val line = if (mIsVerticalFlipped) mBottom - cutPos else mTop + cutPos - 1
        val size = if (line - mTop + 1 >= mBottom - line) mBottom - line else line - mTop + 1
        for (dy in 0 until size){
            for (x in mLeft .. mRight) {
                mArray[line - dy][x].union(mArray[line + dy + 1][x])
            }
        }
        if (line - mTop + 1 >= mBottom - line){
            if (!mIsVerticalFlipped) mIsVerticalFlipped = true
            mBottom = line
        }else {
            if (mIsVerticalFlipped) mIsVerticalFlipped = false
            mTop = line + 1
        }
    }
    fun foldVertical(cutPos: Int): Unit {
        val line = if (mIsHorizontalFlipped)  mRight - cutPos else mLeft + cutPos - 1
        val size = if (line - mLeft + 1 >= mRight - line) mRight - line else line - mLeft + 1
        for (dx in 0 until size){
            for (y in mTop .. mBottom){
                mArray[y][line - dx].union(mArray[y][line + dx + 1])
            }
        }
        if (line - mLeft + 1 >= mRight - line){
            if (!mIsHorizontalFlipped) mIsHorizontalFlipped = true
            mRight = line
        }else{
            if (mIsHorizontalFlipped) mIsHorizontalFlipped = false
            mLeft = line + 1
        }
    }
    fun holeCount(x: Int, y: Int): Int {
        val xPos = if (mIsHorizontalFlipped) mRight - x else mLeft + x
        val yPos = if (mIsVerticalFlipped) mBottom - y else mTop + y
        return mArray[yPos][xPos].size
    }
}
fun main(args:Array<String>){
    while (true){
        val (n, m, t, p) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == 0 && m == 0 && t == 0 && p == 0) return
        val paper = Paper(n, m)
        repeat(t){
            val (d, c) = readLine()!!.trim().split(' ').map(String::toInt)
            when(d){
                1 -> paper.foldVertical(c)
                else -> paper.foldHorizontal(c)
            }
        }
        repeat(p){
            val (x, y) = readLine()!!.trim().split(' ').map(String::toInt)
            println(paper.holeCount(x, y))
        }
    }
}
