///THINK in a GENERAl way please...
///generate random cases for your idea
///generate corner cases for your idea
///think for a better IMP
///test your code several times with corner cases
///check if there is no overflow int*int
///check you are not missing something from the problem statement
#include <bits/stdc++.h>
typedef long long  ll;
typedef long double  ld;
typedef unsigned long long  ull;
using namespace std;
#define DADAH ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int const N = 2e5 + 5;
#define EPS 1e- 6
int main()
{
    DADAH

    map<int,pair<int,int>>mp;
    vector<pair<int,int>>vec;
    int t;
    cin>>t;
    while(t--)
    {
        mp.clear();
        vec.clear();
        int a,w,k;
        cin>>a>>w>>k;
        vector<int>b(k),g(k);
        for(int i=0; i<k; i++)
        {

            cin>>b[i];
            mp[b[i]].first++;

        }
        for(int i=0; i<k; i++)
        {
            cin>>g[i];
            mp[g[i]].second++;
        }


          for(int i=0; i<k; i++)
        {
            vec.emplace_back(b[i],g[i]);
        }





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

//cout<<"Ncr: "<< ans<<endl;
        for(int i=0; i<k; i++)
        {

           mp[vec[i].first].first--;
           mp[vec[i].second].second--;

           if(mp[vec[i].first].first>0)ans-=mp[vec[i].first].first;
           if(mp[vec[i].second].second>0)ans-=mp[vec[i].second].second;

        }

        cout<<ans<<endl;


    }





    return 0 ;
}
