#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
ll numa[N],numb[N];
ll a[N],b[N];
int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        
        ll x1,x2,k;
        cin >> x1 >> x2 >> k;
        for(int i=1;i<=max(x1,x2);i++)
        {
            numa[i] = 0;
            numb[i] = 0;
        }
        for(int i=1;i<=k;i++)
        {
            cin >> a[i];
            numa[a[i]]++;
        }
        for(int i=1;i<=k;i++)
        {
            cin >> b[i];
            numb[b[i]]++;
        }
        ll ans = k * (k - 1) / 2;
        for(int i=1;i<=x1;i++)
        {
            // cout << numa[i] << " ";
            ans -= numa[i] * (numa[i] - 1) / 2;
        }
        // cout << "\n";
        for(int i=1;i<=x2;i++)
        {
            ans -= numb[i] * (numb[i] - 1) / 2;
        }
        cout << ans << "\n";
    }
    return 0;
}