#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int exp(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    int m = 1000001;
    int cnt = 0;
    for (int i = 0, _n = (n); i < _n; i++) cin >> a[i];
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] > m)
        cnt++;
      else
        m = a[i];
    }
    cout << cnt << "\n";
  }
  return 0;
}
