Memento Mori

아직 제출이 없습니다시간 제한2.5초메모리 제한64 MB

문제

Professor Zhang has an n×mn \times m matrix consisting of all zeroes. Professor Zhang changes kk elements of the matrix into 1s.

Given a permutation pp of 1,2,3,4\\{1, 2, 3, 4\\}, Professor Zhang wants to find the number of such submatrices that:

  • The number of 1s in the submatrix is exactly 4.
  • Let the positions of the 1s in the submatrix be (r_1,c_1)(r\_1, c\_1), (r_2,c_2)(r\_2, c\_2), (r_3,c_3)(r\_3, c\_3), and (r_4,c_4)(r\_4, c\_4). Then r_1<r_2<r_3<r_4r\_1 < r\_2 < r\_3 < r\_4 and (p_ip_j)(c_ic_j)>0(p\_i - p\_j) \cdot (c\_i - c\_j) > 0 for all 1i<j41 \le i < j \le 4.
  • no other submatrices inside the chosen submatrix meet the above two requirements.

입력

There are multiple test cases. The first line of input contains an integer TT indicating the number of test cases. For each test case:

The first line contains three integers nn, mm and kk (1n,m,k20001 \le n, m, k \le 2000): the size of the matrix and the number of 1s. The second line contains four integers p_1,p_2,p_3,p_4p\_1, p\_2, p\_3, p\_4 denoting the permutation of 1,2,3,4\\{1, 2, 3, 4\\}.

Each of the next kk lines contains two integers r_ir\_i and c_ic\_i (1r_in1 \le r\_i \le n, 1c_im1 \le c\_i \le m): the position of the ii-th 1. No two 1s will be in the same position.

There are at most 250250 test cases, and the total size of the input is at most 250250 kibibytes.

출력

For each test case, output a single integer: the number of submatrices which meet all the requirements.