#include<stdio.h>
#include<conio.h>

int main()
{
    int t, n, i, j, count;
    scanf("%d", &t);
    int temp=t;
    int ans[t];
    printf("\n");
    while(t!=0)
    {
    count=0;
    scanf("%d", &n);
    int ar[n];
    
    for(i=0;i<n;i++)
    scanf("%d", &ar[i]);
    
    printf("\n");
    
    for(i=0;i<n-1;i++)
    {
    for(j=i+1;j<n;j++)
    {
       if(ar[i]>ar[j])
       {
                      count+=1;
                      }
       }
    }
       ans[t]=count;
    t--;
       }
            
    for(i=0;i<temp;i++)
    printf("%d\n",ans[i]);
            
    getch();
    return 0;
}