def solve(): n = int(input()) P = list(map(int, input().split())) def f(x): ret1 = 0 t = 0 for p in P: if t == 0 and p <= x: ret1 += 1 t ^= 1 elif t == 1 and p > x: ret1 += 1 t ^= 1 ret2 = 0 t = 1 for p in P: if t == 0 and p <= x: ret2 += 1 t ^= 1 elif t == 1 and p > x: ret2 += 1 t ^= 1 return max(ret1, ret2) l = 0 r = n while r - l > 2: llr = (2 * l + r) // 3 lrr = (l + 2 * r) // 3 if f(llr) > f(lrr): l = llr else: r = lrr print(max(f(l), f(llr), f(lrr), f(r))) for _ in range(int(input())): solve()