#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long N = 2e5 + 5;
long long a[N];
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  long long tests;
  cin >> tests;
  while (tests--) {
    long long n, m, k;
    cin >> n >> m >> k;
    set<long long> H, V;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      V.insert(x);
    }
    for (long long i = 0; i < m; i++) {
      long long x;
      cin >> x;
      H.insert(x);
    }
    vector<pair<long long, long long>> v(k);
    for (long long i = 0; i < k; i++) {
      long long x, y;
      cin >> x >> y;
      v.push_back({x, y});
    }
    vector<pair<long long, long long>> Hori, vert;
    for (auto p : v) {
      long long x = p.first;
      long long y = p.second;
      if (!V.count(x))
        Hori.push_back({x, y});
      else if (!H.count(y))
        vert.push_back({y, x});
    }
    sort(Hori.begin(), Hori.end());
    sort(vert.begin(), vert.end());
    vector<long long> ho, ve;
    for (auto it : V) ve.push_back(it);
    for (auto it : H) ho.push_back(it);
    long long ans = 0;
    for (long long i = 0; i < ve.size() - 1; i++) {
      long long x1 = ve[i];
      long long x2 = ve[i + 1];
      pair<long long, long long> p = {x1, INF};
      long long l = lower_bound(Hori.begin(), Hori.end(), p) - Hori.begin();
      p = {x2, 0};
      long long r = upper_bound(Hori.begin(), Hori.end(), p) - Hori.begin();
      r--;
      map<long long, long long> mp;
      for (long long m = l; m <= r; m++) mp[Hori[m].second]++;
      for (auto it : mp) {
        ans -= it.second * (it.second - 1) / 2;
      }
      long long d = r - l + 1;
      if (d >= 1) {
        ans += d * (d - 1) / 2;
      }
    }
    for (long long i = 0; i < ho.size() - 1; i++) {
      long long y1 = ho[i];
      long long y2 = ho[i + 1];
      pair<long long, long long> p = {y1, INF};
      long long l = lower_bound(vert.begin(), vert.end(), p) - vert.begin();
      p = {y2, 0};
      long long r = upper_bound(vert.begin(), vert.end(), p) - vert.begin();
      r--;
      map<long long, long long> mp;
      for (long long m = l; m <= r; m++) mp[vert[m].second]++;
      for (auto it : mp) {
        ans -= it.second * (it.second - 1) / 2;
      }
      long long d = r - l + 1;
      if (d >= 1) {
        ans += d * (d - 1) / 2;
      }
    }
    cout << ans << '\n';
  }
}
