#include <bits/stdc++.h>
const int N = 1e6 + 10;
const int M = 1e6;
using namespace std;
long long n, m, t, k;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
long long vertical[N], horizontal[N], sum = 0, v[N];
struct node {
  long long x, y;
} a[N];
long long cmp1(node x, node y) { return x.x < y.x; }
long long cmp2(node x, node y) { return x.y < y.y; }
long long ANS = 0;
signed main() {
  t = read();
  while (t--) {
    n = read(), m = read(), k = read();
    ANS = 0;
    for (long long i = 1; i <= n; i++) vertical[i] = read();
    for (long long i = 1; i <= m; i++) horizontal[i] = read();
    for (long long i = 1; i <= k; i++) {
      a[i].x = read(), a[i].y = read();
    }
    sort(a + 1, a + k + 1, cmp1);
    long long fst = 1;
    for (long long i = 1; i <= k; i) {
      set<long long> ans;
      ans.clear();
      while (a[i].x < vertical[fst] && i <= k) {
        ans.insert(a[i].y);
        sum++;
        v[a[i].y]++;
        i++;
      }
      while (a[i].x == vertical[fst]) i++;
      fst++;
      for (auto a : ans) {
        ANS += (v[a]) * (sum -= v[a]);
        v[a] = 0;
      }
    }
    fst = 1;
    sort(a + 1, a + k + 1, cmp2);
    for (long long i = 1; i <= k; i) {
      set<long long> ans;
      ans.clear();
      while (a[i].y < horizontal[fst] && i <= k) {
        ans.insert(a[i].x);
        v[a[i].x]++;
        i++;
        sum++;
      }
      while (a[i].y == horizontal[fst]) i++;
      fst++;
      for (auto a : ans) {
        ANS += (v[a]) * (sum -= v[a]);
        v[a] = 0;
      }
    }
    cout << ANS << endl;
  }
  return 0;
}

### Prompt

Please formulate a cpp solution to the following problem:

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.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 1e6 + 10;
const int M = 1e6;
using namespace std;
long long n, m, t, k;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
long long vertical[N], horizontal[N], sum = 0, v[N];
struct node {
  long long x, y;
} a[N];
long long cmp1(node x, node y) { return x.x < y.x; }
long long cmp2(node x, node y) { return x.y < y.y; }
long long ANS = 0;
signed main() {
  t = read();
  while (t--) {
    n = read(), m = read(), k = read();
    ANS = 0;
    for (long long i = 1; i <= n; i++) vertical[i] = read();
    for (long long i = 1; i <= m; i++) horizontal[i] = read();
    for (long long i = 1; i <= k; i++) {
      a[i].x = read(), a[i].y = read();
    }
    sort(a + 1, a + k + 1, cmp1);
    long long fst = 1;
    for (long long i = 1; i <= k; i) {
      set<long long> ans;
      ans.clear();
      while (a[i].x < vertical[fst] && i <= k) {
        ans.insert(a[i].y);
        sum++;
        v[a[i].y]++;
        i++;
      }
      while (a[i].x == vertical[fst]) i++;
      fst++;
      for (auto a : ans) {
        ANS += (v[a]) * (sum -= v[a]);
        v[a] = 0;
      }
    }
    fst = 1;
    sort(a + 1, a + k + 1, cmp2);
    for (long long i = 1; i <= k; i) {
      set<long long> ans;
      ans.clear();
      while (a[i].y < horizontal[fst] && i <= k) {
        ans.insert(a[i].x);
        v[a[i].x]++;
        i++;
        sum++;
      }
      while (a[i].y == horizontal[fst]) i++;
      fst++;
      for (auto a : ans) {
        ANS += (v[a]) * (sum -= v[a]);
        v[a] = 0;
      }
    }
    cout << ANS << endl;
  }
  return 0;
}

```