#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long mod) {
  long long sum = 1;
  while (b) {
    if (b & 1) {
      sum = (sum * a) % mod;
      b--;
    }
    b /= 2;
    a = a * a % mod;
  }
  return sum;
}
const double Pi = acos(-1.0);
const double epsilon = Pi / 180.0;
const int maxn = 1e5 + 10;
int a[160000];
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int minn = a[n];
    int ans = 0;
    for (int i = n - 1; i >= 1; i--) {
      if (a[i] > minn)
        ans++;
      else
        minn = a[i];
    }
    cout << ans << '\n';
  }
}
