Inazuma 11 !

0

0 votes
Problem

In final football tournament , Endou Mamoru and his team Inazuma 11 with other teams tried to fight for the best two sportsperson position but not compromising with their friendship. In total there are N participants competing against each other for the top two spots. There are M friendly relations between participants some among the team members and some beyond that. In each friendship relation, you will be given two integers X and Y, indicating X and Y are friends.

P.S.: Don't Consider Fubuki's double personality disorder as friendship :P

If A and B are friends, B and C are friends, then A, B, C will have the same friend circle. Two combinations are considered different if either first or second ranker is different. The same friendship relation can occur multiple times in input, however, X will never be equal to Y.

Now, the jury has to decide the winners for the top two spots but they do not want to select both participants from the same friend circle so the competition seems fairer. Find the number of ways in which they can do so.

Input format

The first line contains T denoting the number of test cases. 

The first line of each test case contains two space-separated integers N and M denoting the number of participants and the number of friendly relations.

Next M lines of each test case contain two integers X and Y indicating a friendly relation between X and Y.

Output format

For each test case, print a single line denoting the number of ways in which the jury can choose the top two participants.

Constraints

1≤T≤20000

2≤N≤200000

1≤M≤500000

1≤X,Y≤N

Sum of N over all test cases does not exceed 200000 and M will not exceed 500000

Sample Input
2
3 1
1 3
4 2
1 2
3 4
Sample Output
4
8
Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?