Under construction

Still being built. Things may change

Tribal War

Interview

Time limit3sMemory limit512 MB

Summary
Given N tribes where listed pairs are allied and all other pairs are hostile, count the number of triples that are all allied or all hostile.
Level

Medium5 of 10

Topics
Combinatorics, Math, Graph, Implementation
Solved
No attempts yet

Problem

On a certain planet live NN small tribes. For convenience, number the tribes from 11 to NN.

  • Any two distinct tribes are either allied or hostile. This relation is symmetric, so there is no case where tribe A considers tribe B an ally while B considers A an enemy.
  • Even if tribe A and tribe B are allied and tribe B and tribe C are allied, tribe A and tribe C may be hostile.
  • For any three distinct tribes, if all three are allied, call it a three-way alliance, and if all three are hostile, call it a three-way hostility.

Find the total number of distinct three-way alliances and three-way hostilities among the NN tribes.

For example, suppose N=5N = 5, tribes 1 and 2, tribes 1 and 3, and tribes 4 and 5 are allied, and every other pair of tribes is hostile. Then (2,3,4)(2, 3, 4) and (2,3,5)(2, 3, 5) form three-way hostilities and there is no three-way alliance, so the answer is 22.

As another example, suppose N=5N = 5 and tribes 1 and 2, tribes 2 and 3, and tribes 1 and 3 are allied. Then (1,2,3)(1, 2, 3) is a three-way alliance, and (1,4,5)(1, 4, 5), (2,4,5)(2, 4, 5), (3,4,5)(3, 4, 5) are three-way hostilities, so the answer is 44.

Input

The first line gives the number of test cases TT. (1≤T≤101 \le T \le 10)

The first line of each test case gives NN and MM, separated by a space.

The next MM lines each give two integers xx and yy, meaning that xx and yy are allied.

Every alliance given in the input satisfies 1≤x<y≤N1 \le x < y \le N, and the same pair of tribes is never given more than once.

A pair of tribes that does not appear in the input is assumed to be hostile.

Output

For each test case, print the alliance-antialliance coefficient on one line.

Examples1

  1. Example 1

    Input
    3
    3 1
    1 2
    5 3
    1 2
    2 3
    1 3
    5 3
    1 2
    1 3
    4 5
    
    Expected output
    0
    4
    2