#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    long int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int c = 0, max = 0;
    stack<int> s;
    s.push(a[n - 1]);
    for (int j = n - 2; j >= 0; j--) {
      if (a[j] <= s.top())
        s.push(a[j]);
      else
        c++;
    }
    cout << c << "\n";
  }
}
