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