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.
from collections import defaultdict
t = int(input()) # read a line with a single integer
for i in range(1, t + 1):
    n = int(input())
    t_dict = defaultdict(int)
    d_dict = defaultdict(int)
    qns = []
    for _ in range(n):
        t, d = list(map(int, input().split()))
        t_dict[t] += 1
        d_dict[d] += 1
        qns.append((t,d))
    
    t_d_dict = defaultdict(int)
    d_t_dict = defaultdict(int)
    for qn in qns:
        t, d = qn
        t_d_dict[t] += d_dict[d]
        d_t_dict[d] += t_dict[t]
    
    res = n*(n-1)*(n-2)//6
    accum = 0
    # print(t_dict)
    # print(d_dict)
    # print(t_d_dict)
    # print(d_t_dict)
    for qn in qns:
        t, d = qn
        n_t = t_dict[t] - 1
        n_d = d_dict[d] - 1
        n_t_d = t_d_dict[t] - d_dict[d]
        n_d_t = d_t_dict[d] - t_dict[t]
        # share t
        accum += n_t*d_dict[d] - 2*n_t + n_t_d
        # print(n_t*d_dict[d] - 2*n_t + n_t_d)
        # share d
        accum += n_d*t_dict[t] - 2*n_d + n_d_t
        # print(n_d*t_dict[t] - 2*n_d + n_d_t)
        # print(qn, n_t, n_d, n_t_d, n_d_t)
    # print(res)
    # print(accum)
    # assert accum% 4 == 0
    # assert (res-6*accum//4) % 6 == 0
    print((res-accum)//4)
        
    
    # get all topics
    # total_t = 0
    # for t in t_dict:
    #     total_t += t_dict[t] * t_dict[t]
    # res_topic = 0
    # for qn in qns:
    #     t, d = qn
    #     left = total_t - t_dict[t] * t_dict[t]
    #     res_topic += (n-t_dict[t])*(n-t_dict[t]) - left

    # # get all diff
    # total_d = 0
    # for d in d_dict:
    #     total_d += d_dict[d] * d_dict[d]
    # res_diff = 0
    # for qn in qns:
    #     t, d = qn
    #     left = total_d - d_dict[d] * d_dict[d]
    #     res_diff += (n-d_dict[d])*(n-d_dict[d]) - left

    # # get intersection, double count
    # comb_dict = defaultdict(int)
    # for qn in qns:
    #     t, d = qn
    #     comb_dict[qn] = t_dict[t] + d_dict[d] - 1
    
    # res_comb = 0
    # total_comb = 0
    # for qn in comb_dict:
    #     total_comb += comb_dict[qn]
    # for qn in qns:
    #     t, d = qn
    #     left = n - t_dict[t] - d_dict[d] + 1
    #     print((n-comb_dict[qn])*(n-comb_dict[qn]) - left + t_dict[t] - 1 + d_dict[d] - 1)
    #     res_comb += (n-comb_dict[qn])*(n-comb_dict[qn]) - left + t_dict[t] - 1 + d_dict[d] - 1
    
    # assert res_topic%6==0
    # assert res_diff%6==0
    # assert res_comb%6==0
    # print((res_topic+res_diff-res_diff)//6)