#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, garb;
  cin >> garb >> n;
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    long long val;
    cin >> val;
    v.push_back(val);
  };
  long long m[n];
  memset(m, 0, sizeof(m));
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < i; j++) {
      if (v[j] < v[i]) {
        m[i]++;
      }
    }
  }
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    ans += m[i];
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
