#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  int a[m];
  for (int i = 1; i <= m; i++) {
    cin >> a[i];
  }
  int count = 0;
  int sum = 0;
  for (int i = 1; i <= m; i++) {
    int x = a[i];
    for (int j = 1; j <= i; j++) {
      if (x > a[j]) {
        count++;
      }
    }
    sum = sum + count;
    count = 0;
  }
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
