#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double eps = 1e-9;
const long long mod = 1e9 + 7;
const long long llinf = (1ll << 60);
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
  long long tt;
  cin >> tt;
  for (int t = (0); t <= ((tt)-1); t += (+1)) {
    long long n;
    cin >> n;
    vector<long long> v(n), dp(n);
    for (int i = (0); i <= ((n)-1); i += (+1)) {
      cin >> v[i];
    }
    dp[n - 1] = v[n - 1];
    for (int i = (n - 2); i >= (0); i += (-1)) {
      dp[i] = min(v[i], dp[i + 1]);
    }
    long long res = 0;
    for (int i = (0); i <= ((n)-1); i += (+1)) {
      if (v[i] > dp[i]) res++;
    }
    cout << res << '\n';
  }
  return 0;
}
