def main(): T = int(input()) for i in range(T): N = int(input()) p = [0] + list(map(int, input().split())) + [N+1] ans = [] ok = True def swap(i): assert i != p[i] and i+1 != p[i+1] ans.append(i) p[i], p[i+1] = p[i+1], p[i] fixed_idx = [i for i in range(N+2) if i == p[i]] for i in range(len(fixed_idx)-1): f, t = fixed_idx[i]+1, fixed_idx[i+1]-1 if sorted(p[f:t+1]) != list(range(f, t+1)): ok = False break for i in range(f, t+1): for j in range(f, t+1): if p[j] == i: i_idx = j break if i_idx == i: continue for j in range(i_idx, i, -1): assert p[j] == i k = j-1 while p[k] == k+1: k -= 1 if p[k] == k: for s in range(j-1, k, -1): swap(s) break else: for s in range(k, j): swap(s) if not ok: print(-1) else: assert(sorted(p) == p) print(len(ans)) print(*ans) if __name__ == '__main__': main()