H. Rainbow Energy
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Example
Input
2
3 2
1 3
1 3
2 3
4 3
2 2
2 2
3 3
3 4
Output
9
16