#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535897932384626433832795;
const int inf = 1e9;
const long long inf2 = 1e18;
const int mod = 1e9 + 7;
void boost() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}
const int M = 1e6 + 5;
bool mpx[M], mpy[M];
void solve() {
  int n, m, k;
  cin >> n >> m >> k;
  int x, y;
  vector<int> a1(n), a2(m);
  for (int i = 0; i < n; ++i) {
    cin >> x;
    a1[i] = x;
    mpx[x] = true;
  }
  for (int i = 0; i < m; ++i) {
    cin >> y;
    a2[i] = y;
    mpy[y] = true;
  }
  a1.push_back(inf);
  a2.push_back(inf);
  map<int, vector<int> > xx, yy;
  for (int i = 0; i < k; ++i) {
    cin >> x >> y;
    if (mpx[x] && mpy[y]) continue;
    if (mpx[x]) {
      yy[*lower_bound(a2.begin(), a2.end(), y)].push_back(x);
    } else {
      xx[*lower_bound(a1.begin(), a1.end(), x)].push_back(y);
    }
  }
  long long ans = 0;
  for (auto q : xx) {
    vector<int> &temp = q.second;
    int len = temp.size();
    sort(temp.begin(), temp.end());
    for (int i = 0; i < len; i++) {
      int j = i;
      while (j + 1 < len && temp[j + 1] == temp[i]) j++;
      ans = (ans + (j - i + 1) * 1LL * (len - 1 - j));
      i = j;
    }
  }
  for (auto q : yy) {
    vector<int> &temp = q.second;
    int len = temp.size();
    sort(temp.begin(), temp.end());
    for (int i = 0; i < len; i++) {
      int j = i;
      while (j + 1 < len && temp[j + 1] == temp[i]) j++;
      ans = (ans + (j - i + 1) * 1LL * (len - 1 - j));
      i = j;
    }
  }
  cout << ans << '\n';
  for (int i = 0; i < n; i++) mpx[a1[i]] = false;
  for (int i = 0; i < m; i++) mpy[a2[i]] = false;
  return;
}
int main() {
  boost();
  int tc = 1;
  cin >> tc;
  while (tc--) solve();
  return 0;
}
