#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
typedef long long lld;
typedef double lf;
typedef long double llf;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
typedef pair<lld, int> pli;
#define For(i,s,a) for(int i = (int)s; i < (int)a; ++i)
#define rpt(s, it) for(auto it = s.begin(); it != s.end(); ++it)
#define brpt(s, it) for(auto it = s.rend(); it != s.rbegin(); --it)
#define sz size()
#define pb push_back
#define eb emplace_back
#define ff first
#define dd second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ZAPS {int t; scanf("%i", &t); while(t--) solve();}
#define make_unique(x) (x).erase( unique(all(x)), (x).end())


template<typename Ta, typename Tb>
ostream & operator <<(ostream & os, pair<Ta, Tb> x){
	return os << x.ff << " " << x.dd;
}

const int N = 2e5 + 1;

int sta[N], stb[N];
int pa[N], pb[N];

void solve(void){
	int a, b, k;
	scanf("%d%d%d", &a, &b, &k);
	For(i, 0, max(a, b) + 1)
		sta[i] = stb[i] = 0;
	For(i, 0, k){
		int g;
		scanf("%d", &g);
		pa[i] = g;
		++sta[g];
	}
	For(i, 0, k){
		int g;
		scanf("%d", &g);
		pb[i] = g;
		++stb[g];
	}
	lld sum = 0;
	For(i, 0, k)
		sum += k - sta[pa[i]] - stb[pb[i]] + 1;
	printf("%lld\n", sum / 2);
	
}

int32_t main(void){
	ZAPS
}
