description: It is the easy version of the problem. The only difference is that in this version n = 1.
  
  In the cinema seats can be represented as the table with n rows and m columns. The rows are numbered with integers from 1 to n. The seats in each row are numbered with consecutive integers from left to right: in the k-th row from m (k - 1) + 1 to m k for all rows 1 ≤ k ≤ n.
  
  1| 2| ⋅⋅⋅| m - 1| m  
  ---|---|---|---|---  
  m + 1| m + 2| ⋅⋅⋅| 2 m - 1| 2 m  
  2m + 1| 2m + 2| ⋅⋅⋅| 3 m - 1| 3 m  
  \vdots| \vdots| \ddots| \vdots| \vdots  
  m (n - 1) + 1| m (n - 1) + 2| ⋅⋅⋅| n m - 1| n m  
  The table with seats indices
  
  There are nm people who want to go to the cinema to watch a new film. They are numbered with integers from 1 to nm. You should give exactly one seat to each person.
  
  It is known, that in this cinema as lower seat index you have as better you can see everything happening on the screen. i-th person has the level of sight a_i. Let's define s_i as the seat index, that will be given to i-th person. You want to give better places for people with lower sight levels, so for any two people i, j such that a_i < a_j it should be satisfied that s_i < s_j.
  
  After you will give seats to all people they will start coming to their seats. In the order from 1 to nm, each person will enter the hall and sit in their seat. To get to their place, the person will go to their seat's row and start moving from the first seat in this row to theirs from left to right. While moving some places will be free, some will be occupied with people already seated. The inconvenience of the person is equal to the number of occupied seats he or she will go through.
  
  Let's consider an example: m = 5, the person has the seat 4 in the first row, the seats 1, 3, 5 in the first row are already occupied, the seats 2 and 4 are free. The inconvenience of this person will be 2, because he will go through occupied seats 1 and 3.
  
  Find the minimal total inconvenience (the sum of inconveniences of all people), that is possible to have by giving places for all people (all conditions should be satisfied).
  
  Input
  
  The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. Description of the test cases follows.
  
  The first line of each test case contains two integers n and m (n = 1, 1 ≤ m ≤ 300) — the number of rows and places in each row respectively.
  
  The second line of each test case contains n ⋅ m integers a_1, a_2, …, a_{n ⋅ m} (1 ≤ a_i ≤ 10^9), where a_i is the sight level of i-th person.
  
  It's guaranteed that the sum of n ⋅ m over all test cases does not exceed 10^5.
  
  Output
  
  For each test case print a single integer — the minimal total inconvenience that can be achieved.
  
  Example
  
  Input
  
  
  4
  1 3
  1 2 3
  1 5
  2 1 5 3 3
  1 2
  2 1
  1 6
  2 3 2 1 1 1
  
  
  Output
  
  
  3
  6
  0
  1
  
  Note
  
  In the first test case, there is a single way to arrange people, because all sight levels are distinct. The first person will sit on the first seat, the second person will sit on the second place, the third person will sit on the third place. So inconvenience of the first person will be 0, inconvenience of the second person will be 1 and inconvenience of the third person will be 2. The total inconvenience is 0 + 1 + 2 = 3.
  
  In the second test case, people should sit as follows: s_1 = 2, s_2 = 1, s_3 = 5, s_4 = 4, s_5 = 3. The total inconvenience will be 6.
