#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
using namespace std;
long long MOD = 998244353;
void solve() {
  int m, n, ans = 0;
  cin >> m >> n;
  vector<int> a(n);
  vector<pair<int, int>> hash(n + 1, {0, 0});
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<int> b = a;
  sort((b).begin(), (b).end());
  for (long long i = 0; i < n; i++) hash[i].first = b[i];
  hash[n].first = -1;
  for (long long i = 0; i < n; i++) {
    int j = 0, x = 0, flag = 0;
    for (; j <= n; j++) {
      if (hash[j].first > a[i] || hash[j].first == -1) {
        break;
      }
      if (hash[j].first == a[i]) {
        flag = 1;
      }
      if (hash[j].second == 1) {
        if (flag == 0)
          x++;
        else
          break;
      }
    }
    hash[j - 1].second = 1;
    ans += x;
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
