#include <stdio.h>
int main ()
{
int l ,p , x, n ,i ,j ,a[55] ;
scanf ("%d",&n) ;
for (x =1 ; x <=n ; x++)
{
scanf ("%d",&l) ;
for (i =0 ; i< l ;i++)
{
scanf ("%d",&a [i] ) ;
}
int cnt =0 ;
int r = l-1 ;
for (i =0 ; i < r ; i++)
{
for (j =0 ; j< r -i ; j++)
{
if (a [j] > a [j+1] )
{
cnt ++ ;
p = a [j] ;
a [ j] = a [j +1] ;
a [j+1] = p ;
}
}
}
printf ("Optimal train swapping takes %d swaps.\n",cnt) ;
}
return 0 ;
}
int main ()
{
int l ,p , x, n ,i ,j ,a[55] ;
scanf ("%d",&n) ;
for (x =1 ; x <=n ; x++)
{
scanf ("%d",&l) ;
for (i =0 ; i< l ;i++)
{
scanf ("%d",&a [i] ) ;
}
int cnt =0 ;
int r = l-1 ;
for (i =0 ; i < r ; i++)
{
for (j =0 ; j< r -i ; j++)
{
if (a [j] > a [j+1] )
{
cnt ++ ;
p = a [j] ;
a [ j] = a [j +1] ;
a [j+1] = p ;
}
}
}
printf ("Optimal train swapping takes %d swaps.\n",cnt) ;
}
return 0 ;
}