#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.14159265358979323846;
const long long int MAX_N = 2e5 + 5;
long long int binpow(long long int a, long long int b, long long int mod) {
  long long int ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b = b >> 1;
  }
  return ans;
}
long long int fact[MAX_N], invf[MAX_N];
void precompute_factorial() {
  fact[0] = 1;
  for (long long int i = 1; i < MAX_N; i++) {
    fact[i] = fact[i - 1] * i % 998244353;
    invf[i] = binpow(fact[i], 998244353 - 2, 998244353);
  }
}
long long int nCk(long long int n, long long int k) {
  if (n == k) return 1;
  if (k == 0) return 1;
  if (k < 0 || k > n) return 0;
  return fact[n] * invf[k] % 998244353 * invf[n - k] % 998244353;
}
void solve() {
  long long int n, m, k;
  cin >> n >> m >> k;
  set<long long int> row, col;
  for (long long int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    row.insert(x);
  }
  for (long long int i = 0; i < m; i++) {
    long long int x;
    cin >> x;
    col.insert(x);
  }
  map<long long int, long long int> indX, indY;
  long long int c1 = 0, c2 = 0;
  for (auto i : row) {
    indX[i] = c1;
    c1++;
  }
  for (auto j : col) {
    indY[j] = c2;
    c2++;
  }
  vector<long long int> rowC(row.size()), colC(col.size());
  map<pair<long long int, long long int>, long long int> x, y;
  long long int ans = 0;
  for (long long int i = 0; i < k; i++) {
    long long int a, b;
    cin >> a >> b;
    auto it = row.find(a);
    auto it2 = col.find(b);
    if (it != row.end() && it2 != col.end()) {
      continue;
    }
    if (it != row.end()) {
      auto it3 = col.upper_bound(b);
      x[{indY[*it3], a}]++;
      colC[indY[*it3]]++;
      ans += colC[indY[*it3]] - x[{indY[*it3], a}];
    }
    if (it2 != col.end()) {
      auto it3 = row.upper_bound(a);
      y[{indX[*it3], b}]++;
      rowC[indX[*it3]]++;
      ans += rowC[indX[*it3]] - y[{indX[*it3], b}];
    }
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  long long int t = 1;
  precompute_factorial();
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
