#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
      int aux;
      cin >> aux;
      v.push_back(aux);
    }
    int menor = v[n - 1];
    int bad = 0;
    for (int i = n - 2; i >= 0; i--) {
      if (v[i] > menor)
        bad++;
      else
        menor = v[i];
    }
    cout << bad << endl;
  }
}
