#include <bits/stdc++.h>
using namespace std;
long long cont(vector<pair<long long, long long>> v) {
  sort(v.begin(), v.end());
  long long res = 0;
  long long va = 1;
  for (int i = 1, ggdem = ((int)v.size()); i < ggdem; ++i) {
    if (v[i].first == v[i - 1].first) {
      res += va;
      va++;
    } else {
      va = 1;
    }
  }
  va = 1;
  for (int i = 1, ggdem = ((int)v.size()); i < ggdem; ++i) {
    if (v[i] == v[i - 1]) {
      res -= va;
      va++;
    } else {
      va = 1;
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, m, k;
    cin >> n >> m >> k;
    vector<long long> x(n), y(m);
    for (int i = 0, ggdem = n; i < ggdem; ++i) cin >> x[i];
    for (int i = 0, ggdem = m; i < ggdem; ++i) cin >> y[i];
    set<long long> sx;
    for (auto i : x) sx.insert(i);
    set<long long> sy;
    for (auto i : y) sy.insert(i);
    vector<pair<long long, long long>> a(k);
    for (int i = 0, ggdem = k; i < ggdem; ++i) cin >> a[i].first >> a[i].second;
    vector<pair<long long, long long>> cx, cy;
    for (int i = 0, ggdem = k; i < ggdem; ++i) {
      if (sx.count(a[i].first) && sy.count(a[i].second)) continue;
      long long posx = lower_bound(x.begin(), x.end(), a[i].first) - x.begin();
      long long posy = lower_bound(y.begin(), y.end(), a[i].second) - y.begin();
      if (sx.count(a[i].first)) {
        cx.push_back({posx, posy});
      } else {
        cy.push_back({posx, posy});
      }
    }
    for (int i = 0, ggdem = ((int)cx.size()); i < ggdem; ++i)
      swap(cx[i].first, cx[i].second);
    long long res = 0;
    res += cont(cx);
    res += cont(cy);
    cout << res << "\n";
  }
  return 0;
}
