#include <bits/stdc++.h>
using namespace std;
const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[8] = {0, 0, 1, -1, 1, -1, 0};
const int dy4[8] = {1, -1, 0, 0, 1, -1, 0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};
void update(long long &x, long long v) {
  if (x == -1)
    x = v;
  else if (x > v)
    x = v;
}
long long po(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}
void extgcd(long long a, long long b, long long &d, long long &x,
            long long &y) {
  if (!b) {
    d = a;
    x = 1;
  } else {
    extgcd(b, a % b, d, y, x);
    y -= x * (a / b);
  }
}
long long inverse(long long a, long long n) {
  long long d, x, y;
  extgcd(a, n, d, x, y);
  return d == 1 ? (x + n) % n : -1;
}
const int maxn = 2e6 + 5;
const int maxm = 5e2 + 5;
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
const double eps = 1e-10;
void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
void add(long long &x, long long y) {
  x += y;
  if (x >= mod) x -= mod;
}
void sub(int &x, int y) {
  x -= y;
  if (x < 0) x += mod;
}
int n, m, k;
int xv[maxn], yv[maxn];
int xp[maxn], yp[maxn];
map<int, int> haxx;
map<int, int> haxy;
map<int, std::vector<int> > agax;
map<int, std::vector<int> > agay;
void solve() {
  scanf("%d%d%d", &n, &m, &k);
  haxx.clear();
  haxy.clear();
  agax.clear();
  agay.clear();
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(xv[i]));
    haxx[xv[i]] = 1;
  }
  xv[n + 1] = 0;
  sort(xv + 1, xv + n + 1);
  for (int i = 1; i <= m; i++) {
    scanf("%d", &(yv[i]));
    haxy[yv[i]] = 1;
  }
  yv[m + 1] = 0;
  sort(yv + 1, yv + m + 1);
  std::vector<int> valx;
  std::vector<int> valy;
  for (int i = 1; i <= k; i++) {
    scanf("%d", &(xp[i]));
    scanf("%d", &(yp[i]));
    if (haxx.count(xp[i]) && haxy.count(yp[i])) {
      continue;
    }
    if (haxx.count(xp[i])) {
      valx.push_back(yp[i]);
      agax[xp[i]].push_back(yp[i]);
    }
    if (haxy.count(yp[i])) {
      valy.push_back(xp[i]);
      agay[yp[i]].push_back(xp[i]);
    }
  }
  sort(valx.begin(), valx.end());
  sort(valy.begin(), valy.end());
  long long ans = 0;
  for (int i = 0; i < valx.size(); i++) {
    int tmpy = valx[i];
    int pos = lower_bound(yv + 1, yv + m + 1, tmpy) - yv;
    if (pos <= m && yv[pos] <= tmpy) {
      continue;
    }
    int le = i + 1;
    int ri = valx.size() - 1;
    while (le < ri) {
      int mid = (le + ri + 1) / 2;
      if (valx[mid] <= yv[pos]) {
        le = mid;
      } else {
        ri = mid - 1;
      }
    }
    if (le < valx.size() && valx[le] <= yv[pos]) {
      ans += (le - i);
    }
  }
  for (int i = 0; i < valy.size(); i++) {
    int tmpx = valy[i];
    int pos = lower_bound(xv + 1, xv + n + 1, tmpx) - xv;
    if (pos <= n && xv[pos] <= tmpx) {
      continue;
    }
    int le = i + 1;
    int ri = valy.size() - 1;
    while (le < ri) {
      int mid = (le + ri + 1) / 2;
      if (valy[mid] <= xv[pos]) {
        le = mid;
      } else {
        ri = mid - 1;
      }
    }
    if (le < valy.size() && valy[le] <= xv[pos]) {
      ans += (le - i);
    }
  }
  for (auto g : agax) {
    std::vector<int> tmpv = g.second;
    sort(tmpv.begin(), tmpv.end());
    for (int i = 0; i < tmpv.size(); i++) {
      int tmpy = tmpv[i];
      int pos = lower_bound(yv + 1, yv + m + 1, tmpy) - yv;
      if (pos <= m && yv[pos] <= tmpy) {
        continue;
      }
      int le = i + 1;
      int ri = tmpv.size() - 1;
      while (le < ri) {
        int mid = (le + ri + 1) / 2;
        if (tmpv[mid] <= yv[pos]) {
          le = mid;
        } else {
          ri = mid - 1;
        }
      }
      if (le < tmpv.size() && tmpv[le] <= yv[pos]) {
        ans -= (le - i);
      }
    }
  }
  for (auto g : agay) {
    std::vector<int> tmpv = g.second;
    sort(tmpv.begin(), tmpv.end());
    for (int i = 0; i < tmpv.size(); i++) {
      int tmpx = tmpv[i];
      int pos = lower_bound(xv + 1, xv + n + 1, tmpx) - xv;
      if (pos <= n && xv[pos] <= tmpx) {
        continue;
      }
      int le = i + 1;
      int ri = tmpv.size() - 1;
      while (le < ri) {
        int mid = (le + ri + 1) / 2;
        if (tmpv[mid] <= xv[pos]) {
          le = mid;
        } else {
          ri = mid - 1;
        }
      }
      if (le < tmpv.size() && tmpv[le] <= xv[pos]) {
        ans -= (le - i);
      }
    }
  }
  printf("%lld\n", ans);
}
int main() {
  int tm = 1;
  scanf("%d", &(tm));
  for (int i = 1; i <= tm; i++) {
    solve();
  }
  return 0;
}
