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