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

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = "from math import *\r\nfrom collections import *\r\nfrom itertools import *\r\nfrom bisect import *\r\nfrom heapq import *\r\nfrom operator import *\r\nfrom sys import *\r\nsetrecursionlimit(1000000)\r\nd=defaultdict(lambda:0,{})\r\ndef io():\r\n    return map(int,input().split())\r\ndef op():\r\n    return list(map(int,input().split()))\r\ndef o():\r\n    return int(input())\r\ndef r(x):\r\n    if type(x)==int:\r\n        return range(x)\r\n    else:return range(len(x))\r\ndef kl(con,x=0):\r\n    if x==0:print('Yes') if con else print('No')\r\n    elif x==1:print('yes') if con else print('no')\r\n    elif x==2:print('YES') if con else print('NO')\r\nMOD = 1000000007\r\nMAX=float('inf')\r\nMIN=-float('inf')\r\np=input\r\nfor _ in r(o()):\r\n    n,k=io()\r\n    l=op()\r\n    ans=0\r\n    for i in r(l):\r\n        for j in r(l):\r\n            if l[i]>l[j]:\r\n                if i>j:\r\n                    ans+=k*(k-1)/2\r\n                elif i<j:\r\n                    ans+=k*(k+1)/2\r\n    print(int(ans))\r\n\r\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 28155