#include <bits/stdc++.h>
using namespace std;
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const long long INF = 1e9;
const long long MAXN = 1e5 + 10;
const long long MOD = 1e9 + 7;
const long long LOG = ceil(log(MAXN) / log(2));
const long double EPS = 1e-9;
const int dx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
void solve() {
  int n, ans = 0;
  cin >> n;
  vector<int> a(n);
  for (int& x : a) {
    cin >> x;
  }
  reverse(a.begin(), a.end());
  for (int i = 0, mn = INT_MAX; i < n; ++i) {
    if (a[i] > mn)
      ans++;
    else
      mn = a[i];
  }
  cout << ans << '\n';
}
int main() {
  faster();
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
  cerr << "\nTime elapsed " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  return 0;
}
