#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    vector<pair<long long int, long long int> > v;
    long long int x, i, n;
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> x;
      v.push_back(make_pair(x, i));
    }
    long long int count = 0;
    long long int mini = v[n - 1].first;
    for (i = n - 2; i >= 0; i--) {
      if (v[i].first > mini) {
        count++;
      } else
        mini = v[i].first;
    }
    if (n == 1) {
      cout << 0 << '\n';
      continue;
    } else
      cout << count << '\n';
  }
  return 0;
}
