Monocarp is the coach of the Berland State University programming teams. He decided to compose a problemset for a training session for his teams.

Monocarp has n problems that none of his students have seen yet. The i-th problem has a topic a_i (an integer from 1 to n) and a difficulty b_i (an integer from 1 to n). All problems are different, that is, there are no two tasks that have the same topic and difficulty at the same time.

Monocarp decided to select exactly 3 problems from n problems for the problemset. The problems should satisfy at least one of two conditions (possibly, both):

  * the topics of all three selected problems are different; 
  * the difficulties of all three selected problems are different. 



Your task is to determine the number of ways to select three problems for the problemset.

Input

The first line contains a single integer t (1 ≤ t ≤ 50000) — the number of testcases.

The first line of each testcase contains an integer n (3 ≤ n ≤ 2 ⋅ 10^5) — the number of problems that Monocarp have.

In the i-th of the following n lines, there are two integers a_i and b_i (1 ≤ a_i, b_i ≤ n) — the topic and the difficulty of the i-th problem.

It is guaranteed that there are no two problems that have the same topic and difficulty at the same time.

The sum of n over all testcases doesn't exceed 2 ⋅ 10^5.

Output

Print the number of ways to select three training problems that meet either of the requirements described in the statement.

Example

Input


2
4
2 4
3 4
2 1
1 3
5
1 5
2 4
3 3
4 2
5 1


Output


3
10

Note

In the first example, you can take the following sets of three problems:

  * problems 1, 2, 4; 
  * problems 1, 3, 4; 
  * problems 2, 3, 4. 



Thus, the number of ways is equal to three.
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;

#define pb push_back
#define F first
#define S second
#define ld long double
#define pii pair<int,int>
#define int int64_t
#define __int128_t int64_t
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N = 100001;
const int M = 1e9+7;

void solve ()
{
    int n;
    cin >> n;
    int a[n], b[n];
    pii c[n];
    vector <int> p[n+1];
    for (int i=0;i<n;++i) {
        cin >> a[i] >> b[i];
        c[i] = {a[i], b[i]};
        p[b[i]].push_back(i);
    }
    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);
    int ans = 0;
    vector <int> v;
    int cnt = 1;
    v.push_back(0);
    for (int i=0;i<n-1;++i) {
        if (a[i+1] == a[i]) {cnt++;continue;}
        ans += cnt * ((i+1)-cnt) * (n-i-1);
        v.push_back(i);
        cnt = 1;
    }
    cnt = 1;
    for (int i=0;i<n-1;++i) {
        if (b[i+1] == b[i]) {cnt++;continue;}
        ans += cnt * ((i+1)-cnt) * (n-i-1);
        cnt = 1;
    }
    v.push_back(n-1);
    int kp = 0;
    map <int, int> k1, k2;
    for (int i=0;i<=v[1];++i) {
        k1[c[i].S]++;
    }
    if (v.size() > 2) {
        for (int i=v[2]+1;i<n;++i) {
            kp -= k1[c[i].S]*k2[c[i].S];
            k2[c[i].S]++;
            kp += k1[c[i].S]*k2[c[i].S];
        }
    }
//    cout << v.size() << '\n';
    for (int z=2;z<v.size();++z) {
//        cout << z << endl;
        int i = v[z-1], j = v[z];
        int s = v[z-2];
        for (int x=i+1;x<=j;++x) {
            int l = -1, r = p[c[x].S].size();
            while (l < r) {
                int m = (l+r+1)/2;
                if (p[c[x].S][m] <= i)
                    l = m;
                else
                    r = m-1;
            }
            int kk1 = l+1;
            l = -1, r = p[c[x].S].size();
            while (l < r) {
                int m = (l+r)/2;
                if (p[c[x].S][m] > j)
                    {
                        l = max(l, 0ll);
                        r = m;
                    }
                else
                    l = m+1;
            }
            int kk2 = p[c[x].S].size() - l;
            ans -= (i-kk1+1) * (n-j-kk2-1) - kp +
             k1[c[x].S] * k2[c[x].S];
        }
        for (int x=i+1;x<=j;++x) {
            kp -= k1[c[x].S]*k2[c[x].S];
            k1[c[x].S]++;
            kp += k1[c[x].S]*k2[c[x].S];
        }
        if (z < v.size() - 1) {
            for (int x=v[z]+1;x<=v[z+1];++x) {
                kp -= k1[c[x].S]*k2[c[x].S];
                k2[c[x].S]--;
                kp += k1[c[x].S]*k2[c[x].S];
            }
        }
    }
    cout << ans << '\n';
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int q = 1;
    cin >> q;
    for (;q;--q) {
        solve();
    }
    return 0;
}

