fun main(args: Array<String>) {
    while (true) {
        val nmtp = readLine()!!.split(' ').map{ it.toInt() }
        if (nmtp.filter { it != 0 }.isEmpty()) break

        var a = Array(nmtp[1]) { Array(nmtp[0]) { 1 } }

        (0 until nmtp[2]).forEach {
            val dc = readLine()!!.split(' ').map{ it.toInt() }

            var na = Array(nmtp[1]) { Array(nmtp[0]) { 0 } }

            if (dc[0] == 1) {
                (0 until dc[1]).forEach { j ->
                    (0 until nmtp[1]).forEach { k ->
                        na[k][j] = a[k][dc[1] - j - 1]
                    }
                }
                (0 until (nmtp[0] - dc[1])).forEach { j ->
                    (0 until nmtp[1]).forEach { k ->
                        na[k][j] += a[k][dc[1] + j]
                    }
                }
            } else {
                (0 until dc[1]).forEach { j ->
                    (0 until nmtp[0]).forEach { k ->
                        na[j][k] = a[dc[1] - j - 1][k]
                    }
                }
                (0 until (nmtp[1] - dc[1])).forEach { j ->
                    (0 until nmtp[0]).forEach { k ->
                        na[j][k] += a[dc[1] + j][k]
                    }
                }

            }

            a = na
        }

        (0 until nmtp[3]).forEach {
            val xy = readLine()!!.split(' ').map{ it.toInt() }

            println(a[xy[1]][xy[0]])
        }

    }
}

