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