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 9
0 1 2 6 1000000
0 4 8 1000000
4 4
2 5
2 2
6 3
1000000 1
3 8
5 8
8 8
6 8


Output


2
5

Note

The second test case is pictured below: 

<image>

For example, points 3 and 4 form an inconvenient pair, since the shortest path between them (shown red and equal to 7) is greater than its Manhattan distance (equal to 5).

Points 3 and 5 also form an inconvenient pair: the shortest path equal to 1000001 (shown green) is greater than the Manhattan distance equal to 999999.

But points 5 and 9 don't form an inconvenient pair, since the shortest path (shown purple) is equal to its Manhattan distance.
import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
from itertools import permutations
import string


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        import os
        self.os = os
        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
        self.BUFSIZE = 8192

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

    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")


def get_int():
    return int(input())


def get_ints():
    return list(map(int, input().split(' ')))


def get_int_grid(n):
    return [get_ints() for _ in range(n)]


def get_str():
    return input().strip()


def get_strs():
    return get_str().split(' ')


def flat_list(arr):
    return [item for subarr in arr for item in subarr]


def yes_no(b):
    if b:
        return "YES"
    else:
        return "NO"


def binary_search(good, left, right, delta=1, right_true=False):
    """
    Performs binary search
    ----------
    Parameters
    ----------
    :param good: Function used to perform the binary search
    :param left: Starting value of left limit
    :param right: Starting value of the right limit
    :param delta: Margin of error, defaults value of 1 for integer binary search
    :param right_true: Boolean, for whether the right limit is the true invariant
    :return: Returns the most extremal value interval [left, right] which is good function evaluates to True,
            alternatively returns False if no such value found
    """

    limits = [left, right]
    while limits[1] - limits[0] > delta:
        if delta == 1:
            mid = sum(limits) // 2
        else:
            mid = sum(limits) / 2
        if good(mid):
            limits[int(right_true)] = mid
        else:
            limits[int(~right_true)] = mid
    if good(limits[int(right_true)]):
        return limits[int(right_true)]
    else:
        return False


def prefix_sums(a):
    p = [0]
    for x in a:
        p.append(p[-1] + x)
    return p


def solve_a():
    n = get_int()
    s = get_str()
    cnt = 0
    for i in range(n):
        for j in range(i + 1, n + 1):
            if s[i:j].count('a') == s[i:j].count('b'):
                return i + 1, j
    return -1, -1


def solve_b():
    n = get_int()
    s = list(map(int, get_str()))

    grid = [['='] * n for _ in range(n)]

    if 1 <= s.count(2) <= 2:
        print("NO")
        return

    else:
        winners = []
        for i, x in enumerate(s):
            if x == 1:
                for j in range(n):
                    grid[i][j] = '='
            else:
                winners.append(i)

        m = len(winners)
        for i in range(m):
            grid[winners[i]][winners[i - 1]] = '+'
            grid[winners[i - 1]][winners[i]] = '-'

        for i in range(n):
            grid[i][i] = 'X'


        print("YES")
        for row in grid:
            print(''.join(row))
        return



def inv_mod(a, M):
    '''
    Returns the inverse of a modulo M (prime), uses Fermat's Little Theorem.
    Time complexity: O(log M) - fast exponentiation
    Memory complexity: O(1)
    :param a: number to invert
    :param M: modulo base, must be prime
    :return: returns inverse of a modulo M
    '''
    return pow(a, M - 2, M)


def choices(n, M):
    '''
    Returns an array of binomial co-efficients (n choose k) modulo M, for k in {0, 1, ..., n}
    Time complexity: O(n log M)
    Memory complexity: O(n)
    :param n: upper index for the binomial co-efficients
    :param M: modulo base, usually (large) prime
    :return: array of kth binomial co-efficients, modulo M
    '''
    # Initialise array and n choose 0
    ret = [0] * (n + 1)
    ret[0] = 1
    # Loop over k in {1, ..., n} and define n choose k, inductively
    for k in range(1, n + 1):
        ret[k] = (ret[k - 1] * (n - k + 1) * inv_mod(k, M)) % M
    # Return array of binomial co-efficients
    return ret


