from collections import deque T = int(input()) for _ in range(T): N = int(input()) P = [0]+list(map(int,input().split())) k = 0 while 2**k0: tot += T[i] i -= i&(-i) return tot A = deque([P[1]]) update(P[1],1) ans = 0 for i in range(2,N+1): a = cumsum(P[i]) b = i-1-a if a