#include<bits/stdc++.h>
#include<iostream>
#define ll long long


using namespace std;

//typedef long long ll;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    ll t;
    cin >> t;
    while(t--)
    {
        ll a,b,k;
        cin >> a >> b >> k;
        vector<ll> arr(k+1),arr1(k+1);
        map<ll,ll> mp1,mp2;
        for(ll i=1;i<=k;i++)
        {
            cin >> arr[i];
            mp1[arr[i]]++;
        }
        for(ll i=1;i<=k;i++)
        {
            cin >> arr1[i];
            mp2[arr1[i]]++;
        }

        ll ans = (1LL*k*(k-1))/2;

        for(auto ele : mp1)
        {
            //if(ele.second >=2)
            //{
                ll temp_ans = (ele.second*(ele.second-1))/2;
                ans-=temp_ans;
            //}
        }

        for(auto ele : mp2)
        {
           // if(ele.second>=2)
           // {
                ll temp_ans = (ele.second*(ele.second-1))/2;
                ans-=temp_ans;
            //}
        }
        cout << ans << "\n";

    }
    return 0;
}