#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, x;
    cin >> n;
    int arr[n];
    int ans = 0;
    int mi = INT_MAX;
    for (int i = 0; i < n; ++i) scanf("%d", &arr[i]);
    for (int i = n - 1; i >= 0; --i) {
      if (arr[i] > mi) ++ans;
      mi = min(arr[i], mi);
    }
    printf("%d\n", ans);
  }
  return 0;
}
