n = $stdin.gets.chomp!.to_i

n.times do |i|
  gx, gy = $stdin.gets.chomp!.split(" ")
  np = $stdin.gets.chomp!.to_i

  matatabi = []
  np.times do |j|
    x1, y1, x2, y2 = $stdin.gets.chomp!.split(" ")
    matatabi.push [[x1, x2].min, [y1, y2].min, [x1,x2].max, [y1,y2].max]
  end
  
  dp = []
  (0..gx).each do |x|
    dp[x] = []
    (0..gy).each do |y|
      dp[x][y] = 0
      if x > 0 && matatabi.include?([x-1,y,x,y])
        dp[x][y] += dp[x-1][y]
      end

      if y > 0 && matatabi.include?([x,y-1,x,y])
        dp[x][y] += dp[x][y-1]
      end

      if x + y == 0
        dp[x][y] = 0
      end
    end
  end
  puts dp[gx][gy]
end