#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007;
long long modx(long long a) { return (a % MOD + MOD) % MOD; }
long long times(long long a, long long b) { return modx(modx(a) * modx(b)); }
long long add(long long a, long long b) { return modx(modx(a) + modx(b)); }
long long sub(long long a, long long b) {
  return modx(MOD + modx(a) - modx(b));
}
long long fastExp(long long base, long long exp) {
  if (exp == 0LL) {
    return 1LL;
  }
  if (exp % 2 == 0) {
    return fastExp(times(base, base), exp / 2);
  } else {
    return times(exp, fastExp(times(base, base), exp / 2));
  }
}
const int MAXN = (int)1e5 + 1;
int N, T;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> T;
  vector<int> ans;
  for (int i = 0; i < T; i++) {
    cin >> N;
    int arr[N];
    for (int j = 0; j < N; j++) {
      cin >> arr[j];
    }
    int m = arr[N - 1];
    int res = 0;
    for (int j = N - 1; j >= 0; j--) {
      if (arr[j] > m) {
        res++;
      }
      m = min(m, arr[j]);
    }
    ans.push_back(res);
  }
  for (int a : ans) {
    cout << a << "\n";
  }
  return 0;
}
