human
Can you solve the below in PYTHON3?
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.
assistant
#Here is Python program to determine the number of ways to select three problems for the problemset.

# Author : nitish420 --------------------------------------------------------------------
import os
import sys
from io import BytesIO, IOBase
from collections import Counter

def main():
    for _ in range(int(input())):
        n=int(input())
        s=[]
        l=Counter()
        r=Counter()
        for _ in range(n):
            a,b=map(int,input().split())
            s.append((a,b))
            l[a]+=1
            r[b]+=1
        ans=((n*(n-1)*(n-2))//6)
        left=set()
        for i in l:
            if l[i]>1:
                left.add(i)
        right=set()
        for i in r:
            if r[i]>1:
                right.add(i)
        
        for i,j in s:
            if i in left and j in right:
                ans-=(l[i]-1)*(r[j]-1) 

        
        print(ans)

'''
1
4
2 4
3 4
2 1
1 3
'''

#----------------------------------------------------------------------------------------

# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
           ...