#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;

#define fi first
#define se second
#define mm(a,x) memset(a,x,sizeof a)
#define endl "\n"
#define inf 0x3f3f3f3f
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

const int N = 1e5 + 10;
const int mod = 1e9;

int t,n,m,k;

void solve(){
	cin >> n >> m >> k;
	vi cnt_a(n + 10),cnt_b(m + 10);
	vpii q(k + 10);
	for(int i = 0; i < k; i ++ ){
		cin >> q[i].fi;
		cnt_a[q[i].fi] ++;
	}
	for(int i = 0; i < k; i ++ ){
		cin >> q[i].se;
		cnt_b[q[i].se] ++;
	}		
	ll ans = 0;
	for(int i = 0; i < k; i ++ ){
		ans += k - cnt_a[q[i].fi] - cnt_b[q[i].se] + 1;
	}
	cout<<ans/2<<endl;
}

int main() {
	cin >> t;
	while(t --) {
		solve();
	}
	return 0;
}