ZZX has a sequence a[1..n], which is a permutation of 1,2,...,n.
Now ZZX wants to perform some modifications on this sequence: every time he can choose a pair of integers i,j, satisfying 1<=i<j<=n and a[i]>a[j], then swap a[i] and a[j].
If a permutation b[1..n] can be obtained by performing some modifications (possibly nothing is performed) on the initial sequence a, then ZZX says b is reachable from a.
Now JRY has m sequences a_1[1..n], a_2[1..n], ..., a_m[1..n]. Each of them is a permutation of 1,2,...,n. He wants to know how many pairs of (i,j) (1<=i<=m,1<=j<=m) satisfy a_i is reachable from a_j.