Almir had a small sequence $A_1, A_2, \ldots, A_N$. He decided to make $K$ copies of this sequence and concatenate them, forming a sequence $X_1, X_2, \ldots, X_{NK}$; for each valid $i$ and $j$ ($0 \le j < K$), $X_{j \cdot N + i} = A_i$.
For example, if $A = (1, 2, 3)$ and $K = 4$, the final sequence is $X = (1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3)$.
A pair $(i, j)$, where $1 \le i < j \le N$, is an inversion if $X_i > X_j$. Find the number of inversions in the final sequence $X$.
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains two space-separated integers $N$ and $K$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.
-----Output-----
For each test case, print a single line containing one integer ― the number of inversions in the sequence $X$.
-----Constraints-----
- $1 \le T \le 1,000$
- $1 \le N \le 100$
- $1 \le K \le 10^6$
- $1 \le A_i \le 10^9$ for each valid $i$
-----Subtasks-----
Subtask #1 (100 points): original constraints
-----Example Input-----
2
3 3
2 1 3
4 100
99 2 1000 24
-----Example Output-----
12
30000
# cook your dish here
for _ in range(int(eval(input()))):
    n, k = list(map(int, input().split()))
    arr = list(map(int, input().split()))
    x, suffix = 0, 0
    for i, a_i in enumerate(arr):
        for a_j in arr:
            if a_i > a_j: x += 1
        for j in range(i+1, n):
            if a_i > arr[j]: suffix += 1
            
    ans = x*( (k*(k-1))//2 ) + suffix*k
    print(ans)
# cook your dish here
for _ in range(int(eval(input()))):
    n, k = list(map(int, input().split()))
    arr = list(map(int, input().split()))
    x, suffix = 0, 0
    for i, a_i in enumerate(arr):
        for a_j in arr:
            if a_i > a_j: x += 1
        for j in range(i+1, n):
            if a_i > arr[j]: suffix += 1
            
    ans = x*( (k*(k-1))//2 ) + suffix*k
    print(ans)