// Justin Almazan
// 6/25/2025
// Solution to 2025 CS SI UCF Contest 3 Problem: Height Ordering
// https://open.kattis.com/problems/height

#include <bits/stdc++.h>
using namespace std;

const int n = 20;
int tt, tc;

int main() {

    // Get number of data sets
    cin >> tt;

    // For each data set
    while (tt--) {

        // Keeps track of all the students inserted so far
        set<int> s;

        // Get data set number
        cin >> tc;

        // Keeps track of number of steps
        int res = 0;

        // For each student
        for (int i = 0; i < 20; i++) {
            
            // Get height
            int h;
            cin >> h;

            // Find the next tallest student
            auto it = s.upper_bound(h);

            // Count number of students that must step back and add to res
            while (it != s.end()) {
                it++;
                res++;
            }

            // Add student to set
            s.insert(h);
        }

        // Answer
        cout << tc << " " << res << endl;
    }

    return 0;
}