#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, s, p, k, m, t, x, y, ans, res;
  cin >> t;
  while (t--) {
    cin >> n;
    long long a[n + 1];
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    ans = 0;
    m = INT_MAX;
    for (int i = n; i >= 1; i--) {
      if (a[i] > m) ans++;
      m = min(a[i], m);
    }
    cout << ans << endl;
  }
  return 0;
}
