### constant

N = 4
N2 = N * N / 2

### subroutines

def count_rec(rem, x, y)
  return 1 if rem == 0

  while $used[y][x]
    x += 1
    if x >= N
      y += 1
      x = 0
    end
  end

  count = 0
  $used[y][x] = true

  for xy in $xys
    x0 = x + xy[0]
    y0 = y + xy[1]
    if x0 >= 0 && x0 < N && y0 < N && ! $used[y0][x0]
      $used[y0][x0] = true
      count += count_rec(rem - 1, x, y)
      $used[y0][x0] = false
    end
  end

  $used[y][x] = false
  count
end

### main

loop do
  line = gets.strip
  break if line.to_i > N

  ds = line.split.map(&:to_i)

  $xys = []
  N.times do
    xi = ds.shift
    yi = ds.shift
    $xys << [xi, yi]
  end
  #p $xys

  $used = N.times.map{N.times.map{false}}

  count = count_rec(N2, 0, 0)

  p count
end