output_description: For each dataset, output _p_ lines, the _i_ -th of which contains the number
  of holes punched in the paper by the _i_ -th punching instruction.
input_description: The input consists of at most 1000 datasets, each in the following format.
  
  > _n_ _m_ _t_ _p_  
  >  _d_ 1 _c_ 1  
  >  ...  
  >  _d t_ _c t_  
  >  _x_ 1 _y_ 1  
  >  ...  
  >  _x p_ _y p_  
  >
  
  _n_ and _m_ are the width and the height, respectively, of a rectangular piece
  of paper. They are positive integers at most 32. _t_ and _p_ are the numbers
  of folding and punching instructions, respectively. They are positive integers
  at most 20. The pair of _d i_ and _c i_ gives the _i_ -th folding instruction
  as follows:
  
    * _d i_ is either 1 or 2.
    * _c i_ is a positive integer.
    * If _d i_ is 1, the left-hand side of the vertical folding line that passes at _c i_ right to the left boundary is folded onto the right-hand side. 
    * If _d i_ is 2, the lower side of the horizontal folding line that passes at _c i_ above the lower boundary is folded onto the upper side. 
  
  After performing the first _i_ −1 folding instructions, if _d i_ is 1, the
  width of the shape is greater than _c i_. Otherwise the height is greater than
  _c i_. (_x i_ \+ 1/2, _y i_ \+ 1/2) gives the coordinates of the point where
  the _i_ -th punching instruction is performed. The origin (0, 0) is at the
  bottom left of the finally obtained shape. _x i_ and _y i_ are both non-
  negative integers and they are less than the width and the height,
  respectively, of the shape. You can assume that no two punching instructions
  punch holes at the same location.
  
  The end of the input is indicated by a line containing four zeros.
attempt: from operator import add
  
  
  def fold_right(v, length):
      for i in range(len(v[0])):
          if not any(list(zip(*v))[i]):
              continue
          for j in range(length):
              for yoko in range(len(v)):
                  v[yoko][i + j + length] += v[yoko][i + j]
                  v[yoko][i + j] = 0
          return v
  
  
  def fold_up(v, length):
      for i in range(len(v) - 1, -1, -1):
          if not any(v[i]):
              continue
          for j in range(length):
              v[i - j - length] = list(map(add, v[i - j - length], v[i - j]))
              v[i - j] = [0] * len(v[i - j])
          return v
  
  
  def cut_cut_cut(v, x, y):
      for i in range(len(v) - 1, -1, -1):
          if not any(v[i]):
              continue
          y = i - y
          break
      for i in range(len(v[0])):
          if not any(list(zip(*v))[i]):
              continue
          x = i + x
          break
      return v[y][x]
  
  
  while True:
      n, m, t, p = map(int, input().split())
      if n == 0 and m == 0 and t == 0 and p == 0:
          break
      origami = [[0] * 63 for _ in range(63)]
      for i in range(m):
          for j in range(n):
              origami[len(origami) - 1 - i][j] = 1
      for i in range(t):
          d, c = map(int, input().split())
          if d == 1:
              origami = fold_right(origami, c)
          else:
              origami = fold_up(origami, c)
  
      # print(*origami, sep="\n")
      # print()
      for i in range(p):
          x, y = map(int, input().split())
          print(cut_cut_cut(origami, x, y))
  
problem_description: Origami, or the art of folding paper
  
  Master Grus is a famous _origami_ (paper folding) artist, who is enthusiastic
  about exploring the possibility of origami art. For future creation, he is now
  planning fundamental experiments to establish the general theory of origami.
  
  One rectangular piece of paper is used in each of his experiments. He folds it
  horizontally and/or vertically several times and then punches through holes in
  the folded paper.
  
  The following figure illustrates the folding process of a simple experiment,
  which corresponds to the third dataset of the Sample Input below. Folding the
  10 × 8 rectangular piece of paper shown at top left three times results in the
  6 × 6 square shape shown at bottom left. In the figure, dashed lines indicate
  the locations to fold the paper and round arrows indicate the directions of
  folding. Grid lines are shown as solid lines to tell the sizes of rectangular
  shapes and the exact locations of folding. Color densities represent the
  numbers of overlapping layers. Punching through holes at A and B in the folded
  paper makes nine holes in the paper, eight at A and another at B.
  
  ![](https://judgeapi.u-aizu.ac.jp/resources/images/ICPCDomestic2018_B1.png)
  
  Your mission in this problem is to write a computer program to count the
  number of holes in the paper, given the information on a rectangular piece of
  paper and folding and punching instructions.
samples: [{"input": "1 1 1\n    1 1\n    0 0\n    1 3 2 1\n    2 1\n    2 1\n    0 0\n    10 8 3 2\n    2 2\n    1 3\n    1 1\n    0 1\n    3 4\n    3 3 3 2\n    1 2\n    2 1\n    1 1\n    0 1\n    0 0\n    0 0 0 0", "output": "3\n    8\n    1\n    3\n    6"}]