#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <numeric>
#include <cassert>

#define endl '\n'
#define sp ' '

#define pb push_back
#define mp make_pair
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main(){
    
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
    int t;cin>>t;
    while(t--){
        int a,b,k;cin>>a>>b>>k;
        vector<int> as(a+1),bs(b+1);
        vector<pii> couple(k+1);
        for(int i=0;i<k;i++){
            cin>>couple[i].ff;
            as[couple[i].ff]++;
        }
        for(int i=0;i<k;i++){
            cin>>couple[i].ss;
            bs[couple[i].ss]++;
        }   
        ll ans = 0;
        int orgk = k;
        for(int i=0;i<orgk;i++){
            //cerr << couple[i].ff << sp << couple[i].ss << sp << k-as[couple[i].ff]-bs[couple[i].ss]+1 << endl;
            ans += k-as[couple[i].ff]-bs[couple[i].ss]+1;
            as[couple[i].ff]--;
            bs[couple[i].ss]--;
            k--;
        }
        cout << ans << endl;
    }
    
}











