#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  int test_c;
  cin >> test_c;
  for (int test_i = 0; test_i < test_c; test_i++) {
    int n;
    cin >> n;
    vector<int> val(n);
    for (int i = 0; i < n; i++) {
      cin >> val[i];
    }
    int min_val = 1e9, ans = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (min_val < val[i]) {
        ans++;
      } else {
        min_val = val[i];
      }
    }
    cout << ans << '\n';
  }
}
