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 = "import sys\nfrom random import choice,randint\ninp=sys.stdin.readline\nout=sys.stdout.write\nflsh=sys.stdout.flush\n \nsys.setrecursionlimit(10**9)\ninf = 10**20\neps = 1.0 / 10**10\nmod = 10**9+7\ndd = [(-1,0),(0,1),(1,0),(0,-1)]\nddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n \ndef MI(): return map(int, inp().strip().split())\ndef LI(): return list(map(int, inp().strip().split()))\ndef LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]\ndef LI_(): return [int(x)-1 for x in inp().strip().split()]\ndef LF(): return [float(x) for x in inp().strip().split()]\ndef LS(): return inp().strip().split()\ndef I(): return int(inp().strip())\ndef F(): return float(inp().strip())\ndef S(): return inp().strip()\ndef pf(s): return out(s+'\\n')\ndef JA(a, sep): return sep.join(map(str, a))\ndef JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)\n\ndef main():\n    t = I()\n    l = []\n    for _ in range(t):\n        n,k=MI()\n        a=LI()\n        lcf=[0]*n\n        lce=[0]*n\n        for i in range(n):\n            cnt1,cnt2=0,0\n            for j in a[:i]:\n                if j<a[i]:\n                    cnt1+=1\n            for j in a[i:]:\n                if j<a[i]:\n                    cnt2+=1\n            lcf[i]=cnt1\n            lce[i]=cnt2\n        ans=0\n        for i in range(n):\n            ans += lcf[i]*((k*(k-1))//2)\n        for i in range(n):\n            ans += lce[i]*((k*(k+1))//2)\n        l.append(ans)\n\n    for i in range(t):\n        pf(str(l[i]))\n\ndef __starting_point():\n    main()\n__starting_point()"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 16913