#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 2e6;
int arr[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> m;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
      sort(arr + 1, arr + i);
      int start = 1;
      int end = i - 1;
      int res = 0;
      if (arr[i] <= arr[start]) {
        res = 0;
      } else if (arr[i] > arr[end]) {
        res = end;
      } else {
        while (end >= start) {
          int mid = (start + end) / 2;
          if (arr[mid] < arr[i]) {
            start = mid + 1;
          } else {
            end = mid - 1;
            res = mid - 1;
          }
        }
      }
      ans += res;
    }
    cout << ans << endl;
  }
}
