#include <bits/stdc++.h>
using namespace std;
int main() {
  int test;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    int a[n];
    cin >> a[0];
    int count = 0;
    for (int i = 1; i < n; i++) {
      cin >> a[i];
    }
    int m = INT_MAX;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] > m) count++;
      m = min(m, a[i]);
    }
    cout << count << endl;
  }
}
