#include <bits/stdc++.h>
using namespace std;
long long int q, n, a[200020], b[200020];
int main() {
  ios::sync_with_stdio(false);
  cin >> q;
  while (q--) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    long long int cnt = 0;
    b[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; i--) b[i] = min(b[i + 1], a[i]);
    for (int i = 0; i < n; i++)
      if (a[i] == b[i]) cnt++;
    cout << n - cnt << endl;
  }
}
