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

int main(){
    long long t;
    cin>>t;
    while(t--){
        int a,b,n;
        long long ans=0;
        cin>>a>>b>>n;
        int ar[a+1],br[b+1],arr[2][n];
        memset(ar,0,sizeof(ar));
        memset(br,0,sizeof(br));
        for(int i=0;i<n;i++){
            cin>>arr[0][i];
            ar[arr[0][i]]++;
        }
        for(int i=0;i<n;i++){
            cin>>arr[1][i];
            br[arr[1][i]]++;
        }
        for(int i=0;i<n-1;i++){
            ans+=n-i-1 -ar[arr[0][i]]+1 -br[arr[1][i]]+1;
            ar[arr[0][i]]--;
            br[arr[1][i]]--;
        }
        cout<<ans<<endl;
    }
    return 0;
}
