#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map


void doit(){
	ll b, g, k; cin >> b >> g >> k;
	vector<pii>p(k);
	vector<ll>B(b + 2), G(g + 2);
	for(ll i = 0; i < k; i++){
		cin >> p[i].ff;
		B[p[i].ff]++;
	}
	for(ll i = 0; i < k; i++){
		cin >> p[i].ss;
		G[p[i].ss]++;
	}
	ll ans = 0;
	for(ll i = 0; i < k ; i++){
		ans += (k - i - 1) - (B[p[i].ff] + G[p[i].ss] - 2);
		B[p[i].ff]--;
		G[p[i].ss]--;
	}
	cout << ans << nl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
	cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}