solution: import java.io.*;
  import java.util.*;
  import java.math.BigInteger;
  
  /**
   __                  __
   ( _)                ( _)
   / / \\              / /\_\_
   / /   \\            / / | \ \
   / /     \\          / /  |\ \ \
   /  /   ,  \ ,       / /   /|  \ \
   /  /    |\_ /|      / /   / \   \_\
   /  /  |\/ _ '_| \   / /   /   \    \\
   |  /   |/  0 \0\    / |    |    \    \\
   |    |\|      \_\_ /  /    |     \    \\
   |  | |/    \.\ o\o)  /      \     |    \\
   \    |     /\\`v-v  /        |    |     \\
   | \/    /_| \\_|  /         |    | \    \\
   | |    /__/_ `-` /   _____  |    |  \    \\
   \|    [__]  \_/  |_________  \   |   \    ()
   /    [___] (    \         \  |\ |   |   //
   |    [___]                  |\| \|   /  |/
   /|    [____]                  \  |/\ / / ||
   (  \   [____ /     ) _\      \  \    \| | ||
   \  \  [_____|    / /     __/    \   / / //
   |   \ [_____/   / /        \    |   \/ //
   |   /  '----|   /=\____   _/    |   / //
   __ /  /        |  /   ___/  _/\    \  | ||
   (/-(/-\)       /   \  (/\/\)/  |    /  | /
   (/\/\)           /   /   //
   _________/   /    /
   \____________/    (
  
  
   @author NTUDragons-Reborn
   */
  
  public class Solution{
      public static void main(String[] args) {
          InputStream inputStream = System.in;
          OutputStream outputStream = System.out;
          InputReader in = new InputReader(inputStream);
          PrintWriter out = new PrintWriter(outputStream);
          Task solver = new Task();
          solver.solve(in, out);
          out.close();
      }
      // main solver
      static class Task{
  
          double eps= 0.00000001;
          static final int MAXN = 200015;
          static final int MOD= 1000000007;
  
          // stores smallest prime factor for every number
          static int spf[] = new int[MAXN];
  
          static boolean[] prime;
  
          Map<Integer,Set<Integer>> dp= new HashMap<>();
  
          // Calculating SPF (Smallest Prime Factor) for every
          // number till MAXN.
          // Time Complexity : O(nloglogn)
          public void sieve()
          {
              spf[1] = 1;
              for (int i=2; i<MAXN; i++)
  
                  // marking smallest prime factor for every
                  // number to be itself.
                  spf[i] = i;
  
              // separately marking spf for every even
              // number as 2
              for (int i=4; i<MAXN; i+=2)
                  spf[i] = 2;
  
              for (int i=3; i*i<MAXN; i++)
              {
                  // checking if i is prime
                  if (spf[i] == i)
                  {
                      // marking SPF for all numbers divisible by i
                      for (int j=i*i; j<MAXN; j+=i)
  
                          // marking spf[j] if it is not
                          // previously marked
                          if (spf[j]==j)
                              spf[j] = i;
                  }
              }
          }
  
          void sieveOfEratosthenes(int n)
          {
              // Create a boolean array
              // "prime[0..n]" and
              // initialize all entries
              // it as true. A value in
              // prime[i] will finally be
              // false if i is Not a
              // prime, else true.
              prime= new boolean[n + 1];
              for (int i = 0; i <= n; i++)
                  prime[i] = true;
      
              for (int p = 2; p * p <= n; p++)
              {
                  // If prime[p] is not changed, then it is a
                  // prime
                  if (prime[p] == true)
                  {
                      // Update all multiples of p
                      for (int i = p * p; i <= n; i += p)
                          prime[i] = false;
                  }
              }
          }
  
          // A O(log n) function returning primefactorization
          // by dividing by smallest prime factor at every step
          public Set<Integer> getFactorization(int x)
          {
              if(dp.containsKey(x)) return dp.get(x);
              Set<Integer> ret = new HashSet<>();
              while (x != 1)
              {
                  if(spf[x]!=2) ret.add(spf[x]);
                  x = x / spf[x];
              }
              dp.put(x,ret);
              return ret;
          }
          // function to find first index >= x
          public int lowerIndex(List<Integer> arr, int n, int x)
          {
              int l = 0, h = n - 1;
              while (l <= h)
              {
                  int mid = (l + h) / 2;
                  if (arr.get(mid) >= x)
                      h = mid - 1;
                  else
                      l = mid + 1;
              }
              return l;
          }
          public int lowerIndex(int[] arr, int n, int x)
          {
              int l = 0, h = n - 1;
              while (l <= h)
              {
                  int mid = (l + h) / 2;
                  if (arr[mid] >= x)
                      h = mid - 1;
                  else
                      l = mid + 1;
              }
              return l;
          }
  
          // function to find last index <= y
          public int upperIndex(List<Integer> arr, int n, int y)
          {
              int l = 0, h = n - 1;
              while (l <= h)
              {
                  int mid = (l + h) / 2;
                  if (arr.get(mid) <= y)
                      l = mid + 1;
                  else
                      h = mid - 1;
              }
              return h;
          }
          public int upperIndex(int[] arr, int n, int y)
          {
              int l = 0, h = n - 1;
              while (l <= h)
              {
                  int mid = (l + h) / 2;
                  if (arr[mid] <= y)
                      l = mid + 1;
                  else
                      h = mid - 1;
              }
              return h;
          }
  
          // function to count elements within given range
          public int countInRange(List<Integer> arr, int n, int x, int y)
          {
              // initialize result
              int count = 0;
              count = upperIndex(arr, n, y) -
                      lowerIndex(arr, n, x) + 1;
              return count;
          }
  
          public int add(int a, int b){
              a+=b;
              if(a>=MOD) a-=MOD;
              else if(a<0) a+=MOD;
              return a;
          }
  
          public int mul(int a, int b){
              long res= (long)a*(long)b;
              return (int)(res%MOD);
          }
  
          public int power(int a, int b) {
              int ans=1;
              while(b>0){
                  if((b&1)!=0) ans= mul(ans,a);
                  b>>=1;
                  a= mul(a,a);
              }
              return ans;
          }
  
          int[] fact= new int[MAXN];
          int[] inv= new int[MAXN];
  
          public int Ckn(int n, int k){
              if(k<0 || n<0) return 0;
              return mul(mul(fact[n],inv[k]),inv[n-k]);
          }
  
          public int inverse(int a){
              return power(a,MOD-2);
          }
  
          public void preprocess() {
              fact[0]=1;
              for(int i=1;i<MAXN;i++) fact[i]= mul(fact[i-1],i);
              inv[MAXN-1]= inverse(fact[MAXN-1]);
              for(int i=MAXN-2;i>=0;i--){
                  inv[i]= mul(inv[i+1],i+1);
              }
          }
  
          /**
           * return VALUE of lower bound for unsorted array
           */
          public int lowerBoundNormalArray(int[] arr, int x){
              TreeSet<Integer> set= new TreeSet<>();
              for(int num: arr) set.add(num);
              return set.lower(x);
          }
          /**
           * return VALUE of upper bound for unsorted array
           */
          public int upperBoundNormalArray(int[] arr, int x){
              TreeSet<Integer> set= new TreeSet<>();
              for(int num: arr) set.add(num);
              return set.higher(x);
          }
  
          public void debugArr(int[] arr){
              for(int i: arr) out.print(i+" ");
              out.println();
          }
  
          public int rand(){
              int min=0, max= MAXN;
              int random_int = (int)Math.floor(Math.random()*(max-min+1)+min);
              return random_int;
          }
          
          InputReader in; PrintWriter out;
          CustomFileReader cin;
          int[] xor= new int[3*100000+5];
          public void solve(InputReader in, PrintWriter out) {
              this.in=in; this.out=out;
              int t= in.nextInt();
              preprocess();
              // int t=in.nextInt();
              // int t= cin.nextIntArrLine()[0];
              for(int i=1;i<=t;i++) solveD1(i);
          }
          public void solveA(int t){
              int n= in.nextInt(), s= in.nextInt();
              out.println((s / (n - (n-1) / 2)));
          }
          public void solveB(int t) {
              char[] s= in.nextToken().toCharArray();
              int n= s.length;
              int zero=0;
              boolean tiep=false;
              for(int i=0;i<n;i++){
                  if(s[i]=='0' && !tiep){
                      tiep=true;
                      zero++;
                  }
                  else if(s[i]=='1'){
                      tiep=false;
                  }
              }
              if(zero==0) out.println(0);
              else if(zero==1) out.println(1);
              else out.println(2);
          }
          public void solveC(int t){
              int n= in.nextInt();
              char[] a= in.nextToken().toCharArray();
              char[] b= in.nextToken().toCharArray();
              int res=0;
              for(int i=0;i<n;i++){
                  if((a[i]=='0' && b[i]=='1') || (a[i]=='1' && b[i]=='0')) res+=2;
                  else if(a[i]=='0'){
                      if(i+1<n && a[i+1]=='1' && b[i+1]=='1') {
                          i++;
                          res+=2;
                      }
                      else res++;
                  }
                  else if(i+1<n && a[i+1]=='0' && b[i+1]=='0') {
                      i++;
                      res+=2;
                  }
              }
              out.println(res);
          }
          public void solveD1(int t){
              int n= in.nextInt(), m= in.nextInt();
              int[] pos= new int[m*n];
              int[] has= new int[m*n];
              List<Pair> a= new ArrayList<>();
              for(int i=0;i<m*n;i++){
                  a.add(new Pair(in.nextInt(),-i));
              }
              Collections.sort(a);
              int ans = 0;
              for (int i = 0; i < m * n; i++){
                  pos[i] = -a.get(i).y;
              }
              for (int id = 0; id < m * n; id++){
                  for (int i = 0; i < pos[id]; i++){
                      ans += has[i];
                  }
                  has[pos[id]] = 1;
              }
              out.println(ans);
          }
          public boolean ok(int num) {
              for (int i = 2; i * i <= num; i++){
                  if (num%i==0) return true;
              }
              return false;
          }
          public int _gcd(int a,  int b)
          {
  
              if(b == 0) {
                  return a;
              }
              else {
                  return _gcd(b, a % b);
              }
          }
          public int _lcm(int a, int b){
              return (a*b)/_gcd(a,b);
          }
  
      }
  
  
      static class SEG {
          public long _gcd(long a,  long  b)
          {
  
              if(b == 0) {
                  return a;
              }
              else {
                  return _gcd(b, a % b);
              }
          }
          long[] segs;
          public SEG(List<Long> a) {
              int n= a.size();
              segs= new long[4*n];
              build(0,a,0,n-1);
          }
          void build(int root, List<Long> a, int l, int r){
              if (l==r){
                  segs[root] = a.get(l); return;
              }
              int m = (l+r) >> 1;
              build(root*2+1, a, l, m);
              build(root*2+2, a, m+1, r);
              segs[root] = _gcd(segs[root*2+1], segs[root*2+2]);
          }
          long query(int root, int l, int r, int lq, int rq){
              if (lq > r || rq < l) return 0l;
              if (l >= lq && rq >= r) return segs[root];
              int m = (l+r)>>1;
              return _gcd(query(root*2+1, l, m, lq, rq),
                           query(root*2+2, m+1, r, lq, rq));
          }
      }
  
      static class Venice{
          public Map<Long,Long> m= new HashMap<>();
          public long base=0;
          public long totalValue=0;
          private int M= 1000000007;
  
          private long addMod(long a, long b){
              a+=b;
              if(a>=M) a-=M;
              return a;
          }
  
          public void reset(){
              m= new HashMap<>();
              base=0;
              totalValue=0;
          }
          public void update(long add){
              base= base+ add;
          }
          public void add(long key, long val){
              long newKey= key-base;
              m.put(newKey, addMod(m.getOrDefault(newKey,(long)0),val));
          }
      }
  
  
  
      static class Tuple implements Comparable<Tuple>{
          int x, y, z;
          public Tuple(int x, int y, int z){
              this.x= x;
              this.y= y;
              this.z=z;
          }
          @Override
          public int compareTo(Tuple o){
              return this.z-o.z;
          }
      }
  
      static class Pair implements Comparable<Pair>{
          public int x;
          public int y;
          public Pair(int x, int y){
              this.x= x;
              this.y= y;
          }
  
          @Override
          public int compareTo(Pair o) {
              if(this.x!=o.x) return this.x-o.x;
              return this.y-o.y;
          }
      }
  
      // public static class compareL implements Comparator<Tuple>{
      //     @Override
      //     public int compare(Tuple t1, Tuple t2) {
      //         return t2.l - t1.l;
      //     }
      // }
  
      // fast input reader class;
      static class InputReader {
          BufferedReader br;
          StringTokenizer st;
  
          public InputReader(InputStream stream) {
              br = new BufferedReader(new InputStreamReader(stream));
          }
  
          public String nextToken() {
              while (st == null || !st.hasMoreTokens()) {
                  String line = null;
                  try {
                      line = br.readLine();
                  } catch (IOException e) {
                      throw new RuntimeException(e);
                  }
                  if (line == null) {
                      return null;
                  }
                  st = new StringTokenizer(line);
              }
              return st.nextToken();
          }
  
          public int nextInt() {
              return Integer.parseInt(nextToken());
          }
          public double nextDouble(){
              return Double.parseDouble(nextToken());
          }
          public long nextLong(){
              return Long.parseLong(nextToken());
          }
          public int[] nextIntArr(int n){
              int[] arr= new int[n];
              for(int i=0;i<n;i++) arr[i]= nextInt();
              return arr;
          }
          public long[] nextLongArr(int n){
              long[] arr= new long[n];
              for(int i=0;i<n;i++) arr[i]= nextLong();
              return arr;
          }
          public List<Integer> nextIntList(int n){
              List<Integer> arr= new ArrayList<>();
              for(int i=0;i<n;i++) arr.add(nextInt());
              return arr;
          }
          public int[][] nextIntMatArr(int n, int m){
              int[][] mat= new int[n][m];
              for(int i=0;i<n;i++) for(int j=0;j<m;j++) mat[i][j]= nextInt();
              return mat;
          }
          public List<List<Integer>> nextIntMatList(int n, int m){
              List<List<Integer>> mat= new ArrayList<>();
              for(int i=0;i<n;i++){
                  List<Integer> temp= new ArrayList<>();
                  for(int j=0;j<m;j++) temp.add(nextInt());
                  mat.add(temp);
              }
              return mat;
          }
          public char[] nextStringCharArr(){
              return nextToken().toCharArray();
          }
      }
  
      static class CustomFileReader{
          String path="";
          Scanner sc;
          public CustomFileReader(String path){
              this.path=path;
              try{
                  sc= new Scanner(new File(path));
              }
              catch(Exception e){}
          }
          public String nextLine(){
              return sc.nextLine();
          }
          public int[] nextIntArrLine(){
              String line= sc.nextLine();
              String[] part= line.split("[\\s+]");
              int[] res= new int[part.length];
              for(int i=0;i<res.length;i++) res[i]= Integer.parseInt(part[i]);
              return res;
          }
      }
  }