#include<iostream>
using namespace std;
int time(int *a,int n){
int time = 0;
for(int x = 0;x<n;x++){
for(int y = x+1;y<n;y++){
if(a[x]>a[y]){
int temp = a[x];
a[x] = a[y];
a[y] = temp;
time++;
}
}
}
return time;
}
int main(){
int g,n;
int step[5] = {0};
int nu[10];
cin >> g;
int a = 0;
while(a<g){
cin >> n;
for(int i = 0;i<n;i++){
cin >> nu[i];
}
step[a] = time(nu,n);
a++;
}
int s = 0;
while(s<g){
cout<<"Optimal train swapping takes "<<step[s]<<" swaps."<<endl;
s++;
}
}