#include <bits/stdc++.h>
using namespace std;
inline int rd() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
int t, n, m, k;
long long ans;
int fx[1000010];
int fy[1000010];
int x[300010], y[300010];
int dx[300010], dy[300010];
int a[300010], b[300010];
int p[300010], cnp;
int q[300010], cnq;
map<pair<int, int>, int> mp;
map<pair<int, int>, int> mq;
int main() {
  t = rd();
  while (t--) {
    n = rd(), m = rd(), k = rd(), ans = 0;
    memset(fx, 0, sizeof(fx));
    memset(fy, 0, sizeof(fy));
    mp.clear();
    cnp = 0;
    mq.clear();
    cnq = 0;
    for (register int i = 1; i <= n; i++) x[i] = rd(), fx[x[i]] = 1, a[i] = 0;
    for (register int i = 1; i <= m; i++) y[i] = rd(), fy[y[i]] = 1, b[i] = 0;
    for (register int i = 1; i <= k; i++) {
      dx[i] = rd(), dy[i] = rd();
      if (!fx[dx[i]]) {
        int xx = lower_bound(x + 1, x + n + 1, dx[i]) - (x + 1);
        int yy = lower_bound(y + 1, y + m + 1, dy[i]) - (y);
        int pos = mp[make_pair(xx, yy)];
        a[xx]++;
        if (pos)
          p[pos]++;
        else
          p[++cnp] = 1, mp[make_pair(xx, yy)] = cnp;
      }
      if (!fy[dy[i]]) {
        int xx = lower_bound(x + 1, x + n + 1, dx[i]) - (x);
        int yy = lower_bound(y + 1, y + m + 1, dy[i]) - (y + 1);
        int pos = mq[make_pair(xx, yy)];
        b[yy]++;
        if (pos)
          q[pos]++;
        else
          q[++cnq] = 1, mq[make_pair(xx, yy)] = cnq;
      }
    }
    for (register int i = 1; i <= k; i++) {
      if (!fx[dx[i]]) {
        int xx = lower_bound(x + 1, x + n + 1, dx[i]) - (x + 1);
        int yy = lower_bound(y + 1, y + m + 1, dy[i]) - (y);
        int pos = mp[make_pair(xx, yy)];
        ans += a[xx] - p[pos];
      }
      if (!fy[dy[i]]) {
        int xx = lower_bound(x + 1, x + n + 1, dx[i]) - (x);
        int yy = lower_bound(y + 1, y + m + 1, dy[i]) - (y + 1);
        int pos = mq[make_pair(xx, yy)];
        ans += b[yy] - q[pos];
      }
    }
    printf("%lld\n", ans / 2);
  }
  return 0;
}