def powers(a, n, M):
    '''
    Return an array of the kth powers of a, modulo M. k in {0, 1, ..., n}
    Time Complexity
    :param a: base for exponentiation
    :param n: maximum exponent (inclusive)
    :param M: modulo base, usually (large) prime
    :return: array of the kth powers, modulo M
    '''
    # Initilise array and a ** 0
    ret = [0] * (n + 1)
    ret[0] = 1
    # Loop over k in {1, ..., n} and define a ** k, inductively
    for k in range(1, n + 1):
        ret[k] = (ret[k - 1] * a) % M
    # Return array of powers
    return ret


def factorials(n, M):
    '''
    Return an array of kth factorials, modulo M. k in {0, 1, ..., n}
    :param n: maximum factorial to return
    :param M: modulo base, usually (large) prime
    :return: array of kth factorials, modulo M
    '''
    # Initialise an array and 0!
    ret = [0] * (n + 1)
    ret[0] = 1
    # Loop over k in {1, ..., n} and define k!, inductively
    for k in range(1, n + 1):
        ret[k] = (ret[k - 1] * k) % M
    # Return array of factorials
    return ret

M = 998244353
F = factorials(2 * 10 ** 5 + 1, M)


def solve_c():
    n = get_int()
    a = get_ints()
    c = choices(n, M)

    C = Counter(a)

    s = list(C.items())
    s.sort()

    if len(s) == 1:
        return F[n]


    else:
        tops = s[-1][1]
        seconds = s[-2][1]
        ans = F[n]
        if tops > 1:
            return ans

        elif s[-1][0] != s[-2][0] + 1:
            return 0

        c = choices(n - tops - seconds, M)

        for i in range(n - 1):
            if i >= tops + seconds - 1:
                ans -= F[i] * F[n - i - 1] * c[i - tops - seconds + 1] * tops
                ans %= M

        ans -= tops * F[n - 1]
        ans %= M

        return ans



class DSU:

    # Disjoint Set Union (Union-Find) Data Structure
    def __init__(self, nodes, recursive=True, choose_join=True):
        # Parents
        self.p = [i for i in range(nodes)]
        # Ranks
        self.r = [0 for i in range(nodes)]
        # Sizes
        self.s = [1 for i in range(nodes)]
        self.recursive = recursive
        self.choose_join = choose_join

    def _get_recursive(self, u):
        if u != self.p[u]:
            self.p[u] = self.get(self.p[u])
        return self.p[u]

    def _get_nonrecursive(self, u):
        v = self.p[u]
        while v != self.p[v]:
            v = self.p[v]
        while u != v:
            u, self.p[u] = self.p[u], v
        return v

    def get(self, u):
        if self.recursive:
            return self._get_recursive(u)
        else:
            return self._get_nonrecursive(u)

    def union(self, u, v):
        # Unites the sets with identifiers u and v
        u = self.get(u)
        v = self.get(v)
        if u != v:
            if self.r[u] > self.r[v] and self.choose_join:
                u, v = v, u
            self.p[u] = v
            if self.r[u] == self.r[v]:
                self.r[v] += 1
            self.s[v] += self.s[u]


def solve_d():
    n, m, k = get_ints()
    x = get_ints()
    y = get_ints()
    x.sort()
    y.sort()
    xd = defaultdict(int)
    yd = defaultdict(int)

    xd2 = defaultdict(int)
    yd2 = defaultdict(int)

    xs = set(x)
    ys = set(y)

    cnt = 0
    for _ in range(k):
        a, b = get_ints()
        if a in xs and b in ys:
            continue
        elif a in xs:
            i = bisect.bisect_left(y, b)
            xd[i] += 1
            xd2[(i, a)] += 1
        elif b in ys:
            j = bisect.bisect_left(x, a)
            yd[j] += 1
            yd2[(j, b)] += 1

    cnt = 0


    for k, v in xd.items():
        cnt += (v * (v - 1)) // 2
    for k, v in yd.items():
        cnt += (v * (v - 1)) // 2
    for k, v in xd2.items():
        cnt -= (v * (v - 1)) // 2
    for k, v in yd2.items():
        cnt -= (v * (v - 1)) // 2

    return cnt


t = get_int()
for _ in range(t):
    print(solve_d())
