#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t, n, m, b, nn, s, r, f, p, d, l, lo, k, h, c, res = 99999999;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<long long int> v;
    r = 0;
    for (long long int i = 0; i < n; i++) {
      cin >> p;
      v.push_back(p);
    }
    p = v[n - 1];
    for (long long int i = n - 1; i >= 0; i--) {
      if (v[i] > p)
        r++;
      else if (v[i] < p)
        p = v[i];
    }
    cout << r << endl;
  }
  return 0;
}
