#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, k, l, i, j;
  int count = 0;
  cin >> n;
  while (n--) {
    cin >> k;
    int ara[k];
    int min_v = 324345443;
    for (i = 0; i < k; i++) {
      cin >> ara[i];
    }
    for (i = k - 1; i >= 0; i--) {
      if (ara[i] > min_v) {
        count++;
      }
      min_v = min(min_v, ara[i]);
    }
    cout << count << '\n';
    count = 0;
  }
  return 0;
}
