human
Give me a Python program to print the number of inconvenient pairs given the following:
PYTHON3 solution for "There is a city that can be represented as a square grid with corner points in (0, 0) and (10^6, 10^6).

The city has n vertical and m horizontal streets that goes across the whole city, i. e. the i-th vertical streets goes from (x_i, 0) to (x_i, 10^6) and the j-th horizontal street goes from (0, y_j) to (10^6, y_j). 

All streets are bidirectional. Borders of the city are streets as well.

There are k persons staying on the streets: the p-th person at point (x_p, y_p) (so either x_p equal to some x_i or y_p equal to some y_j, or both).

Let's say that a pair of persons form an inconvenient pair if the shortest path from one person to another going only by streets is strictly greater than the Manhattan distance between them.

Calculate the number of inconvenient pairs of persons (pairs (x, y) and (y, x) are the same pair).

Let's recall that Manhattan distance between points (x_1, y_1) and (x_2, y_2) is |x_1 - x_2| + |y_1 - y_2|.

Input

The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of test cases.

The first line of each test case contains three integers n, m and k (2 ≤ n, m ≤ 2 ⋅ 10^5.
2 ≤ k ≤ 3 ⋅ 10^5) — the number of vertical and horizontal streets and the number of persons.

The second line of each test case contains n integers x_1, x_2, ..., x_n (0 = x_1 < x_2 < ... < x_{n - 1} < x_n = 10^6) — the x-coordinates of vertical streets.

The third line contains m integers y_1, y_2, ..., y_m (0 = y_1 < y_2 < ... < y_{m - 1} < y_m = 10^6) — the y-coordinates of horizontal streets.

Next k lines contains description of people. The p-th line contains two integers x_p and y_p (0 ≤ x_p, y_p ≤ 10^6.
x_p ∈ \\{x_1, ..., x_n\} or y_p ∈ \\{y_1, ..., y_m\}) — the coordinates of the p-th person. All points are distinct.

It guaranteed that sum of n doesn't exceed 2 ⋅ 10^5, sum of m doesn't exceed 2 ⋅ 10^5 and sum of k doesn't exceed 3 ⋅ 10^5.

Output

For each test case, print the number of inconvenient pairs.

Example

Input

2
2 2 4
0 1000000
0 1000000
1 0
1000000 1
999999 1000000
0 999999
5 4...":
assistant
#Here is Python program to print the number of inconvenient pairs.
 #!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
from bisect import bisect_left
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def main():
    t = int(input())

    for _ in range(t):
        n, m, k = map(int, input().split())
        x = [int(xi) for xi in input().split()]
        y = [int(xi) for xi in input().split()]

        p = [[int(i) for i in input().split()] for _ in range(k)]

        sol = 0

        seen, prev, curr = [0] * len(y), [0] * len(y), [0] * len(y)
        for xp, yp in sorted(p, key=lambda x: x[0]):
            idx_x = bisect_left(x, xp)
            idx_y = bisect_left(y, yp)

            if y[idx_y] == yp:
                continue

            if prev[idx_y] != idx_x:
                seen[idx_y] += curr[idx_y]
                prev[idx_y] = idx_x
                curr[idx_y] = 0

            curr[idx_y] += 1

            sol += seen[idx_y]

        seen, prev, curr = [0] * len(x), [0] * len(x), [0] * len(x)
        for xp, yp in sorted(p, key=lambda x: x[1]):
            idx_x = bisect_left(x, xp)
            idx_y = bisect_left(y, yp)

            if x[idx_x] == xp:
                continue

            if prev[idx_x] != idx_y:
                seen[idx_x] += curr[idx_x]
                prev[idx_x] = idx_y
                curr[idx_x] = 0

            curr[idx_x] += 1

            sol += seen[idx_x]

        print(sol)


# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
           ...