#include <bits/stdc++.h>
using namespace std;
long long n, x, y, m, t, k;
const int mod = 1e9 + 7;
const int mxn = 2e5 + 5;
long long mx = 0, mn = 1e18;
long long a, b;
long long arr[500000];
string str;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    cin >> n;
    mn = 1e18;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    long long coun = 0;
    for (int i = n - 1; i >= 0; i--) {
      mn = min(mn, arr[i]);
      if (arr[i] > mn) coun++;
    }
    cout << coun << endl;
    ;
  }
  return 0;
}
