#include <bits/stdc++.h>
using namespace std;
void aasani() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  aasani();
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    vector<long long> suf(n);
    suf[n - 1] = a[n - 1];
    for (long long i = n - 2; i >= 0; i--) {
      suf[i] = min(a[i], suf[i + 1]);
    }
    long long cnt = 0;
    for (long long i = 0; i < n; i++) {
      if (suf[i] != a[i]) cnt++;
    }
    cout << cnt << endl;
  }
}
