#include <bits/stdc++.h>
using namespace std;
struct node {
  int price;
  int min;
};
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<node> list;
    while (n--) {
      node a;
      cin >> a.price;
      list.push_back(a);
    }
    int i;
    int min = 1e6 + 5;
    for (i = list.size() - 1; i >= 0; i--) {
      if (min > list[i].price) min = list[i].price;
      list[i].min = min;
    }
    int cnt = 0;
    for (i = 0; i < list.size(); i++)
      if (list[i].price != list[i].min) cnt++;
    cout << cnt << endl;
  }
}
