ZZX has a sequence a, which is a permutation of 1,2,…,n. Now ZZX wants to perform some modifications on this sequence. For each modification, he can choose a pair of integers i and j, satisfying 1≤i<j≤n and a_i>a_j, and then swap a_i and a_j.
If a permutation b can be obtained by performing some (possibly zero) modifications on the initial sequence a, then ZZX says b is reachable from a.
Now JRY has m sequences a(1), a(2), …, a(m). Each of them is a permutation of 1,2,…,n. He wants to know how many pairs (i,j) such that 1≤i≤m and 1≤j≤m have the property that a_i is reachable from a_j.
The first line contains an integer T. Then T test cases follow. In each test case:
The first line contains two integers n and m. After that, m lines follow. The k-th of them contains n integers a(k)_1, a(k)_2, …, a(k)_n. Each a(k) is a permutation of 1,2,…,n.
There are at most 1000 small test cases and 1 large test case. The small test cases satisfy 1≤n≤5 and 1≤m≤500. The large test case satisfies 1≤n≤9 and 1≤m≤3⋅105.
For each test case, print the answer on a separate line.