#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n;
void solve() {
  scanf("%d", &n);
  int arr[N];
  for (int i = 1; i <= n; ++i) scanf("%d", arr + i);
  int mn = INT_MAX;
  int cnt = 0;
  for (int i = n; i > 0; --i) {
    if (arr[i] > mn) ++cnt;
    mn = min(mn, arr[i]);
  }
  printf("%d\n", cnt);
}
int main(void) {
  int t;
  scanf("%d", &t);
  while (t--) solve();
}
