#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using db = long double;
using ii = pair<int, int>;
const int N = 2e5 + 5, LG = 19, MOD = 1e9 + 7;
const int SQ = 225;
const long double EPS = 1e-7;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& x : a) cin >> x;
    int mn = INT_MAX;
    int cnt = 0;
    for (int i = n - 1; i >= 0; --i) {
      if (a[i] > mn) cnt++;
      mn = min(mn, a[i]);
    }
    cout << cnt << '\n';
  }
  return 0;
}
