Correct and detailed answer will upvoted else downvoted . Skip if you don't know. Monocarp is the mentor of the Berland State University programming groups. He chose to form a problemset for an instructional meeting for his groups. Monocarp has n issues that none of his understudies
Correct and detailed answer will upvoted else downvoted . Skip if you don't know.
Monocarp is the mentor of the Berland State University
Monocarp has n issues that none of his understudies have seen at this point. The I-th issue has a subject man-made intelligence (an integer from 1 to n) and a trouble bi (an integer from 1 to n). All issues are unique, that is, there are no two assignments that have a similar theme and trouble simultaneously.
Monocarp chose to choose precisely 3 issues from n issues for the problemset. The issues ought to fulfill somewhere around one of two conditions (potentially, both): the subjects of each of the three chose issues are unique; the troubles of every one of the three chose issues are unique. Your errand is to decide the number of ways of choosing three issues for the problemset.
Input :The primary line contains a solitary integer t (1≤t≤50000) — the number of testcases. The primary line of each testcase contains an integer n (3≤n≤2⋅105) — the number of issues that Monocarp have. In the I-th of the accompanying n lines, there are two integers computer based intelligence and bi (1≤
It is ensured that there are no two issues that have a similar subject and trouble simultaneously. The amount of n over all testcases doesn't surpass 2⋅105.
Output :Print the number of ways of choosing three preparing issues that meet both of the prerequisites depicted in the assertion.
Step by step
Solved in 4 steps with 1 images