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