#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define endl "\n"
#define int long long int
int number = 1, number1;
void solve()
{
    int a, b, k;
    cin >> a >> b >> k;
    unordered_map<int, int> m, m1;
    int boys[k];
    int girls[k];
    for (int i = 0; i < k; i++)
    {
        cin >> boys[i];
        m[boys[i]]++;
    }
    for (int i = 0; i < k; i++)
    {
        cin >> girls[i];
        m1[girls[i]]++;
    }
    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        ans = ans + (k) - (m[boys[i]] + m1[girls[i]] - 1);
    }
    cout << ans / 2 << endl;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("Input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("Output.txt", "w", stdout);
#endif
    int t = 1;
    cin >> t;
    while (t > 0)
    {
        solve();
        --t;
    }
    return 0;
}