#include <bits/stdc++.h>
#define int long long
#define mk make_pair
#define gcd __gcd
using namespace std;
const double eps = 1e-10;
const int mod = 1e9+7;
const int N = 3e5+7;
int n,m,k,t = 1,cas = 1;
int a[N],b[N];
map<int,int> mp1,mp2;
map<pair<int,int>,int> mp3;
 
signed main(){
    cin>>t;
    while(t--){
        cin>>n>>m>>k;
        mp1.clear(),mp2.clear(),mp3.clear();
        for(int i = 0 ; i < k ; i ++) cin>>a[i],mp1[a[i]] ++;
        for(int i = 0 ; i < k ; i ++) cin>>b[i],mp2[b[i]] ++,mp3[{a[i],b[i]}] ++;
        int res = 0;
        for(int i = 0 ; i < k ; i ++){
            res += (k)-mp1[a[i]]-mp2[b[i]]+1;
        }
        cout<<res/2<<endl;
    }
    return 0;
}