#include <bits/stdc++.h>
using namespace std;
int main() {
  int total_sets, total_nums;
  cin >> total_sets;
  for (int set_count = 0; set_count < total_sets; set_count++) {
    cin >> total_nums;
    vector<int> data;
    for (int num = 0; num < total_nums; num++) {
      int input;
      cin >> input;
      data.push_back(input);
    }
    int minimum = data[total_nums - 1];
    int poorprices = 0;
    for (int scanid = total_nums - 2; scanid >= 0; scanid--) {
      if (data[scanid] > minimum) {
        poorprices++;
        continue;
      } else {
        minimum = data[scanid];
      }
    }
    cout << poorprices << endl;
  }
}
