#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
const int mod = 998244353;
int x[maxn], y[maxn], n, m;
struct Node {
  int x, y;
} a[maxn];
bool cmp1(Node a, Node b) { return a.y < b.y || a.y == b.y && a.x < b.x; }
bool cmp2(Node a, Node b) { return a.x < b.x || a.x == b.x && a.y < b.y; }
bool check(int vx, int vy) {
  int idx = lower_bound(x + 1, x + 1 + n, vx) - x;
  int idy = lower_bound(y + 1, y + 1 + m, vy) - y;
  if (x[idx] != vx || y[idy] != vy) return false;
  return true;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int k;
    scanf("%d%d%d", &n, &m, &k);
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &x[i]);
    }
    for (int i = 1; i <= m; ++i) {
      scanf("%d", &y[i]);
    }
    int tot = 0;
    for (int i = 1; i <= k; ++i) {
      int vx, vy;
      scanf("%d%d", &vx, &vy);
      if (!check(vx, vy)) {
        a[++tot] = {vx, vy};
      }
    }
    int nowy = 1;
    sort(a + 1, a + 1 + tot, cmp1);
    long long ans = 0;
    for (int i = 1; i <= tot; ++i) {
      while (nowy + 1 <= m && y[nowy + 1] <= a[i].y) nowy++;
      if (a[i].y == y[nowy]) continue;
      int j = i;
      int cnt = 0, nowcnt = 0;
      vector<Node> g;
      while (j <= tot && a[j].y < y[nowy + 1]) {
        g.push_back(a[j]);
        j++;
      }
      int cj = j;
      j = 0;
      sort(g.begin(), g.end(), [&](Node a, Node b) { return a.x < b.x; });
      while (j < (int)g.size()) {
        if (j == 0 || g[j].x == g[j - 1].x) {
          nowcnt++;
        } else {
          ans += 1ll * nowcnt * cnt;
          cnt += nowcnt;
          nowcnt = 1;
        }
        j++;
      }
      ans += 1ll * nowcnt * cnt;
      i = cj - 1;
    }
    sort(a + 1, a + 1 + tot, cmp2);
    int nowx = 1;
    for (int i = 1; i <= tot; ++i) {
      while (nowx + 1 <= n && x[nowx + 1] <= a[i].x) nowx++;
      if (a[i].x == x[nowx]) continue;
      int j = i;
      int cnt = 0, nowcnt = 0;
      vector<Node> g;
      while (j <= tot && a[j].x < x[nowx + 1]) {
        g.push_back(a[j]);
        j++;
      }
      int cj = j;
      j = 0;
      sort(g.begin(), g.end(), [&](Node a, Node b) { return a.y < b.y; });
      while (j < (int)g.size()) {
        if (j == 0 || g[j].y == g[j - 1].y) {
          nowcnt++;
        } else {
          ans += 1ll * nowcnt * cnt;
          cnt += nowcnt;
          nowcnt = 1;
        }
        j++;
      }
      ans += 1ll * nowcnt * cnt;
      i = cj - 1;
    }
    printf("%lld\n", ans);
  }
}
