#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int min_num = -5;
    long long int n;
    cin >> n;
    stack<long long int> num_stack;
    for (long long int i = 0; i < n; i++) {
      long long int x;
      cin >> x;
      num_stack.push(x);
    }
    min_num = num_stack.top();
    long long int count = 0;
    while (!num_stack.empty()) {
      long long int x;
      x = num_stack.top();
      num_stack.pop();
      if (x > min_num) {
        count++;
      } else {
        min_num = x;
      }
    }
    cout << count << '\n';
  }
}
