#include <bits/stdc++.h>
using namespace std;
const int maxn = 150007;
int a[maxn];
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    int m = a[n - 1];
    int cnt = 0;
    for (int i = n - 2; i >= 0; i--) {
      if (a[i] > m) {
        cnt++;
      } else
        m = a[i];
    }
    cout << cnt << endl;
  }
  return 0;
}
