#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, s, p = 0, t;
  cin >> s;
  while (s--) {
    cin >> n;
    int ara[n];
    for (i = 0; i < n; i++) {
      cin >> ara[i];
    }
    t = ara[i - 1];
    for (i = n - 2; i >= 0; i--) {
      if (t < ara[i]) {
        p++;
      } else {
        t = ara[i];
      }
    }
    cout << p << endl;
    p = 0;
  }
}
