#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
void ans() {
  long long i, j, k, p, q, r, m, n, o, t, x, sum = 0, flag = 0, cnt = 0;
  cin >> n;
  long long a[n];
  long long minimum;
  for (long long i = 0; i < n; i++) cin >> a[i];
  minimum = a[n - 1];
  i = n - 2;
  while (i >= 0) {
    if (a[i] > minimum) {
      cnt++;
    }
    minimum = min(a[i], minimum);
    i--;
  }
  cout << cnt << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    ans();
  }
}
