class BIT: def __init__(self,n): self.n = n; self.k = [0]*(n+1) def a(self,i,x): while i<=self.n: self.k[i] += x; i += i&-i def s(self,i): t = 0 while i>0: t += self.k[i]; i -= i&-i return t from collections import deque for _ in range(int(input())): n = int(input()); bit = BIT(n); x = 0; dq = deque() for i,v in enumerate(map(int,input().split())): c = bit.s(v); bit.a(v,1) if c