#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
const int INF = 1e9;
const int N = 2e5 + 1;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int DP;
  int t;
  cin >> t;
  while (t--) {
    int n, i;
    cin >> n;
    int a[n], b[n - 1];
    int mini = INF, ans = 0;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (i = n - 1; i >= 0; i--) {
      mini = min(a[i], mini);
      b[i - 1] = mini;
    }
    for (i = 0; i < n - 1; i++) {
      if (a[i] > b[i]) ans++;
    }
    cout << ans << "\n";
  }
  return 0;
}
