#include <bits/stdc++.h>
using namespace std;
int a[150000 + 15], mini[150000 + 15] = {0};
int main() {
  int t, n;
  cin >> t;
  while (t--) {
    cin >> n;
    mini[n] = 0x3f3f3f3f;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = n - 1; i >= 0; i--) mini[i] = min(mini[i + 1], a[i]);
    int ans = 0;
    for (int i = 0; i < n; i++)
      if (a[i] > mini[i]) ans++;
    cout << ans << endl;
  }
  return 0;
}
