#include<iostream>
#include<vector>
#include<set>
#include<map>
using namespace std;

struct pair{
    int xx;
    int yy;
};

int main() {
    int t;
    cin>>t;
    vector<long long int>result;
    while(t--)
    {
        int a,b,k;
        cin>>a>>b>>k;
        long long int total = 0;
        int x;
        map<int,int>store_a;
        map<int,int>store_b;
        vector<int>arr_a;
        vector<int>arr_b;
        for(int i=0;i<k;i++)
        {
            cin>>x;
            store_a[x]++;
            arr_a.push_back(x);
        }
        for(int i=0;i<k;i++)
        {
            cin>>x;
            store_b[x]++;
            arr_b.push_back(x);
        }
        for(int i=0;i<k;i++)
        {
           total = total + k-1-(store_a[arr_a[i]]-1) - (store_b[arr_b[i]]-1);
        }
        total = total/2;
        result.push_back(total);
    }
    for(auto i = result.begin();i!=result.end();i++)
    {
        cout<<*i<<endl;
    }
    return 0;
}