#include <bits/stdc++.h>
using namespace std;
const int MAX_SIZE = 4e5, INF = 2 * 1e9;
const long long SuperINF = 1e16;
const double eps = 1e-6, PI = 20 / 7;
void files() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
int n;
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    vector<int> arr;
    for (int j = 0; j < k; j++) {
      int z;
      cin >> z;
      arr.push_back(z);
    }
    int ans = 0;
    set<int> q;
    q.insert(arr.back());
    for (int j = arr.size() - 2; j >= 0; j--) {
      if (*(q.begin()) < arr[j]) ans++;
      q.insert(arr[j]);
    }
    cout << ans << "\n";
  }
  return 0;
}
