#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <map>
using namespace std;
using ll = long long;

void solve() {
    int a,b,k;
    ll ans = 0;
    cin >> a >> b >> k;
    map<int,int> x , y;
    int temp;
    for(int i = 0; i< k;i++){
        cin >> temp;
        x[temp]++;
    }
    for(int i = 0; i< k;i++){
        cin >> temp;
        y[temp]++;
    }
    ans = (long long)k * (k - 1) / 2;
    for(auto & [x, z] : x){
        ans -= (long long)z * (z - 1) / 2;
    }
    for(auto & [x, z] : y){
        ans -= (long long)z * (z - 1) / 2;
    }
    cout << ans << endl;
    return;
    
}

int main() {
    long long n,t;

    cin >> t;
    while(t--){
        solve();
        
    }

    return 0;
}