#include <bits/stdc++.h>
using namespace std;
int main() {
  int testscase;
  cin >> testscase;
  while (testscase--) {
    int n, x, count = 0;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
      cin >> x;
      v.push_back(x);
    }
    int pos = v[n - 1];
    for (int i = n - 1; i >= 0; --i) {
      if (pos < v[i]) {
        count++;
      } else {
        pos = v[i];
      }
    }
    cout << count << '\n';
  }
}
