#include <bits/stdc++.h>
using namespace std;
long long visx[1000005], visy[1000005], cnt[1000005];
set<long long> xs, ys;
long long sol(vector<pair<long long, long long>> pr) {
  sort(pr.begin(), pr.end());
  queue<long long> q;
  long long ans = 0;
  for (long long i = 0; i < pr.size(); i++) {
    auto it = ys.upper_bound(pr[i].first);
    if (it == ys.begin()) continue;
    it--;
    while (q.size() && pr[q.front()].first <= *it) {
      cnt[pr[q.front()].second]--;
      q.pop();
    }
    ans += q.size() - cnt[pr[i].second];
    cnt[pr[i].second]++;
    q.push(i);
  }
  while (q.size()) {
    cnt[pr[q.front()].second]--;
    q.pop();
  }
  return ans;
}
void solve() {
  long long n, m, k;
  cin >> n >> m >> k;
  xs.insert(0);
  ys.insert(0);
  xs.insert(1000000);
  ys.insert(1000000);
  visx[0] = visx[1000000] = visy[0] = visy[1000000] = 1;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    xs.insert(x);
    visx[x] = 1;
  }
  for (long long i = 0; i < m; i++) {
    long long y;
    cin >> y;
    ys.insert(y);
    visy[y] = 1;
  }
  vector<pair<long long, long long>> vert, hor;
  for (long long i = 0; i < k; i++) {
    long long x, y;
    cin >> x >> y;
    if (visx[x] && visy[y]) continue;
    if (visx[x])
      vert.push_back({y, x});
    else
      hor.push_back({x, y});
  }
  for (auto &cv : xs) visx[cv] = 0;
  for (auto &cv : ys) visy[cv] = 0;
  long long ans = sol(vert);
  swap(xs, ys);
  ans += sol(hor);
  xs.clear(), ys.clear();
  cout << ans << endl;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
