#include <bits/stdc++.h>
#pragma GCC optimize "03"
using namespace std;
const long long int inf = INT_MAX;
const long long int MOD = 1e9 + 7;
const long long int N = 1e5 + 5;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int a[n];
    for (long long int i = n - 1; i >= 0; i--) {
      cin >> a[i];
    }
    long long int mn = inf;
    long long int c = 0;
    for (long long int i = 0; i < n; i++) {
      mn = min(mn, a[i]);
      if (a[i] > mn) c++;
    }
    cout << c << '\n';
  }
  return 0;
}
