#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

void setIO(string name = "") {
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	if (sz(name)) {
		freopen((name + ".in").c_str(), "r", stdin);
		freopen((name + ".out").c_str(), "w", stdout);
	}
}

const int inf = 1e9;
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int MAXN = 2e5 + 5;

int a, b, k;
pair<int, int> p[MAXN];
int ctb[MAXN], ctg[MAXN];
map<pair<int, int>, int> ctboth;
int A[MAXN], B[MAXN];

void solve() {
	cin >> a >> b >> k;
	
	for (int i = 1; i <= a; i++) {
		ctb[i] = 0;
	}	
	
	for (int i = 1; i <= b; i++) {
		ctg[i] = 0;
	}
	
	ctboth.clear();
	
	for (int i = 1; i <= k; i++) {
		cin >> A[i];
	}
	
	for (int i = 1; i <= k; i++) {
		cin >> B[i];
		
		p[i] = mp(A[i], B[i]);
		ctb[p[i].F]++;
		ctg[p[i].S]++;
		ctboth[p[i]]++;
	}
	
	ll res = 0;
	for (int i = 1; i <= k; i++) {
		res += (k - ctb[p[i].F] - ctg[p[i].S] + ctboth[p[i]]);
	}
	
	res >>= 1;
	
	cout << res << '\n';	
}


int main() {
	setIO();
	
	int tt = 1;
	cin >> tt;
	while (tt--) {
		solve();
	}
	
	return 0;
}
