import java.util.Scanner;
import java.util.Stack;
import java.util.ArrayList;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
while (T > 0) {
T--;
int count = sc.nextInt();
ArrayList<Integer> q = new ArrayList<>();
Stack<Integer> buffer = new Stack<>();
for (int i = 0; i < 20; i++) {
buffer.push(sc.nextInt());
}
int stepCount = 0;
for (int i =0 ; i < 20; i++) {
Integer a = buffer.pop();
int index = 0;
while (index < q.size() && q.get(index) > a) {
index++;
}
if (index == q.size()) {
q.add(a);
} else {
q.add(index, a);
stepCount += q.size() - index - 1;
}
}
System.out.println(count + " " + stepCount);
}
}
}