#include <iostream>
using namespace std;
int main(){
    int T;
    cin >> T;
    while (T --){
        int no, a[25];
        cin >> no;
        for (int i = 0; i < 20; i++){
            cin >> a[i];
        }
        int ans = 0;
        for (int i = 0; i < 20; i++){
            int t = i;
            for (int j = i; j < 20; j++){
                if (a[j] < a[t])
                    t = j;
            }
            ans += (t - i);
            for (int j = t; j >= i; j--)
                a[j] = a[j - 1];
        }
        cout << no << " " << ans << endl;
    }
}