#K77727. Count Friendly Pairs
Count Friendly Pairs
Count Friendly Pairs
You are given several test cases. In each test case, there are n employees and m direct messages exchanged between them. Each message is represented as a pair of integers (u, v) indicating a message sent from employee u to employee v.
A friendly pair is defined as a pair of employees \( (u, v) \) (with \( u < v \)) such that both a message from \( u \) to \( v \) and a message from \( v \) to \( u \) exist in that test case. Even if there are multiple messages between the same pair, each friendly pair is counted only once.
Your task is to count the number of unique friendly pairs for each test case.
inputFormat
The input begins with an integer \( T \) indicating the number of test cases. For each test case:
- The first line contains two space-separated integers \( n \) and \( m \), where \( n \) is the number of employees and \( m \) is the number of messages.
- The next \( m \) lines each contain two space-separated integers \( u \) and \( v \) representing a message from employee \( u \) to employee \( v \).
All input is read from standard input (stdin).
outputFormat
For each test case, output a single integer on a new line – the number of unique friendly pairs in that test case. All output should be written to standard output (stdout).
## sample2
3 3
1 2
2 3
2 1
4 4
1 2
2 1
3 4
4 3
1
2
</p>