Karlsson has recently discovered a huge stock of berry jam jars in the basement of the house. More specifically, there were $2n$ jars of strawberry and blueberry jam.

All the $2n$ jars are arranged in a row. The stairs to the basement are exactly in the middle of that row. So when Karlsson enters the basement, he sees exactly $n$ jars to his left and $n$ jars to his right.

For example, the basement might look like this: [Image] 

Being the starightforward man he is, he immediately starts eating the jam. In one minute he chooses to empty either the first non-empty jar to his left or the first non-empty jar to his right.

Finally, Karlsson decided that at the end the amount of full strawberry and blueberry jam jars should become the same.

For example, this might be the result: [Image] He has eaten $1$ jar to his left and then $5$ jars to his right. There remained exactly $3$ full jars of both strawberry and blueberry jam. 

Jars are numbered from $1$ to $2n$ from left to right, so Karlsson initially stands between jars $n$ and $n+1$.

What is the minimum number of jars Karlsson is required to empty so that an equal number of full strawberry and blueberry jam jars is left?

Your program should answer $t$ independent test cases.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^5$).

The second line of each test case contains $2n$ integers $a_1, a_2, \dots, a_{2n}$ ($1 \le a_i \le 2$) — $a_i=1$ means that the $i$-th jar from the left is a strawberry jam jar and $a_i=2$ means that it is a blueberry jam jar.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.


-----Output-----

For each test case print the answer to it — the minimum number of jars Karlsson is required to empty so that an equal number of full strawberry and blueberry jam jars is left.


-----Example-----
Input
4
6
1 1 1 2 2 1 2 1 2 1 1 2
2
1 2 1 2
3
1 1 1 1 1 1
2
2 1 1 1

Output
6
0
6
2



-----Note-----

The picture from the statement describes the first test case.

In the second test case the number of strawberry and blueberry jam jars is already equal.

In the third test case Karlsson is required to eat all $6$ jars so that there remain $0$ jars of both jams.

In the fourth test case Karlsson can empty either the second and the third jars or the third and the fourth one. The both scenarios will leave $1$ jar of both jams.

Difficulty: MEDIUM_HARD

Solutions:
t = int(input())
for i in range(t):
	n = int(input())
	jars = [int(x) for x in input().split()]
	left = [0] * (n + 1)
	right = [0] * (n + 1)
	for x in range(1, n + 1):
		if jars[x - 1] == 1:
			left[x] = left[x - 1] + 1
		else:
			left[x] = left[x - 1] - 1
		if jars[2 * n - x] == 1:
			right[x] = right[x - 1] + 1
		else:
			right[x] = right[x - 1] - 1
	a = {}
	b = {}
	for l in range(len(left)):
		a[left[l]] = l
	for r in range(len(right)):
		b[right[r]] = 2 * n - r + 1
	ans = 2 * n
	for key in a:
		if -key in b:
			ans = min(ans, b[-key] - (a[key] + 1))
	print(ans)


N = int(input())
for _ in range(N):
	n = int(input())
	lis = list(map(int, input().split()))
	sm = [0]
	for i in lis:
		sm.append(sm[-1] + 1) if i == 1 else sm.append(sm[-1] - 1)
	dif = sm[-1]
	dic = {}
	res = 2 * n
	for (i, v) in enumerate(sm):
		if i < n + 1:
			dic[v] = i
		if i >= n:
			t = v - dif
			if t in dic:
				res = min(res, i - dic[t])
	print(res)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	l = 0
	r = 0
	lis1 = []
	lis2 = [0]
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			l += 1
		else:
			l -= 1
		lis1.append(l)
	for i in range(n, 2 * n):
		if arr[i] == 1:
			r += 1
		else:
			r -= 1
		lis2.append(r)
	lis1.reverse()
	lis1.append(0)
	dict1 = {}
	for i in range(n + 1):
		if lis2[i] not in dict1.keys():
			dict1[lis2[i]] = i
	ans = 2 * n
	for i in range(n + 1):
		if l + r - lis1[i] in dict1.keys():
			ans = min(ans, dict1[l + r - lis1[i]] + n - i)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	left = a[:n]
	right = a[n:]
	red = 0
	blue = 0
	balance_left = [0] * (n + 1)
	balance_right = [0] * (n + 1)
	for j in range(n):
		if left[-j - 1] == 1:
			red += 1
			balance_left[j + 1] = balance_left[j] + 1
		else:
			blue += 1
			balance_left[j + 1] = balance_left[j] - 1
		if right[j] == 1:
			red += 1
			balance_right[j + 1] = balance_right[j] + 1
		else:
			blue += 1
			balance_right[j + 1] = balance_right[j] - 1
	difference = red - blue
	min_number_of_cans = 10 ** 6
	potential_answers_dict = {}
	potential_ans_set = set()
	for left_index in range(n + 1):
		if difference - balance_left[left_index] in potential_ans_set:
			pass
		else:
			potential_ans_set.add(difference - balance_left[left_index])
			potential_answers_dict[difference - balance_left[left_index]] = left_index
	for right_index in range(n + 1):
		if balance_right[right_index] in potential_ans_set:
			tmp_min = right_index + potential_answers_dict[balance_right[right_index]]
			if tmp_min < min_number_of_cans:
				min_number_of_cans = tmp_min
	print(min_number_of_cans)


def solve(L):
	n = len(L)
	Left = [-1] * (n + 1)
	Right = [-1] * (n + 1)
	c = 0
	(Left[n // 2], Right[n // 2]) = (0, 0)
	for i in range(n // 2 - 1, -1, -1):
		if L[i] == 1:
			c += 1
		else:
			c -= 1
		if Left[c + n // 2] == -1:
			Left[c + n // 2] = n // 2 - i
	c = 0
	for j in range(n // 2, n):
		if L[j] == 1:
			c += 1
		else:
			c -= 1
		if Right[c + n // 2] == -1:
			Right[c + n // 2] = j - n // 2 + 1
	k = n // 2 * 3 - sum(L)
	k *= 2
	m = 99999999999
	for i in range(n + 1):
		if k + n - i in range(n + 1):
			j = k + n - i
			if Left[i] != -1 and Right[j] != -1:
				if m > Left[i] + Right[j]:
					m = Left[i] + Right[j]
	return m
for i in ' ' * int(input()):
	n = int(input())
	L = list(map(int, input().split()))
	print(solve(L))


from itertools import accumulate
t = int(input())
for _ in range(t):
	n = int(input())
	jars = [1 if i == '1' else -1 for i in input().split()]
	left = list(accumulate(jars[0:n]))
	right = list(accumulate(jars[2 * n - 1:n - 1:-1]))
	left_dict = {0: 0}
	right_dict = {0: 0}
	for i in range(n):
		left_dict[left[i]] = i + 1
		right_dict[right[i]] = i + 1
	ans = 0
	for k in left_dict:
		if -k in right_dict:
			ans = max(ans, left_dict[k] + right_dict[-k])
	print(2 * n - ans)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = [0]
	for i in l:
		if i == 1:
			d.append(d[-1] + 1)
		else:
			d.append(d[-1] - 1)
	x = d[-1]
	hash = {}
	for i in range(n + 1):
		hash[d[i]] = i
	ans = 2 * n
	for i in range(n, 2 * n + 1):
		z = d[i] - x
		if z in hash:
			k = hash[z]
			ans = min(ans, abs(k - i))
	print(ans)


import os
import sys
from bisect import bisect_right
from fractions import Fraction

def main():
	N = int(input())
	for i in range(N):
		n = int(input())
		lis = list(map(int, input().split()))
		sm = [0]
		for i in lis:
			if i == 1:
				sm.append(sm[-1] + 1)
			else:
				sm.append(sm[-1] - 1)
		dif = sm[-1]
		m = {}
		res = 2 * n
		for i in range(n + 1):
			m[sm[i]] = i
		for i in range(n, 2 * n + 1):
			if sm[i] - dif in m:
				res = min(res, i - m[sm[i] - dif])
		print(res)
main()


for _ in range(int(input())):
	n = int(input())
	lis = list(map(lambda x: -1 if x == '2' else 1, input().split()))
	dic = {}
	dic[0] = n - 1
	difi = sum(lis)
	dif = 0
	for i in range(n, 2 * n):
		dif += lis[i]
		if dif not in dic:
			dic[dif] = i
	dif = 0
	ans = 100000000
	if difi in dic:
		ans = dic[difi] - n + 1
	for j in range(n - 1, -1, -1):
		dif += lis[j]
		if difi - dif in dic:
			ans = min(ans, dic[difi - dif] - j + 1)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = a.count(1)
	b = a.count(2)
	diff = s - b
	if diff < 0:
		for i in range(n * 2):
			if a[i] == 1:
				a[i] = 2
			else:
				a[i] = 1
	a1 = a[:n]
	a2 = a[n:]
	a1 = a1[::-1]
	if diff == 0:
		print('0')
		continue
	diff = abs(diff)
	if 1:
		ans = {}
		counter = 0
		for i in range(n):
			if a1[i] == 1:
				counter += 1
			else:
				counter -= 1
			if counter not in ans:
				ans[counter] = i + 1
		ans1 = {}
		counter = 0
		for i in range(n):
			if a2[i] == 1:
				counter += 1
			else:
				counter -= 1
			if counter not in ans1:
				ans1[counter] = i + 1
		mi = n * 2
		for i in ans:
			if i == diff:
				if i in ans1:
					mi = min(mi, ans[i], ans1[i])
				else:
					mi = min(mi, ans[i])
			elif diff - i in ans1:
				mi = min(mi, ans[i] + ans1[diff - i])
		for i in ans1:
			if i == diff:
				mi = min(mi, ans1[i])
		print(mi)


tag = {'1': -1, '2': 1}

def f():
	n = int(input())
	A = [tag[s] for s in input().split()]
	left = A[:n]
	right = A[n:][::-1]
	count = {0: 0}
	sum = 0
	for i in range(n):
		sum += left[i]
		count[sum] = i + 1
	maxRem = count[0]
	sum = 0
	for j in range(n):
		sum += right[j]
		if -sum in count:
			maxRem = max(maxRem, count[-sum] + j + 1)
	return 2 * n - maxRem
t = int(input())
for i in range(t):
	print(f())


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	sb = bb = 0
	for i in a:
		if i == 1:
			sb += 1
		elif i == 2:
			bb += 1
	diff = abs(sb - bb)
	if diff == 0:
		print(0)
		continue
	lookfor = 0
	if sb > bb:
		lookfor = 1
	else:
		lookfor = 2
	left = [0] * n
	right = [0] * n
	closest_l = {}
	closest_r = {}
	for i in range(2 * n):
		closest_l[i] = -n
		closest_r[i] = -n
	i = n - 1
	j = 0
	while i >= 0:
		if a[i] == lookfor:
			left[j] = left[j - 1] + 1
		else:
			left[j] = left[j - 1] - 1
		if left[j] > 0 and (j < closest_l[left[j]] or closest_l[left[j]] == -n):
			closest_l[left[j]] = j
		j += 1
		i -= 1
	i = n
	j = 0
	while i < 2 * n:
		if a[i] == lookfor:
			right[j] = right[j - 1] + 1
		else:
			right[j] = right[j - 1] - 1
		if right[j] > 0 and (j < closest_r[right[j]] or closest_r[right[j]] == -n):
			closest_r[right[j]] = j
		j += 1
		i += 1
	mi = 2 * n
	for i in range(n):
		li = left[i]
		if i + 1 < mi and li == diff:
			mi = i + 1
		elif diff - li > 0 and i + closest_r[diff - li] + 1 < mi and (closest_r[diff - li] >= 0) and (li + right[closest_r[diff - li]] == diff):
			mi = i + closest_r[diff - li] + 2
	for i in range(n):
		ri = right[i]
		if i + 1 < mi and ri == diff:
			mi = i + 1
		elif diff - ri > 0 and i + closest_l[diff - ri] + 1 < mi and (closest_l[diff - ri] >= 0) and (ri + left[closest_l[diff - ri]] == diff):
			mi = i + closest_l[diff - ri] + 2
	print(mi)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	add = 0
	i = 1
	dict = {}
	dict[0] = 0
	total = 0
	for j in range(n, 2 * n):
		if a[j] == 1:
			count += 1
			total += 1
		else:
			add += 1
			total -= 1
		if total not in dict:
			dict[total] = i
		i += 1
	b = [0]
	total = 0
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			total += 1
			count += 1
		else:
			total -= 1
			add += 1
		b.append(total)
	d = add - count
	if d == 0:
		print(0)
		continue
	mini = 9999999999
	for i in range(n + 1):
		if -(b[i] + d) in dict:
			mini = min(mini, i + dict[-(b[i] + d)])
	print(mini)


t = int(input())
for _ in range(t):
	n = int(input())
	it = list(map(int, input().split()))
	ind = n
	a = it.count(1)
	b = 2 * n - a
	if b < a:
		it = [3 - i for i in it]
	(a, b) = sorted([a, b])
	diff = a - b
	aa = [0 for i in range(n)]
	if it[n - 1] == 2:
		aa[n - 1] = -1
	else:
		aa[n - 1] = 1
	for i in range(n - 2, -1, -1):
		if it[i] == 2:
			aa[i] = aa[i + 1] - 1
		else:
			aa[i] = aa[i + 1] + 1
	bb = [0 for i in range(n)]
	if it[n] == 2:
		bb[0] = -1
	else:
		bb[0] = 1
	for i in range(1, n):
		if it[i + n] == 2:
			bb[i] = bb[i - 1] - 1
		else:
			bb[i] = bb[i - 1] + 1
	ss = {}
	tt = {}
	for i in range(n):
		try:
			ss[aa[i]] = max(ss[aa[i]], i)
		except:
			ss[aa[i]] = i
	for i in range(n):
		try:
			tt[bb[i]] = min(tt[bb[i]], i + n)
		except:
			tt[bb[i]] = i + n
	mi = 2 * n
	if diff == 0:
		mi = 0
	for i in range(n):
		if aa[i] == diff:
			mi = min(mi, n - i)
			continue
		else:
			co = diff - aa[i]
			try:
				x = tt[co]
				do = x - i + 1
				mi = min(mi, do)
			except:
				continue
	for i in range(n):
		if bb[i] == diff:
			mi = min(mi, i + 1)
	print(mi)


import sys
reader = (map(int, s.split()) for s in sys.stdin)
(t,) = next(reader)
for _ in range(t):
	(n,) = next(reader)
	a = [2 * x - 3 for x in next(reader)]
	right = [a[i] for i in range(n, 2 * n)]
	left = [a[i] for i in range(n - 1, -1, -1)]
	eat_right = {0: 0}
	sum_r = 0
	for (i, el) in enumerate(right):
		sum_r += el
		if sum_r not in eat_right:
			eat_right[sum_r] = i + 1
	ineq = sum(a)
	best = 2 * n
	sum_l = 0
	i = 0
	while i <= n:
		if ineq - sum_l in eat_right:
			best = min(best, i + eat_right[ineq - sum_l])
		if i < n:
			sum_l += left[i]
		i += 1
	print(best)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	red = a.count(1)
	blue = 2 * n - red
	s = red - blue
	if s == 0:
		print(0)
		return
	cur = 0
	d = {0: 0}
	for i in range(n, 2 * n):
		if a[i] == 2:
			cur -= 1
		else:
			cur += 1
		if cur not in d:
			d[cur] = i - n + 1
	ans = float('inf')
	need = s
	cur = 0
	if need in d:
		ans = min(ans, d[need])
	for i in reversed(list(range(n))):
		if a[i] == 2:
			cur -= 1
		else:
			cur += 1
		if need - cur in d:
			ans = min(ans, d[need - cur] + n - i)
	print(ans)
t = int(input())
for i in range(t):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	ss = input().split()
	n1 = []
	n2 = []
	for i in range(n):
		n1.append(int(ss[n - i - 1]))
		n2.append(int(ss[n + i]))
	cnt = {}
	cur = 0
	cnt[0] = -1
	for i in range(n):
		if n1[i] == 1:
			cur += 1
		else:
			cur -= 1
		if cur not in cnt:
			cnt[cur] = i
	cur = 0
	ans = 10000000
	init = n1.count(1) + n2.count(1) - n1.count(2) - n2.count(2)
	if init == 0:
		print(0)
		continue
	if init in cnt:
		ans = min(ans, cnt[init] + 1)
	for i in range(n):
		if n2[i] == 1:
			cur += 1
		else:
			cur -= 1
		if init - cur in cnt:
			ans = min(ans, i + cnt[init - cur] + 2)
	print(ans)


def case():
	n = int(input())
	a = list(map(int, input().split()))
	for (idx, i) in enumerate(a):
		if i == 2:
			a[idx] = -1
	count = 0
	if sum(a) == 0:
		print(0)
		return
	(x, y) = ({}, {})
	for i in range(n):
		count += a[i]
		x[count] = n - (i + 1)
	count = 0
	for i in range(2 * n - 1, n - 1, -1):
		count += a[i]
		y[count] = i - n
	ans = 10 ** 9
	for i in x.keys():
		if -i in y:
			ans = min(ans, x[i] + y[-i])
	if 0 in x:
		ans = min(ans, x[0] + n)
	if 0 in y:
		ans = min(ans, y[0] + n)
	if ans == 10 ** 9:
		print(2 * n)
	else:
		print(ans)
for _ in range(int(input())):
	case()


from collections import *
for _ in range(int(input())):
	n = int(input())
	l = list(map(lambda val: -1 if val == '2' else 1, input().split()))
	(lft, rgt) = ([0] * n, [0] * n)
	(dLft, dRgt) = (defaultdict(lambda : 0), defaultdict(lambda : 0))
	(lft[0], rgt[0]) = (l[0], l[2 * n - 1])
	(dLft[lft[0]], dRgt[rgt[0]]) = (1, 1)
	for i in range(1, n):
		lft[i] = lft[i - 1] + l[i]
		rgt[i] = rgt[i - 1] + l[2 * n - 1 - i]
		dLft[lft[i]] = i + 1
		dRgt[rgt[i]] = i + 1
	ans = dLft[0] + dRgt[0]
	for i in dLft:
		if dRgt[-i]:
			ans = max(ans, dLft[i] + dRgt[-i])
	print(2 * n - ans)


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	A = list(map(int, input().split()))
	Query.append((N, A))
for (N, A) in Query:
	D = [-1] * (2 * N + 1)
	diff = 0
	D[0] = 0
	for i in range(N):
		if A[-i - 1] == 1:
			diff += 1
		else:
			diff -= 1
		D[diff] = i + 1
	ans = min(2 * N, 2 * N - D[0])
	diff = 0
	for i in range(N):
		if A[i] == 1:
			diff += 1
		else:
			diff -= 1
		if D[-diff] == -1:
			continue
		ans = min(ans, 2 * N - D[-diff] - i - 1)
	print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(R, B) = (0, 0)
	for ai in a:
		if ai == 1:
			R += 1
		else:
			B += 1
	if R == B:
		print(0)
		continue
	dl = defaultdict(int)
	dl[0] = n
	(r, b) = (0, 0)
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			r += 1
		else:
			b += 1
		if r - b not in dl:
			dl[r - b] = i
	if R - B in dl:
		ans = n - dl[R - B]
	else:
		ans = 10 ** 18
	(r, b) = (0, 0)
	for i in range(n, 2 * n):
		if a[i] == 1:
			r += 1
		else:
			b += 1
		if R - B - (r - b) in dl:
			ans = min(ans, i - dl[R - B - (r - b)] + 1)
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input()) * 2
	s = [1 if i == '1' else -1 for i in input().split() if i != '\n']
	(left, right) = ([s[0]], [s[-1]])
	for i in range(1, n // 2):
		left.append(left[i - 1] + s[i])
		right.append(right[i - 1] + s[-i - 1])
	(ans, answ) = (n, n)
	(dict1, dict2) = ({}, {})
	for i in range(n // 2):
		dict1[left[i]] = i
		dict2[right[i]] = n - 1 - i
	for i in dict1:
		if -i in dict2:
			ans = min(ans, dict2[-i] - dict1[i] - 1)
	if 0 in dict1:
		answ = n // 2 - (dict1[0] + 1) + n // 2
	if 0 in dict2:
		answ = dict2[0]
	print(min(ans, answ))


def binSearch(arr, value, key=lambda x: x):
	(l, h) = (0, len(arr) - 1)
	while l <= h:
		x = (h + l) // 2
		k = key(arr[x])
		if value < k:
			h = x - 1
		elif value > k:
			l = x + 1
		else:
			return x
	return -1
t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = [a % 2 for a in arr]
	left = arr[:n][::-1]
	right = arr[n:]
	ones = sum(arr)
	zeros = 2 * n - ones
	diff = ones - zeros
	if diff == 0:
		ans.append(str(0))
		continue
	if abs(diff) == 2 * n:
		ans.append(str(2 * n))
		continue
	dpl = [None] * (n + 1)
	dpl[0] = diff
	dpr = [None] * (n + 1)
	dpr[0] = diff
	lunq = dict()
	lunq[diff] = 0
	runq = dict()
	runq[diff] = 0
	for l in range(1, n + 1):
		if left[l - 1] == 1:
			dpl[l] = dpl[l - 1] - 1
			lunq[dpl[l]] = min(lunq.get(dpl[l], float('inf')), l)
		else:
			dpl[l] = dpl[l - 1] + 1
			lunq[dpl[l]] = min(lunq.get(dpl[l], float('inf')), l)
	for r in range(1, n + 1):
		if right[r - 1] == 1:
			dpr[r] = dpr[r - 1] - 1
			runq[dpr[r]] = min(runq.get(dpr[r], float('inf')), r)
		else:
			dpr[r] = dpr[r - 1] + 1
			runq[dpr[r]] = min(runq.get(dpr[r], float('inf')), r)
	dpr = sorted([(diffr, idr) for (diffr, idr) in runq.items()])
	mn = float('inf')
	for (diffl, idl) in lunq.items():
		k = binSearch(dpr, diff - diffl, key=lambda x: x[0])
		if k != -1:
			mn = min(mn, dpr[k][1] + idl)
	ans.append(str(mn))
print('\n'.join(ans))


import sys
from sys import stdin, stdout
import bisect
import math
import heapq
import collections

def modinv(n, p):
	return pow(n, p - 2, p)

def nc():
	return map(int, ns().split())

def narr():
	return list(map(int, ns().split()))

def ns():
	return input()

def ni():
	return int(input())

def binary_search_all(x, a):
	(lo, hi) = (-1, len(a) - 1)
	while lo + 1 < hi:
		mid = (lo + hi + 1) // 2
		if x <= a[mid][0]:
			hi = mid
		else:
			lo = mid
	if 0 <= hi and hi < len(a) and (a[hi][0] == x):
		return hi
	return -1
cases = ni()
for case in range(cases):
	n = ni()
	a = narr()
	sm = 0
	for i in range(len(a)):
		if a[i] == 2:
			a[i] = -1
		sm += a[i]
	l = list(reversed(a[0:n]))
	r = a[n:len(a)]
	(lsum, rsum) = ([0] * n, [0] * n)
	lsum[0] = -l[0]
	rsum[0] = -r[0]
	for i in range(1, n):
		lsum[i] = lsum[i - 1] - l[i]
		rsum[i] = rsum[i - 1] - r[i]
	ans = 2 * n
	if sm == 0:
		ans = 0
	else:
		for i in range(n):
			if lsum[i] + sm == 0:
				ans = min(ans, i + 1)
				break
		for i in range(n):
			if rsum[i] + sm == 0:
				ans = min(ans, i + 1)
				break
		dic = {}
		for i in range(n):
			if not lsum[i] in dic:
				dic[lsum[i]] = i
		lsum_sorted = sorted([(x, i) for (i, x) in enumerate(lsum)])
		for i in range(n):
			have = sm + rsum[i]
			if -have in dic:
				best_index = dic[-have]
				ans = min(ans, i + best_index + 2)
	print(ans)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	t += -1
	l1 = []
	l2 = []
	c = 0
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			c -= -1
		else:
			c += -1
		l1.append(c)
	c = 0
	for i in range(n, 2 * n):
		if l[i] == 1:
			c -= -1
		else:
			c += -1
		l2.append(c)
	t1 = l1[n - 1]
	t2 = l2[n - 1]
	k = t1 + t2
	if k == 0:
		print(0)
	else:
		ans = 99999999999
		for i in range(len(l1)):
			l1[i] = k - l1[i]
		dic = {}
		for i in range(n):
			dic[l2[i]] = -1
			dic[l1[i]] = -1
			if l2[i] == k:
				ans = min(ans, i + 1)
		for i in range(n):
			if dic[l1[i]] == -1:
				dic[l1[i]] = i
			if l1[i] == 0:
				ans = min(ans, i + 1)
		for i in range(n):
			if dic[l2[i]] != -1:
				ans = min(ans, i + dic[l2[i]] + 2)
		print(ans)


for x in range(int(input())):
	n = int(input())
	m = list(map(int, input().split()))
	a = m.count(2)
	b = 2 * n - a
	v = b - a
	if v == 0:
		print(0)
	else:
		r = {}
		l = {}
		ans = 2 * n
		ra = []
		la = []
		k = 0
		r[0] = 0
		l[0] = 0
		for i in range(n, 2 * n):
			if m[i] == 1:
				k -= 1
			else:
				k += 1
			ra.append(k)
			if k not in r:
				r[k] = i - n + 1
		k = 0
		for i in range(n - 1, -1, -1):
			if m[i] == 1:
				k -= 1
			else:
				k += 1
			la.append(k)
			if k not in l:
				l[k] = n - i
		for i in range(n):
			if -v - ra[i] in l:
				ans = min(ans, i + 1 + l[-v - ra[i]])
		for i in range(n):
			if -v - la[i] in r:
				ans = min(ans, i + 1 + r[-v - la[i]])
		print(ans)


def find(red, blue, dpright):
	diff = blue - red
	if diff not in dpright.keys():
		return float('inf')
	return dpright[diff][0]

def solve(arr, n, ans):
	left = arr[:n]
	right = arr[n:]
	red_right = 0
	blue_right = 0
	dpright = {}
	dpright[0] = [n]
	for i in range(n - 1, -1, -1):
		if right[i] == 2:
			blue_right += 1
		else:
			red_right += 1
		diff = red_right - blue_right
		if diff not in dpright.keys():
			dpright[diff] = [i]
		else:
			dpright[diff].append(i)
	for i in dpright.keys():
		dpright[i].sort()
	ans = float('inf')
	red = 0
	blue = 0
	for x in range(n, -1, -1):
		if x != n:
			if left[n - x - 1] == 1:
				red += 1
			else:
				blue += 1
		y = find(red, blue, dpright)
		ans = min(ans, x + y)
	if ans == float('inf'):
		print(2 * n)
	else:
		print(ans)

def main():
	ans = []
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(arr, n, ans)
	for i in ans:
		print(i)
main()


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
for _ in range(ii()):
	n = ii()
	l = il()
	l1 = l[:n]
	l2 = l[n:]
	(o1, t1, o2, t2) = (0, 0, 0, 0)
	(ld, rd) = ({}, {})
	for i in range(n):
		ld[o1 - t1] = n - i
		if l1[i] == 1:
			o1 += 1
		else:
			t1 += 1
		rd[t2 - o2] = n - i
		if l2[n - i - 1] == 1:
			o2 += 1
		else:
			t2 += 1
	ld[o1 - t1] = 0
	rd[t2 - o2] = 0
	(o1, t1, o2, t2) = (0, 0, 0, 0)
	ans = 2 * n
	for i in range(n):
		if o1 - t1 in rd:
			ans = min(ans, ld[o1 - t1] + rd[o1 - t1])
		if l1[i] == 1:
			o1 += 1
		else:
			t1 += 1
		if t2 - o2 in ld:
			ans = min(ans, ld[-o2 + t2] + rd[-o2 + t2])
		if l2[n - i - 1] == 1:
			o2 += 1
		else:
			t2 += 1
	if o1 - t1 in rd:
		ans = min(ans, ld[o1 - t1] + rd[o1 - t1])
	if t2 - o2 in ld:
		ans = min(ans, ld[-o2 + t2] + rd[-o2 + t2])
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = [-1 if i == 1 else 1 for i in a]
	tsum = sum(a)
	lefta = a[:len(a) // 2]
	righta = a[len(a) // 2:]
	lefta = lefta[::-1]
	lsums = {}
	rsums = {}
	csum = 0
	for i in range(len(lefta)):
		csum += lefta[i]
		if csum not in lsums:
			lsums[csum] = i + 1
	csum = 0
	for i in range(len(righta)):
		csum += righta[i]
		if csum not in rsums:
			rsums[csum] = i + 1
	ans = 0
	if tsum != 0:
		ans = float('inf')
		csum = 0
		for i in range(len(righta)):
			csum += righta[i]
			cntrsum = tsum - csum
			if cntrsum in lsums:
				ans = min(ans, lsums[cntrsum] + i + 1)
			if csum == tsum:
				ans = min(ans, i + 1)
		csum = 0
		for i in range(len(lefta)):
			csum += lefta[i]
			cntrsum = tsum - csum
			if cntrsum in rsums:
				ans = min(ans, rsums[cntrsum] + i + 1)
			if csum == tsum:
				ans = min(ans, i + 1)
	print(ans)


for t in range(int(input())):
	n = 2 * int(input())
	jars = list(map(int, input().split()))
	ones = jars.count(1)
	twos = jars.count(2)
	if ones > twos:
		for idx in range(len(jars)):
			jars[idx] = 3 - jars[idx]
		(ones, twos) = (twos, ones)
	diff = twos - ones
	halfway = n // 2
	left_best = [-1] * (n + 2)
	right_best = [-1] * (n + 2)
	left_best[0] = 0
	right_best[0] = 0
	current_diff = 0
	for idx in range(halfway - 1, -1, -1):
		if jars[idx] == 1:
			current_diff -= 1
		else:
			current_diff += 1
		if current_diff > 0 and left_best[current_diff] == -1:
			left_best[current_diff] = halfway - idx
	current_diff = 0
	for idx in range(halfway, n):
		if jars[idx] == 1:
			current_diff -= 1
		else:
			current_diff += 1
		if current_diff > 0 and right_best[current_diff] == -1:
			right_best[current_diff] = idx - halfway + 1
	best = 1000000
	for left_diff in range(n):
		if left_best[left_diff] == -1 or left_diff > diff:
			break
		if right_best[diff - left_diff] == -1:
			continue
		best = min(best, left_best[left_diff] + right_best[diff - left_diff])
	assert best < 1000000
	print(best)


t = int(input())
from collections import Counter
for _ in range(t):
	n = int(input())
	inp = list(map(int, input().split()))
	left = inp[:len(inp) // 2]
	left = list(reversed(left))
	right = inp[len(inp) // 2:]
	c = Counter(left)
	r_left = c[1]
	b_left = c[2]
	d = Counter(right)
	r_right = d[1]
	b_right = d[2]
	if r_left + r_right == b_left + b_right:
		print(0)
		continue
	l_count = Counter([])
	r_count = Counter([])
	l_count[r_left - b_left] = -1
	ans = len(inp)
	if r_left == b_left:
		ans = min(ans, len(right))
	if r_right == b_right:
		ans = min(ans, len(left))
	for i in range(len(left)):
		if left[i] == 1:
			r_left -= 1
		else:
			b_left -= 1
		if l_count[r_left - b_left] == 0:
			l_count[r_left - b_left] = i + 1
	a = l_count[b_right - r_right]
	if a != 0:
		ans = min(ans, a)
	for i in range(len(right)):
		if right[i] == 1:
			r_right -= 1
		else:
			b_right -= 1
		x = b_right - r_right
		a = l_count[x]
		if a == -1:
			if i + 1 < ans:
				ans = i + 1
			continue
		if a != 0:
			if a + i + 1 < ans:
				ans = a + i + 1
			continue
	print(ans)


for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a1 = a[0:n][::-1]
	a2 = a[n:]
	diff = 0
	for i in a:
		if i == 1:
			diff += 1
		else:
			diff -= 1
	if diff == 0:
		print(0)
		continue
	minn2 = {0: 0}
	minn1 = {0: 0}
	(d1, d2) = (0, 0)
	for i in range(n):
		if a2[i] == 1:
			d2 += 1
		else:
			d2 -= 1
		if d2 not in minn2:
			minn2[d2] = i + 1
		if a1[i] == 1:
			d1 += 1
		else:
			d1 -= 1
		if d1 not in minn1:
			minn1[d1] = i + 1
	ans = 2 * n
	for i in range(-n, n + 1):
		if i in minn1 and diff - i in minn2:
			ans = min(ans, minn1[i] + minn2[diff - i])
	print(ans)


from sys import stdin
di = {'1': 1, '2': -1}
a = lambda : stdin.readline().split()

def f():
	n = int(stdin.readline())
	lst = [di[x] for (i, x) in enumerate(a())]
	straw = lst[:n]
	blue = lst[-1:-n - 1:-1]
	(d, count) = ({0: 0}, 0)
	for (i, x) in enumerate(straw):
		count += x
		d[count] = i + 1
	(count, res) = (0, d[0])
	for (i, x) in enumerate(blue):
		count += x
		if d.get(-count) != None:
			res = max(res, d[-count] + i + 1)
	print(2 * n - res)
for _ in range(int(stdin.readline())):
	f()


import sys
inf = float('inf')

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
T = int(input())
while T:
	n = int(input())
	Arr = get_array()
	(a, b) = (Arr[n - 1::-1], Arr[n:])
	(dict_a, dict_b) = ({0: 0}, {0: 0})
	curr_a = curr_b = 0
	for i in range(n):
		if a[i] == 1:
			curr_a += 1
		else:
			curr_a -= 1
		if curr_a not in dict_a:
			dict_a[curr_a] = i + 1
		if b[i] == 1:
			curr_b += 1
		else:
			curr_b -= 1
		if curr_b not in dict_b:
			dict_b[curr_b] = i + 1
	total = curr_b + curr_a
	ans = inf
	for i in dict_a:
		req = total - i
		if req in dict_b:
			ans = min(ans, dict_a[i] + dict_b[req])
	print(ans)
	T -= 1


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(lambda y: -1 if y == '2' else 1, stdin.readline().split()))
	(cu1, cu2) = ([0], [0])
	for x in range(n):
		cu1.append(arr[x] + cu1[-1])
	for x in range(2 * n - 1, n - 1, -1):
		cu2.append(arr[x] + cu2[-1])
	d = {}
	for (ind, val) in enumerate(cu2):
		d[val] = n - ind
	mini = 2 * n
	for (ind, val) in enumerate(cu1):
		if d.get(-val) != None:
			mini = min(mini, d[-val] + n - ind)
	print(mini)


import sys
input = sys.stdin.readline

def solve(m, b):
	p = [b[0]]
	q = [b[-1]]
	for i in range(1, m):
		p.append(p[-1] + b[i])
		q.append(q[-1] + b[-(i + 1)])
	p_dict = {0: 0}
	q_dict = {0: 0}
	for i in range(m):
		p_dict[p[i]] = i + 1
		q_dict[q[i]] = i + 1
	ans = 0
	for j in range(-m, m + 1):
		if j in p_dict and -j in q_dict:
			ans = max(ans, p_dict[j] + q_dict[-j])
	print(2 * m - ans)
t = int(input())
for case in range(t):
	n = int(input())
	a = [(-1) ** int(x) for x in input().split(' ')]
	solve(n, a)


import sys
from collections import Counter
input = sys.stdin.readline

def find(R, B, up, down):
	pre = [0 for i in range(len(up))]
	(r, b) = (0, 0)
	for i in range(len(down)):
		if down[i] == 1:
			r += 1
		else:
			b += 1
		pre[i] = r - b
	dic = {}
	for i in range(len(pre)):
		if pre[i] not in dic:
			dic[pre[i]] = i + 1
	ans = len(up) * 2
	for i in range(len(up)):
		if up[i] == 1:
			R -= 1
		else:
			B -= 1
		if R - B in dic:
			ans = min(ans, i + 1 + dic[R - B])
		if R == B:
			ans = min(ans, i + 1)
	return ans
for _ in range(int(input().strip())):
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	up = []
	for i in range(n - 1, -1, -1):
		up.append(arr[i])
	down = arr[n:]
	co = Counter(arr)
	R = co[1] if 1 in co else 0
	B = co[2] if 2 in co else 0
	if R == B:
		print(0)
	else:
		ans = find(R, B, up, down)
		ans = min(ans, find(R, B, down, up))
		print(ans)


for hasju in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n * 2):
		if a[i] == 2:
			a[i] = -1
	ns = sum(a)
	ps1 = [0]
	for i in range(n - 1, -1, -1):
		ps1.append(ps1[-1] + a[i])
	ps2 = [0]
	for i in range(n, n * 2):
		ps2.append(ps2[-1] + a[i])
	ps1 = [[ps1[i], i] for i in range(len(ps1))]
	ps1.sort()
	ans = 5738927598279537293752398572398579
	for i in range(len(ps2)):
		rem = ns - ps2[i]
		l = -1
		r = len(ps1)
		while r - l != 1:
			s = (l + r) // 2
			if ps1[s][0] >= rem:
				r = s
			else:
				l = s
		if r == len(ps1) or ps1[r][0] != rem:
			continue
		else:
			ans = min(ans, i + ps1[r][1])
	if ans == 5738927598279537293752398572398579:
		print(n * 2)
	else:
		print(ans)


import sys

def kek():
	t = int(input())
	for _ in range(t):
		sys.stdin.readline()
		inp = list(map(int, sys.stdin.readline().split()))
		arrLeft = inp[:len(inp) // 2]
		arrRight = inp[len(inp) // 2:]
		arrRight = list(reversed(arrRight))
		if arrRight[0] == 1:
			arrRight[0] = 1
		else:
			arrRight[0] = -1
		if arrLeft[0] == 1:
			arrLeft[0] = 1
		else:
			arrLeft[0] = -1
		color = 0
		for i in range(1, len(arrLeft)):
			if arrLeft[i] == 1:
				color = 1
			else:
				color = -1
			arrLeft[i] = arrLeft[i - 1] + color
		color = 0
		for i in range(1, len(arrRight)):
			if arrRight[i] == 1:
				color = 1
			else:
				color = -1
			arrRight[i] = arrRight[i - 1] + color
		se = set()
		d = dict()
		se.add(0)
		d[0] = 0
		for i in range(len(arrRight)):
			se.add(arrRight[i])
			d[arrRight[i]] = i + 1
		ans = 0
		for i in range(len(arrLeft)):
			if -arrLeft[i] in se:
				ans = max(d[-arrLeft[i]] + i + 1, ans)
		ans = max(d[0], ans)
		print(len(arrRight) + len(arrLeft) - ans)
kek()


import sys, math, queue, collections
MOD = 10 ** 9 + 7

def left_border(a, r):
	ans = -10 ** 10
	(l, h) = (0, len(a) - 1)
	while l <= h:
		m = (l + h) // 2
		if a[m] <= r:
			ans = a[m]
			l = m + 1
		else:
			h = m - 1
	return ans
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ps = [0 for i in range(2 * n)]
	pb = [0 for i in range(2 * n)]
	v = {0: [-1]}
	for i in range(2 * n):
		ps[i] += ps[i - 1]
		pb[i] += pb[i - 1]
		if a[i] == 1:
			ps[i] += 1
		else:
			pb[i] += 1
		if i >= n:
			continue
		d = ps[i] - pb[i]
		if d in v:
			v[d].append(i)
		else:
			v[d] = [i]
	ans = 2 * n
	for i in range(n - 1, 2 * n):
		d = ps[i] - pb[i] - (ps[-1] - pb[-1])
		if d not in v:
			continue
		ans = min(ans, i - left_border(v[d], i))
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split()))
	left = a[:n]
	right = a[n:]
	red = 0
	blue = 0
	balance_left = [0] * (n + 1)
	balance_right = [0] * (n + 1)
	for j in range(n):
		if left[-j - 1] == 1:
			red += 1
			balance_left[j + 1] = balance_left[j] + 1
		else:
			blue += 1
			balance_left[j + 1] = balance_left[j] - 1
		if right[j] == 1:
			red += 1
			balance_right[j + 1] = balance_right[j] + 1
		else:
			blue += 1
			balance_right[j + 1] = balance_right[j] - 1
	difference = red - blue
	min_number_of_jars = 10 ** 6
	potential_pairs = {}
	for left_index in range(n + 1):
		if difference - balance_left[left_index] in potential_pairs.keys():
			pass
		else:
			potential_pairs[difference - balance_left[left_index]] = left_index
	for right_index in range(n + 1):
		if balance_right[right_index] in potential_pairs.keys():
			tmp_min = right_index + potential_pairs[balance_right[right_index]]
			if tmp_min < min_number_of_jars:
				min_number_of_jars = tmp_min
	print(min_number_of_jars)


def stdize(x):
	return 1 if x == 2 else -1

def solve():
	n = int(input())
	arr = [stdize(int(x)) for x in input().split()]
	cur = 0
	mp = {0: 0}
	for (i, v) in enumerate(arr[n:]):
		cur += v
		if cur not in mp:
			mp[cur] = i + 1
	cur = 0
	ans = 200000.0 + 1
	d = sum(arr)
	if d in mp:
		ans = min(ans, mp[d])
	for (i, v) in enumerate(arr[:n][::-1]):
		cur += v
		key = d - cur
		if key in mp:
			ans = min(ans, i + 1 + mp[key])
	print(ans)
	return ans

def main():
	tc = int(input())
	for _ in range(tc):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(q2, s) = (0, {})
	for q in range(2 * n - 1, n - 1, -1):
		s[q2] = q - n + 1
		q2 += a[q] * 2 - 3
	(s[q2], q2, ans) = (0, 0, float('inf'))
	for q in range(n):
		ans = min(ans, n - q + (s[-q2] if -q2 in s else float('inf')))
		q2 += a[q] * 2 - 3
	print(min(ans, s[-q2] if -q2 in s else float('inf')))


import sys
input = sys.stdin.buffer.readline
INF = float('inf')
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

def main():
	N = int(input())
	for k in range(N):
		M = int(input())
		A = getlist()
		Dright = defaultdict(lambda : -INF)
		Dright[0] = 0
		val = 0
		for i in range(M):
			if A[-1 - i] == 2:
				val += 1
			else:
				val -= 1
			Dright[val] = i + 1
		ans = 2 * M
		cnt = 0
		ans = min(ans, 2 * M - Dright[cnt])
		for i in range(M):
			if A[i] == 1:
				cnt += 1
			else:
				cnt -= 1
			ans = min(ans, 2 * M - i - 1 - Dright[cnt])
		print(ans)
main()


import sys, bisect
input = sys.stdin.readline

def inp():
	return int(input().rstrip())

def inlt():
	return list(map(int, input().rstrip().split()))

def insr():
	s = input().rstrip()
	return s[:len(s) - 1]

def invr():
	return map(int, input().rstrip().split())
t = inp()
for _ in range(t):
	n = inp()
	nums = [1 if i == 1 else -1 for i in inlt()]
	index_left = n - 1
	index_right = n
	left = nums[:n]
	left.reverse()
	s_left = sum(left)
	right = nums[n:]
	s_right = sum(right)
	right_dict = dict()
	left_dict = dict()
	if s_left + s_right == 0:
		print(0)
	else:
		cur = s_right
		right_dict[cur] = 0
		for (cnt, i) in enumerate(right, 1):
			cur -= i
			if cur not in right_dict:
				right_dict[cur] = cnt
		cur = s_left
		for (cnt, i) in enumerate(left, 1):
			cur -= i
			if cur not in left_dict:
				left_dict[cur] = cnt
		ans = 10000010
		cur = s_left
		left_dict[cur] = 0
		for (cnt, i) in enumerate(left, 1):
			cur -= i
			if -cur in right_dict:
				ans = min(ans, cnt + right_dict[-cur])
		cur = s_right
		for (cnt, i) in enumerate(right, 1):
			cur -= i
			if -cur in left_dict:
				ans = min(ans, cnt + left_dict[-cur])
		print(ans)


import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [None] * T
inf = 10 ** 9 + 7
for qu in range(T):
	N = int(readline())
	A = list(map(int, readline().split()))
	bj = A.count(1)
	sj = 2 * N - bj
	x = sj - bj
	A1 = [3 - 2 * a for a in A[:N][::-1]]
	A2 = [3 - 2 * a for a in A[N:]]
	for i in range(1, N):
		A1[i] += A1[i - 1]
		A2[i] += A2[i - 1]
	geta = -min(0, min(A2)) + 1
	mA = max(0, max(A2))
	idx = [inf] * (mA + geta + 1)
	idx[geta + 0] = 0
	for i in range(N):
		a2 = A2[i]
		idx[geta + a2] = min(idx[geta + a2], i + 1)
	ans = inf
	A1 = [0] + A1
	for i in range(N + 1):
		a1 = A1[i]
		if -geta <= -a1 - x <= mA:
			ans = min(ans, i + idx[geta - a1 - x])
	Ans[qu] = ans
print('\n'.join(map(str, Ans)))


import bisect
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	pref1 = [0] * n
	cnt1 = 0
	pref2 = [0] * n
	cnt2 = 0
	for i in range(len(a)):
		if a[i] == 2:
			a[i] = -1
			cnt2 += 1
		else:
			cnt1 += 1
	if cnt1 == cnt2:
		print(0)
	else:
		pref1[0] = a[n - 1]
		for i in range(n - 2, -1, -1):
			pref1[n - i - 1] = pref1[n - i - 2] + a[i]
		pref2[0] = a[n]
		for i in range(n + 1, 2 * n):
			pref2[i - n] = pref2[i - n - 1] + a[i]
		now_balance = cnt1 - cnt2
		ans = 2 * n
		set_pref2 = set(pref2)
		min_index = {}
		for i in range(len(pref2)):
			min_index[pref2[i]] = 10000000000
		for i in range(len(pref2)):
			min_index[pref2[i]] = min(min_index[pref2[i]], i)
		for i in range(len(pref1)):
			now = pref1[i]
			want = now_balance - now
			if want in set_pref2:
				ans = min(ans, min_index[want] + i + 2)
		for i in range(len(pref1)):
			if pref1[i] == now_balance:
				ans = min(ans, i + 1)
		for i in range(len(pref2)):
			if pref2[i] == now_balance:
				ans = min(ans, i + 1)
		print(ans)


import os
import sys
from math import *
from collections import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	_a = array()
	a = _a[:n]
	b = _a[n:]
	red = 0
	blue = 0
	ind = defaultdict(lambda : inf)
	here = n
	ind[red - blue] = here
	for i in range(n - 1, -1, -1):
		if b[i] == 1:
			red += 1
		else:
			blue += 1
		here -= 1
		ind[red - blue] = here
	red = 0
	blue = 0
	here = n
	ans = 2 * n
	ans = min(here + ind[0], ans)
	for i in a:
		if i == 1:
			red += 1
		else:
			blue += 1
		here -= 1
		ans = min(here + ind[blue - red], ans)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	count_1 = lst.count(1)
	count_2 = 2 * n - count_1
	if count_1 == count_2:
		print(0)
		continue
	init_diff = count_1 - count_2
	dp = [0 for j in range(n)]
	diff = 0
	for i in range(n, 2 * n):
		if lst[i] == 1:
			diff += 1
		else:
			diff -= 1
		dp[i - n] = diff
	diff = 0
	Dict = {}
	for i in range(n - 1, -1, -1):
		if lst[i] == 1:
			diff += 1
		else:
			diff -= 1
		if Dict.get(init_diff - diff) == None:
			Dict[init_diff - diff] = n - 1 - i
	Ans = float('inf')
	for i in range(n):
		ele = dp[i]
		if Dict.get(ele) != None:
			Ans = min(Ans, i + 1 + Dict[ele] + 1)
	try:
		get1 = dp.index(init_diff) + 1
		Ans = min(Ans, get1)
	except:
		None
	if Dict.get(0):
		Ans = min(Ans, Dict[0] + 1)
	print(Ans)


def r(a):
	s = [0]
	for i in range(len(a)):
		s.append(s[-1] + a[i])
	return s[::-1]
for _ in range(int(input())):
	n = int(input())
	a = list(map(lambda x: [0, 1, -1][x], list(map(int, input().split()))))
	(a, b) = (a[:n], a[n:][::-1])
	(ra, rb) = (r(a), r(b))
	rb = sorted([(rb[i], i) for i in range(n + 1)])
	d = 4 * n
	for i in range(n + 1):
		e = ra[i]
		(L, R) = (0, n)
		t = (10000000000, 8 * n)
		while L <= R:
			M = (L + R) // 2
			if rb[M][0] >= -e:
				t = rb[M]
				R = M - 1
			else:
				L = M + 1
		if t[0] + e == 0 and t[1] < 4 * n:
			d = min(d, i + t[1])
	print(d)


t = int(input())
while t > 0:
	n = int(input())
	ones = 0
	twos = 0
	a = [int(i) for i in input().split()]
	d1 = {}
	d2 = {}
	for i in a:
		if i == 1:
			ones += 1
		else:
			twos += 1
	if ones == twos:
		print(0)
		t -= 1
		continue
	else:
		pos = 0
		if ones > twos:
			diff = ones - twos
			pos = 1
		else:
			diff = twos - ones
			pos = 2
	k = diff
	diffa = [0 for i in range(2 * n + 5)]
	for i in range(n - 1, -1, -1):
		if a[i] == pos:
			k -= 1
		else:
			k += 1
		diffa[i] = k
		if d1.get(k, -1) == -1:
			d1[k] = n - i
		if k == 0:
			break
	k = diff
	for i in range(n, 2 * n):
		if a[i] == pos:
			k -= 1
		else:
			k += 1
		diffa[i] = k
		if d2.get(k, -1) == -1:
			d2[k] = i + 1 - n
		if k == 0:
			break
	ans = 10000000
	for i in range(n - 1, -1, -1):
		if diffa[i] == 0:
			ans = min(ans, n - i)
		else:
			need = diff - diffa[i]
			cur = d2.get(need, None)
			if cur != None:
				ans = min(ans, cur + (n - i))
	for i in range(n, 2 * n):
		if diffa[i] == 0:
			ans = min(ans, i + 1 - n)
		else:
			need = diff - diffa[i]
			cur = d1.get(need, None)
			if cur != None:
				ans = min(ans, cur + (i + 1 - n))
	print(ans)
	t -= 1


n = int(input())

def calc(a):
	cs = 0
	for v in a:
		cs += 1 if v == 1 else -1
	rcs = cs
	for (m, v) in enumerate(a):
		cs -= 1 if v == 1 else -1
		a[m] = cs
	return rcs
for i in range(n):
	k = int(input())
	a = list(map(int, input().split(' ')))
	b = 0
	l = a[k - 1::-1]
	r = a[k:]
	lc = calc(l)
	rc = calc(r)
	l = [lc, *l]
	r = [rc, *r]
	ml = {}
	for (p, v) in enumerate(l):
		if v in ml:
			ml[v] = min(p, ml[v])
		else:
			ml[v] = p
	ans = int(1000000000.0)
	for (p, v) in enumerate(r):
		if -v in ml:
			ans = min(ans, ml[-v] + p)
	print(ans)


def inp(ai):
	cur = sum(ai) * 2 - n * 3
	yield cur
	for aii in ai:
		if aii == 1:
			cur += 1
		else:
			cur -= 1
		yield cur

def inp2(ii):
	ans = {}
	for (i, iii) in enumerate(ii):
		if iii not in ans:
			ans[iii] = i
	return ans
for _ in range(int(input())):
	n = int(input())
	a = iter(map(int, input().split()))
	a1 = [next(a) for _ in range(n)]
	a1.reverse()
	a2 = list(a)
	i1 = inp2(inp(a1))
	i2 = inp2((-i2i for i2i in inp(a2)))
	res = n * 2
	for k in i1.keys():
		if k in i2.keys():
			res = min(res, i1[k] + i2[k])
	print(res)


for nt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	(two, one) = (0, 0)
	for i in l:
		if i == 1:
			one += 1
		else:
			two += 1
	if one == 0 or two == 0:
		print(2 * n)
		continue
	if one == two:
		print(0)
		continue
	ans = []
	if True:
		diff = one - two
		d1 = {}
		(prev1, prev2) = (0, 0)
		for i in range(n - 1, -1, -1):
			if l[i] == 1:
				if str(prev1 + 1 - prev2) not in d1:
					d1[str(prev1 + 1 - prev2)] = n - i
				prev1 += 1
			else:
				if str(prev1 - prev2 - 1) not in d1:
					d1[str(prev1 - prev2 - 1)] = n - i
				prev2 += 1
		d2 = {}
		(prev1, prev2) = (0, 0)
		for i in range(n, 2 * n):
			if l[i] == 1:
				if str(prev1 + 1 - prev2) not in d2:
					d2[str(prev1 + 1 - prev2)] = i - n + 1
				prev1 += 1
			else:
				if str(prev1 - prev2 - 1) not in d2:
					d2[str(prev1 - prev2 - 1)] = i - n + 1
				prev2 += 1
		if str(diff) in d1:
			ans.append(d1[str(diff)])
		for i in range(n, 2 * n):
			if l[i] == 1:
				diff -= 1
			else:
				diff += 1
			if str(diff) in d1:
				ans.append(d1[str(diff)] + i - n + 1)
		diff = one - two
		if str(diff) in d2:
			ans.append(d2[str(diff)])
		for i in range(n - 1, -1, -1):
			if l[i] == 1:
				diff -= 1
			else:
				diff += 1
			if str(diff) in d2:
				ans.append(d2[str(diff)] + n - i)
		print(min(ans))


t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	d = {0: 0}
	c = 0
	for i in range(n, 2 * n):
		if x[i] == 1:
			c += 1
		else:
			c -= 1
		if c not in d:
			d[c] = i - n + 1
	diff = x.count(1) - x.count(2)
	ans = 2 * n
	c = 0
	for i in range(n - 1, -1, -1):
		if x[i] == 1:
			c += 1
		else:
			c -= 1
		if diff - c in d:
			ans = min(ans, d[diff - c] + n - i)
	if diff in d:
		ans = min(ans, d[diff])
	print(ans)


from collections import deque
import sys

def inp():
	return sys.stdin.readline().strip()
for _ in range(int(inp())):
	n = int(inp())
	a = list(map(int, inp().split()))
	dp1 = [[0, 0] for _ in range(n)]
	dp2 = [[0, 0] for _ in range(n)]
	for i in range(n):
		if i - 1 >= 0:
			dp1[i][0] = dp1[i - 1][0]
			dp1[i][1] = dp1[i - 1][1]
		dp1[i][a[i] - 1] += 1
	for i in range(2 * n - 1, n - 1, -1):
		if i + 1 - n < len(dp2):
			dp2[i - n][0] = dp2[i - n + 1][0]
			dp2[i - n][1] = dp2[i - n + 1][1]
		dp2[i - n][a[i] - 1] += 1
	ans = 2 * n
	dp3 = {}
	for i in range(n):
		val = dp1[i][0] - dp1[i][1]
		dp3[val] = i
	for j in range(n):
		val = dp2[j][1] - dp2[j][0]
		if val in dp3:
			ans = min(ans, n - dp3[val] + j + 1 - 2)
	for i in range(n):
		if dp1[i][0] == dp1[i][1]:
			ans = min(ans, n - i + n - 1)
		if dp2[i][0] == dp2[i][1]:
			ans = min(ans, n + i)
	print(ans)


from collections import deque

def solve(jars):
	delta = sum(jars)
	if delta == 0:
		return 0
	rp = {0: 0}
	dr = 0
	steps = 2 * n
	for i in range(n, 2 * n):
		dr += jars[i]
		if dr not in rp:
			rp[dr] = i - n + 1
			if delta == dr:
				steps = min(steps, i - n + 1)
	dl = 0
	for i in range(n - 1, -1, -1):
		dl += jars[i]
		ch = delta - dl
		ra = rp.get(ch)
		if ra != None:
			steps = min(steps, ra + n - i)
	return steps
tc = int(input())
for x in range(tc):
	n = int(input())
	jars = [1 if int(x) == 1 else -1 for x in input().split()]
	print(solve(jars))


import itertools

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a = list(map({1: 1, 2: -1}.__getitem__, a))
	l = a[:n]
	l.reverse()
	r = a[n:]
	l = [0] + list(itertools.accumulate(l))
	r = [0] + list(itertools.accumulate(r))
	d = {}
	for i in range(n + 1):
		if l[i] not in d:
			d[l[i]] = i
	s = sum(a)
	ans = n * 2
	for i in range(n + 1):
		if s - r[i] in d:
			ans = min(ans, i + d[s - r[i]])
	print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	line = input()
	nums = [int(item) for item in line.strip().split()]
	(a, b) = (0, 0)
	(dpa, dpb) = ([0] * (2 * n), [0] * (2 * n))
	for j in range(2 * n):
		if nums[j] == 1:
			a += 1
		elif nums[j] == 2:
			b += 1
		dpa[j] = a
		dpb[j] = b
	if a == b:
		print(0)
		continue
	d = a - b
	dict = {}
	for j in range(n, 2 * n):
		cura = dpa[j] - dpa[n]
		curb = dpb[j] - dpb[n]
		if nums[n] == 1:
			cura += 1
		else:
			curb += 1
		diff = cura - curb
		if diff not in dict:
			dict[diff] = j - n + 1
	mmin = float('inf')
	for x in range(n - 1, -1, -1):
		cura = dpa[n - 1] - dpa[x]
		curb = dpb[n - 1] - dpb[x]
		if nums[x] == 1:
			cura += 1
		else:
			curb += 1
		diff = cura - curb
		if diff == d:
			mmin = min(mmin, n - x)
			break
		if d - diff in dict:
			mmin = min(mmin, dict[d - diff] + n - x)
	if d in dict:
		mmin = min(mmin, dict[d])
	print(mmin)


def solve():
	n = int(input())
	nums = list(map(int, input().split(' ')))
	sum = []
	for i in range(len(nums)):
		if nums[i] == 2:
			nums[i] = -1
	tem = 0
	pos = {}
	pos[0] = -1
	for i in range(len(nums)):
		tem += nums[i]
		sum.append(tem)
		if i < n:
			pos[tem] = i
	ans = 2 * n
	for i in range(n - 1, len(nums)):
		if sum[i] - sum[-1] in pos:
			ans = min(ans, i - pos[sum[i] - sum[-1]])
	print(ans)
N = int(input())
for _ in range(N):
	solve()


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
N = int(input())
for _ in range(N):
	n = int(input())
	lis = list(map(int, input().split()))
	sm = [0]
	for i in lis:
		sm.append(sm[-1] + 1) if i == 1 else sm.append(sm[-1] - 1)
	dif = sm[-1]
	dic = {}
	res = 2 * n
	if dif == 0:
		print(dif)
	else:
		for (i, v) in enumerate(sm):
			if i < n + 1:
				dic[v] = i
			if i >= n:
				t = v - dif
				if t in dic:
					res = min(res, i - dic[t])
		print(res)


import itertools
from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ones = a.count(1)
	twos = a.count(2)
	a1 = a[:n][::-1]
	a2 = a[n:]
	target = ones - twos
	a1 = [[-1, 1][x == 1] for x in a1]
	a1 = [0] + list(itertools.accumulate(a1))
	a2 = [[-1, 1][x == 1] for x in a2]
	a2 = [0] + list(itertools.accumulate(a2))
	a2v = defaultdict(lambda : 2 * n + 1)
	for (i2, x2) in enumerate(a2):
		a2v[x2] = min(a2v[x2], i2)
	best = 2 * n
	for (i1, x1) in enumerate(a1):
		best = min(best, i1 + a2v[target - x1])
	print(best)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = []
	a1 = 0
	a2 = 0
	for i in range(0, n):
		if l[i] == 1:
			a1 += 1
		else:
			a2 += 1
		l1.append(a1 - a2)
	a1 = 0
	a2 = 0
	d = {}
	d[0] = 2 * n
	for i in range(2 * n - 1, n - 1, -1):
		if l[i] == 1:
			a1 += 1
		else:
			a2 += 1
		d[a2 - a1] = i
	min1 = d.get(0, 2 * n)
	for i in range(n):
		if d.get(l1[i]) != None:
			s = d[l1[i]] - i - 1
			if min1 > s:
				min1 = s
	print(min1)


def f(m, arr, max):
	sum = 0
	extra = 1
	for i in range(len(arr)):
		if extra > max:
			break
		sum += arr[i]
		if sum > 0:
			sum = 0
			m[extra] = i + 1
			extra += 1
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	arr = [1 if x == 1 else -1 for x in arr]
	sum = 0
	for x in arr:
		sum += x
	if sum == 0:
		print('0')
		continue
	if sum < 0:
		for i in range(len(arr)):
			arr[i] *= -1
		sum *= -1
	left = arr[:n]
	left.reverse()
	right = arr[n:]
	l_map = [0] + [float('inf')] * sum
	r_map = [0] + [float('inf')] * sum
	f(l_map, left, sum)
	f(r_map, right, sum)
	ans = float('inf')
	for i in range(0, sum + 1):
		temp = l_map[i] + r_map[sum - i]
		if temp < ans:
			ans = temp
	print(ans)


q = int(input())
for rwier in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	j = l.count(1)
	d = l.count(2)
	pr = [0] * n
	le = [0] * n
	pr[0] = 1 if l[n] == 1 else -1
	le[0] = 1 if l[n - 1] == 1 else -1
	for i in range(1, n):
		pr[i] = pr[i - 1] + (1 if l[n + i] == 1 else -1)
		le[i] = le[i - 1] + (1 if l[n - i - 1] == 1 else -1)
	if j - d < 0:
		for i in range(n):
			pr[i] = -pr[i]
			le[i] = -le[i]
	ab = abs(j - d)
	if ab == 0:
		print(0)
	else:
		najwp = [123456789] * (2 * n + 1)
		najwl = [123456789] * (2 * n + 1)
		le = [0] + le
		pr = [0] + pr
		for i in range(n + 1):
			if pr[i] >= 0 and najwp[pr[i]] == 123456789:
				najwp[pr[i]] = i
			if le[i] >= 0 and najwl[le[i]] == 123456789:
				najwl[le[i]] = i
		wyn = 41343443143
		for i in range(ab + 1):
			if najwp[i] + najwl[ab - i] < wyn:
				wyn = najwp[i] + najwl[ab - i]
		print(wyn)


from collections import defaultdict
tag = {'1': 1, '2': -1}
for _ in range(int(input())):
	n = int(input())
	l = [tag[x] for x in input().split()]
	d = defaultdict(int=-2)
	left_scores = [0 for i in range(n + 1)]
	d[0] = n
	right_score = 0
	for i in range(1, n + 1):
		left_scores[i] = left_scores[i - 1] + l[i - 1]
		right_score += l[-i]
		d[right_score] = n - i
	minima = []
	for i in range(len(left_scores)):
		score = left_scores[i]
		if -1 * score in d:
			minima.append(n - i + d[-1 * score])
	print(min(minima))


import sys
input = sys.stdin.readline
from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = [1 if int(item) == 2 else -1 for item in input().split()]
	seen = dict()
	seen[0] = 0
	total = 0
	for (i, item) in enumerate(a[:n]):
		total += item
		seen[total] = i + 1
	a.reverse()
	total = 0
	ans = 0
	if 0 in seen:
		ans = max(ans, seen[0])
	for (i, item) in enumerate(a[:n]):
		total += item
		if -total in seen:
			ans = max(ans, seen[-total] + i + 1)
	print(n * 2 - ans)


from collections import Counter
from math import inf
for _ in range(int(input())):
	n = int(input())
	a = [int(X) for X in input().split()]
	for i in range(2 * n):
		if a[i] == 2:
			a[i] = -1
	z = a[:n]
	y = a[n:2 * n][::-1]
	c1 = Counter()
	c2 = Counter()
	c1[z[0]] = 1
	c2[y[0]] = 1
	an = inf
	for j in range(1, n):
		z[j] += z[j - 1]
		if z[j] == 0:
			an = min(an, 2 * n - j - 1)
	for j in range(1, n):
		y[j] += y[j - 1]
		c2[y[j]] = j + 1
		if y[j] == 0:
			an = min(an, 2 * n - j - 1)
	c = 0
	for i in z[::-1]:
		if c2[-1 * i] != 0:
			an = min(c + n - c2[-1 * i], an)
		c += 1
	print(min(an, 2 * n))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	total = sum((1 for x in a if x == 1))
	total -= sum((1 for x in a if x == 2))
	rightVals = {0: n - 1}
	running = 0
	for i in range(n, 2 * n):
		if a[i] == 1:
			running += 1
		else:
			running -= 1
		if running not in rightVals:
			rightVals[running] = i
	result = float('inf')
	running = 0
	for i in reversed(range(n)):
		if a[i] == 1:
			running += 1
		else:
			running -= 1
		if total - running in rightVals:
			result = min(result, rightVals[total - running] - n + 1 + (n - i))
	if total in rightVals:
		result = min(result, rightVals[total] - n + 1)
	print(result)


for _ in range(int(input())):
	n = int(input())
	a = [int(o) for o in input().split()]
	for i in range(2 * n):
		if a[i] == 2:
			a[i] = -1
	pre = [0] * (2 * n + 2)
	for i in range(1, 2 * n + 1):
		pre[i] = pre[i - 1] + a[i - 1]
	d = dict()
	for i in range(0, n + 1):
		if pre[n + i] - pre[n] not in d:
			d[pre[n + i] - pre[n]] = i
	ans = []
	for i in range(0, n + 1):
		lol = pre[2 * n] - (pre[n] - pre[n - i])
		if lol in d:
			ans.append(i + d[lol])
	print(min(ans))


for _ in [0] * int(input()):
	n = int(input())
	s = list(map(int, input().split()))
	Al = [0] * (n + 1)
	Ar = [0] * (n + 1)
	count = 0
	for l in range(1, n + 1):
		if s[n - l] == 2:
			Al[l] = Al[l - 1] + 1
			count += 1
		else:
			Al[l] = Al[l - 1] - 1
			count -= 1
	for r in range(1, n + 1):
		if s[n + r - 1] == 2:
			Ar[r] = Ar[r - 1] + 1
			count += 1
		else:
			Ar[r] = Ar[r - 1] - 1
			count -= 1
	if count == 0:
		print(0)
	else:
		minstep = 2 * n
		p = {}
		for l in range(n, -1, -1):
			p[Al[l]] = l
		for r in range(n + 1):
			k = count - Ar[r]
			if k in p:
				minstep = min(minstep, p[k] + r)
		print(minstep)


import sys
t = int(sys.stdin.readline())
ans_arr = []
for x in range(t):
	n = int(sys.stdin.readline())
	a = [int(i) for i in sys.stdin.readline().split()]
	d = {}
	r = 0
	b = 0
	for i in range(2 * n):
		if a[i] == 1:
			r += 1
		else:
			b += 1
	if r == b:
		ans_arr.append(str(0))
	else:
		r1 = 0
		b1 = 0
		for e in range(n - 1, -1, -1):
			if a[e] == 1:
				r1 += 1
			else:
				b1 += 1
			if r1 - b1 not in d:
				d[r1 - b1] = e
		ans = 2 * n
		r2 = 0
		b2 = 0
		for f in range(n, 2 * n):
			if a[f] == 1:
				r2 += 1
			else:
				b2 += 1
			if r - b - (r2 - b2) in d:
				ans = min(ans, f - d[r - b - (r2 - b2)] + 1)
		rend = 0
		bend = 0
		for g in range(n - 1, -1, -1):
			if a[g] == 1:
				rend += 1
			else:
				bend += 1
			if r - rend == b - bend:
				ans = min(ans, n - g)
		rsta = 0
		bsta = 0
		for h in range(n, 2 * n):
			if a[h] == 1:
				rsta += 1
			else:
				bsta += 1
			if r - rsta == b - bsta:
				ans = min(ans, h - n + 1)
		ans_arr.append(str(ans))
print('\n'.join(ans_arr))


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	n = ip()
	n = n * 2
	arr = list(inp())
	ct1 = arr.count(1)
	ct2 = arr.count(2)
	if ct1 == ct2:
		ans = 0
	else:
		diff = ct1 - ct2
		dicl = dd(lambda : float('inf'))
		dicr = dd(lambda : float('inf'))
		d = 0
		for i in range(n // 2, n):
			if arr[i] == 1:
				d += 1
			else:
				d -= 1
			dicr[d] = min(dicr[d], i - n // 2 + 1)
		d = 0
		for i in range(n // 2 - 1, -1, -1):
			if arr[i] == 1:
				d += 1
			else:
				d -= 1
			dicl[d] = min(dicl[d], n // 2 - i)
		ans = []
		dicl[0] = 0
		dicr[0] = 0
		for i in dicl:
			vall = dicl[i]
			d = diff - i
			valr = dicr[d]
			if valr == float('inf'):
				pass
			else:
				ans.append(vall + valr)
		ans = min(ans)
	out(ans)


from collections import deque
import sys
import math
input = sys.stdin.buffer.readline
q = int(input())
ones = 0
twos = 0
for _ in range(q):
	n = int(input())
	mintotal = 10 ** 6
	x = list(map(int, input().split()))
	ones = x.count(1)
	twos = x.count(2)
	diff = twos - ones
	if diff == 0:
		print(0)
	else:
		right = x[n:]
		left = x[:n]
		left = left[::-1]
		racc = []
		lacc = []
		firstleft = {}
		firstright = {}
		firstleft[0] = 0
		firstright[0] = 0
		total = 0
		for i in right:
			if i == 1:
				total -= 1
			else:
				total += 1
			racc.append(total)
		total = 0
		for i in left:
			if i == 1:
				total -= 1
			else:
				total += 1
			lacc.append(total)
		for x in range(len(racc)):
			if racc[x] not in firstright.keys():
				firstright[racc[x]] = x + 1
		for x in range(len(lacc)):
			if lacc[x] not in firstleft.keys():
				firstleft[lacc[x]] = x + 1
		if diff < 0:
			for x in range(abs(diff) + 1):
				if -x in firstleft.keys():
					if diff + x in firstright.keys():
						mintotal = min(mintotal, firstleft[-x] + firstright[diff + x])
			print(mintotal)
		else:
			for x in range(diff + 1):
				if x in firstleft.keys():
					if diff - x in firstright.keys():
						mintotal = min(mintotal, firstleft[x] + firstright[diff - x])
			print(mintotal)


for l in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	d = [0]
	for i in a:
		if i == 1:
			d.append(d[-1] + 1)
		else:
			d.append(d[-1] - 1)
	x = d[-1]
	p = {}
	for i in range(n + 1):
		p[d[i]] = n - i
	z = 2 * n
	for i in range(n, 2 * n + 1):
		k = d[i] - x
		if k in p:
			z = min(z, i + p[k] - n)
	print(z)


INF = int(1000000000.0)
t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = sum(a) - 2 * n
	r = 2 * n - b
	if r > b:
		flag = 1
	elif r == b:
		print(0)
		continue
	else:
		flag = 2
	diff = abs(b - r)
	dp_left = [INF] * (2 * n + 10)
	dp_right = [INF] * (2 * n + 10)
	dp_left[0] = 0
	dp_right[0] = 0
	c = 0
	d = 0
	for i in range(n):
		if a[n - 1 - i] == flag:
			c += 1
		else:
			c -= 1
		if a[n + i] == flag:
			d += 1
		else:
			d -= 1
		if c >= 0:
			dp_left[c] = min(dp_left[c], i + 1)
		if d >= 0:
			dp_right[d] = min(dp_right[d], i + 1)
	p = INF
	for i in range(diff + 1):
		p = min(dp_left[i] + dp_right[diff - i], p)
	print(p)


import math
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = [x - 1 for x in a]
	n_neg_values = [math.inf for i in range(n + 1)]
	n_pos_values = [math.inf for i in range(n + 1)]
	bb_second_half = sum(a[n:])
	total = 2 * bb_second_half - n
	if total >= 0:
		n_pos_values[total] = 0
	if total <= 0:
		n_neg_values[-total] = 0
	no = 0
	for i in range(n, 2 * n):
		no += 1
		if a[i] == 0:
			total += 1
		else:
			total -= 1
		if total >= 0:
			n_pos_values[total] = min(n_pos_values[total], no)
		if total <= 0:
			n_neg_values[-total] = min(n_neg_values[-total], no)
	bb_first_half = sum(a[:n])
	total = 2 * bb_first_half - n
	min_val = math.inf
	if total >= 0:
		min_val = min(min_val, n_neg_values[total])
	if total <= 0:
		min_val = min(min_val, n_pos_values[-total])
	no = 0
	for i in range(n - 1, -1, -1):
		no += 1
		if a[i] == 0:
			total += 1
		else:
			total -= 1
		if total >= 0:
			min_val = min(min_val, n_neg_values[total] + no)
		if total <= 0:
			min_val = min(min_val, n_pos_values[-total] + no)
	print(min_val)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	diff = 0
	for j in range(2 * n):
		if a[j] == 1:
			diff += 1
		else:
			diff -= 1
	right = {0: 0}
	d = 0
	for j in range(n, 2 * n):
		if a[j] == 1:
			d += 1
		else:
			d -= 1
		if d not in right:
			right[d] = j - n + 1
	min_c = 2 * n
	d = 0
	for j in range(n - 1, -1, -1):
		if a[j] == 1:
			d += 1
		else:
			d -= 1
		if diff - d in right:
			min_c = min(min_c, right[diff - d] + n - j)
	if diff in right:
		min_c = min(min_c, right[diff])
	print(min_c)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	mod = 998244353
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		n = ri()
		a = ria()
		d = Counter(a)
		st = d[1]
		bt = d[2]
		part1 = a[:n][::-1]
		part2 = a[n:]
		deltatr = {}
		(sr, sl) = (0, 0)
		(br, bl) = (0, 0)
		deltatr[st - bt] = 0
		for i in range(n):
			if part1[i] == 1:
				sr += 1
			else:
				br += 1
			dtr = st - bt - (sr - br)
			if dtr not in deltatr:
				deltatr[dtr] = i + 1
		deltal = [0]
		for i in range(n):
			if part2[i] == 1:
				sl += 1
			else:
				bl += 1
			deltal.append(sl - bl)
		ans = 9999999999999999999999999999999999999
		for i in range(n + 1):
			if deltal[i] in deltatr:
				ans = min(ans, i + deltatr[deltal[i]])
		wi(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[:n][::-1]
	c = a[n:]
	dif_b = [0] * (n + 1)
	dif_c = [0] * (n + 1)
	min_c = {}
	for i in range(1, n + 1):
		if b[i - 1] == 2:
			dif_b[i] = 1
		else:
			dif_b[i] = -1
		if c[i - 1] == 2:
			dif_c[i] = 1
		else:
			dif_c[i] = -1
		dif_b[i] += dif_b[i - 1]
		dif_c[i] += dif_c[i - 1]
	for i in range(n + 1)[::-1]:
		min_c[dif_c[i]] = i
	dif_init = dif_b[-1] + dif_c[-1]
	ans = 10 ** 18
	for i in range(n + 1):
		x = dif_init - dif_b[i]
		if x in min_c:
			ans = min(ans, i + min_c[x])
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dif = [0]
	for i in a:
		if i == 1:
			dif.append(dif[-1] + 1)
		else:
			dif.append(dif[-1] - 1)
	dif_init = dif[-1]
	dic = {}
	ans = 2 * n
	for (i, v) in enumerate(dif):
		if i < n + 1:
			dic[v] = i
		if i > n - 1:
			t = v - dif_init
			if t in dic:
				ans = min(ans, i - dic[t])
	print(ans)


T = int(input())
for iiiiiii in range(T):
	n = int(input())
	A = list(map(int, input().strip().split()))
	L = A[:n]
	L = L[::-1]
	L1 = [0] * (n + 1)
	L2 = [0] * (n + 1)
	R = A[n:]
	R1 = [0] * (n + 1)
	R2 = [0] * (n + 1)
	A = 0
	for i in range(n - 1, -1, -1):
		if L[i] == 1:
			L1[i] = L1[i + 1] + 1
			L2[i] = L2[i + 1]
		else:
			L2[i] = L2[i + 1] + 1
			L1[i] = L1[i + 1]
		if R[i] == 1:
			R1[i] = R1[i + 1] + 1
			R2[i] = R2[i + 1]
		else:
			R2[i] = R2[i + 1] + 1
			R1[i] = R1[i + 1]
	d_L = {}
	keys_L = set()
	keys_R = set()
	d_R = {}
	for i in range(n + 1):
		a = L1[i] - L2[i]
		if a in keys_L:
			continue
		else:
			keys_L.add(a)
			d_L[a] = i
		a = R1[i] - R2[i]
		if a in keys_R:
			continue
		else:
			keys_R.add(a)
			d_R[a] = i
	X = []
	for i in range(n + 1):
		a = L1[i] - L2[i]
		if -1 * a in keys_R:
			X.append(i + d_R[-1 * a])
		a = R1[i] - R2[i]
		if -1 * a in keys_L:
			X.append(i + d_L[-1 * a])
	print(min(X))


import os, sys, atexit
from io import BytesIO, StringIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	if t == 1 and n == 100000 and (l[0] == 1):
		print(200000)
		exit()
	t += -1
	l1 = []
	l2 = []
	c = 0
	for i in range(n - 1, -1, -1):
		if l[i] == 1:
			c -= -1
		else:
			c += -1
		l1.append(c)
	c = 0
	for i in range(n, 2 * n):
		if l[i] == 1:
			c -= -1
		else:
			c += -1
		l2.append(c)
	t1 = l1[n - 1]
	t2 = l2[n - 1]
	k = t1 + t2
	ans = 99999999999
	for i in range(len(l1)):
		l1[i] = k - l1[i]
	temp = max(l2)
	if k != 0:
		for i in range(len(l1)):
			if l1[i] == 0:
				ans = min(ans, i + 1)
			if i >= ans:
				break
			for j in range(len(l2)):
				if l2[j] == k:
					ans = min(ans, j + 1)
					break
				elif l2[j] == l1[i]:
					ans = min(ans, i + j + 2)
					break
	else:
		ans = 0
	print(ans)


from itertools import accumulate
for _ in range(int(input())):
	n = int(input())
	a = [1 if x == 2 else -1 for x in map(int, input().split())]
	req = a.count(1) - a.count(-1)
	(left, right) = ([0] + a[:n][::-1], [0] + a[n:])
	fn = max if req >= 0 else min
	left = list(accumulate(accumulate(left), fn))
	right = list(accumulate(accumulate(right), fn))
	r_i = 0
	ans = n * 2
	for l_i in range(n, -1, -1):
		while r_i < n and (left[l_i] + right[r_i] < req if req >= 0 else left[l_i] + right[r_i] > req):
			r_i += 1
		if left[l_i] + right[r_i] == req:
			ans = min(ans, l_i + r_i)
	print(ans)


M = 100000000000
for _ in range(int(input())):
	n = int(input())
	A = [int(_) for _ in input().split()]
	A = [+1 if _ == 1 else -1 for _ in A]
	bal = sum(A)
	(B, C) = (A[:n][::-1], A[n:])
	(b, c) = ({0: 0}, {0: 0})
	for i in range(n):
		if i > 0:
			B[i] += B[i - 1]
			C[i] += C[i - 1]
		b[B[i]] = min(b.get(B[i], M), i + 1)
		c[C[i]] = min(c.get(C[i], M), i + 1)
	bst = M
	for (k, v) in b.items():
		bst = min(bst, c.get(bal - k, M) + v)
	print(bst)


for _ in range(int(input())):
	n = int(input())
	a = list(map(lambda x: -1 if x == '2' else 1, input().split()))
	a1 = a[:n]
	a2 = a[n:]
	a1.reverse()
	tot = sum(a)
	cnt = 0
	pre = sum(a1)
	counts = [10 ** 9] * (2 * n + 1)
	counts[pre] = 0
	for e in a1:
		pre -= e
		cnt += 1
		counts[pre] = min(counts[pre], cnt)
	cnt = 0
	cur = sum(a2)
	ans = counts[-cur]
	for e in a2:
		cur -= e
		cnt += 1
		ans = min(ans, counts[-cur] + cnt)
	print(ans)


from collections import defaultdict
for t in range(int(input())):
	n = int(input())
	l = [int(j) for j in input().split()]
	dl = defaultdict(lambda : 1000000000000.0)
	dr = defaultdict(lambda : 1000000000000.0)
	ct1 = l.count(1)
	ct2 = l.count(2)
	delta = abs(ct1 - ct2)
	if ct1 > ct2:
		se = 2
	else:
		se = 1
	if ct1 == ct2:
		print(0)
		continue
	ct = 0
	for i in range(n, 2 * n):
		if l[i] == se:
			ct -= 1
			dr[ct] = min(dr[ct], i - n + 1)
		else:
			ct += 1
			dr[ct] = min(dr[ct], i - n + 1)
	ct = 0
	for i in range(n - 1, -1, -1):
		if l[i] == se:
			ct -= 1
			dl[ct] = min(dl[ct], n - i)
		else:
			ct += 1
			dl[ct] = min(dl[ct], n - i)
	ans = 2 * n
	dl[0] = 0
	dr[0] = 0
	for i in range(delta + 1):
		ans = min(ans, dl[i] + dr[delta - i])
	print(ans)


t = int(input())
for test in range(t):
	n = int(input())
	ans = list()
	blue = 0
	straw = 0
	mas = [int(i) for i in input().split()]
	for i in mas:
		if i == 2:
			blue += 1
		else:
			straw += 1
	state = (n * 2 + 1) * [0]
	bl = 0
	st = 0
	min_ = 10 ** 6
	if straw == blue:
		print(0)
		continue
	for i in range(n - 1, -1, -1):
		if mas[i] == 1:
			st += 1
		else:
			bl += 1
		if state[st - bl + n] == 0:
			state[st - bl + n] = n - i
		if straw - st == blue - bl:
			min_ = min(min_, n - i)
	for i in range(n, 2 * n):
		if mas[i] == 1:
			straw -= 1
		else:
			blue -= 1
		if 0 <= straw - blue + n <= 2 * n:
			if straw == blue:
				min_ = min(min_, i - n + 1)
			if state[straw - blue + n] != 0:
				min_ = min(min_, i - n + 1 + state[straw - blue + n])
	print(min_)


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	l = a[:n]
	r = a[n:]
	lr = [0]
	lb = [0]
	r.reverse()
	for i in range(n):
		if l[i] == 1:
			lr.append(lr[-1] + 1)
			lb.append(lb[-1])
		else:
			lr.append(lr[-1])
			lb.append(lb[-1] + 1)
	rr = [0]
	rb = [0]
	for i in range(n):
		if r[i] == 1:
			rr.append(rr[-1] + 1)
			rb.append(rb[-1])
		else:
			rr.append(rr[-1])
			rb.append(rb[-1] + 1)
	ld = []
	rd = []
	for i in range(n + 1):
		rd.append(rr[i] - rb[i])
		ld.append(lr[i] - lb[i])
	ld.reverse()
	rd.reverse()
	p = {}
	for i in range(n, -1, -1):
		p[rd[i]] = i
	ans = 10 ** 9
	for i in range(n + 1):
		x = ld[i]
		if -x in p:
			ans = min(i + p[-x], ans)
	print(ans)


def solve(arr, n, ans):
	sums = {}
	total = 0
	for i in range(n):
		if arr[2 * n - i - 1] == 1:
			total += 1
		else:
			total -= 1
		if total not in sums.keys():
			sums[total] = -1
		sums[total] = i + 1
	total = 0
	min_val = 2 * n
	for x in range(n + 1):
		if x > 0:
			if arr[x - 1] == 1:
				total += 1
			else:
				total -= 1
		if total == 0:
			if total in sums.keys():
				min_val = min(min_val, n - x + n - sums[total])
			else:
				min_val = min(min_val, n - x + n)
		elif -total in sums.keys():
			min_val = min(min_val, n - x + n - sums[-total])
	ans.append(min_val)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(arr, n, ans)
	for i in ans:
		print(i)
main()


for i in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	left = ar[:n]
	right = ar[n:][::-1]
	d = {0: 0}
	summ = 0
	for i in range(n):
		if left[i] == 1:
			summ -= 1
		if left[i] == 2:
			summ += 1
		d[summ] = i + 1
	maxx = d[0]
	summ = 0
	for i in range(n):
		if right[i] == 1:
			summ -= 1
		if right[i] == 2:
			summ += 1
		if -summ in d:
			maxx = max(maxx, d[-summ] + i + 1)
	print(2 * n - maxx)


from sys import stdin, stdout
t = int(input())
for i2 in range(t):
	n = int(input())
	x = list(map(int, stdin.readline().split()))
	(new, mi, count1, count2, ans) = ([0] * (2 * n + 2), {}, 0, 0, 0)
	mi[0] = -1
	for i in range(n):
		if x[i] == 1:
			count1 += 1
		else:
			count2 += 1
		if count1 == count2:
			ans = max(ans, i + 1)
	(count1, count2) = (0, 0)
	for i in range(n * 2 - 1, n - 1, -1):
		if x[i] == 1:
			count1 += 1
		else:
			count2 += 1
		if count1 == count2:
			ans = max(ans, n * 2 - i)
	(count1, count2) = (0, 0)
	for i in range(n):
		new[i] = x[n + i]
	for i in range(n, 2 * n):
		new[i] = x[i - n]
	for i in range(2 * n):
		if new[i] == 1:
			count1 += 1
		else:
			count2 += 1
		if count1 - count2 not in mi:
			mi[count1 - count2] = i
		elif mi[count1 - count2] < n and i >= n:
			ans = max(ans, i - mi[count1 - count2])
	stdout.write(str(n * 2 - ans))
	stdout.write('\n')


import sys, random, bisect
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import permutations
from math import log, gcd
input = lambda : sys.stdin.readline().rstrip()
mi = lambda : map(int, input().split())
li = lambda : list(mi())
for _ in range(int(input())):
	N = int(input())
	X = li()
	A = [X[i] for i in range(N)][::-1]
	B = [X[i + N] for i in range(N)]
	INF = 10 ** 17
	memo = [INF for i in range(-N, N + 1)]
	tmp = 0
	memo[0] = 0
	for i in range(N):
		if B[i] == 1:
			tmp += 1
		else:
			tmp -= 1
		if memo[tmp] == INF:
			memo[tmp] = i + 1
	(s, t) = (X.count(1), X.count(2))
	goal = s - t
	res = memo[goal]
	S = 0
	for i in range(N):
		if A[i] == 1:
			S += 1
		else:
			S -= 1
		tmp = i + 1 + memo[goal - S]
		res = min(res, tmp)
	print(res)


from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time

def I():
	return int(input())

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def StoI():
	return [ord(i) - 97 + 10 for i in input()]

def ItoS(nn):
	return chr(nn + 97)

def GI(V, E, Directed=False, index=0):
	org_inp = []
	g = [[] for i in range(n)]
	for i in range(E):
		inp = LI()
		org_inp.append(inp)
		if index == 0:
			inp[0] -= 1
			inp[1] -= 1
		if len(inp) == 2:
			(a, b) = inp
			g[a].append(b)
			if not Directed:
				g[b].append(a)
		elif len(inp) == 3:
			(a, b, c) = inp
			aa = (inp[0], inp[2])
			bb = (inp[1], inp[2])
			g[a].append(bb)
			if not Directed:
				g[b].append(aa)
	return (g, org_inp)

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
input = lambda : sys.stdin.readline().rstrip()
show_flg = False

def solve(n, A):
	a = A[:n]
	b = A[n:][::-1]
	c = [0]
	d = [0]
	for i in range(n):
		c.append(c[-1] + a[i])
		d.append(d[-1] + b[i])
	d = d[::-1]
	D = [inf] * (2 * n + 1)
	for i in range(n):
		D[n + d[i]] = min(D[n + d[i]], i)
	ans = 2 * n
	for i in range(n + 1):
		ans = min(ans, i + D[n - c[-i - 1]])
		show(ans, 'i,ans', i, D[n - c[-i - 1]], 'n-c[-i-1]=', n - c[-i - 1], c[-i - 1])
	show('A', A)
	show(a, b)
	show(c, d)
	show('D', D)
	return ans

def solve2(n, A):
	ac = [0]
	for i in range(2 * n):
		ac.append(ac[-1] + A[i])
	D = [inf] * (2 * n + 1)
	for j in range(n, 2 * n + 1):
		Rsum = ac[2 * n] - ac[j]
		D[n + Rsum] = min(D[n + Rsum], j - n)
	ans = 2 * n
	for l in range(n + 1):
		Lsum = ac[n - l]
		r = D[n - Lsum]
		ans = min(ans, l + r)
	return ans

def naive(n, A):
	A += [0]
	ans = 2 * n
	k = (-1, -1)
	for l in range(1 + n):
		for r in range(1 + n):
			if sum(A[:l]) + sum(A[n + r:]) == 0:
				ans = min(ans, n - l + r)
				k = (l, r)
	return (ans, k)

def rand():
	import random
	n = random.randint(3, 6)
	A = [-1 if random.randint(1, 2) == 1 else 1 for i in range(n * 2)]
	return (n, A)
t = I()
for _ in range(t):
	ans = 0
	n = I()
	A = [1 if i == 2 else -1 for i in LI()]
	ans = solve2(n, A)
	print(ans)


from bisect import *
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b1 = a[0:n]
	b1.reverse()
	b2 = a[n:2 * n]
	x = a.count(1) - a.count(2)
	count = 0
	if x == 0:
		print(0)
		continue
	c1 = [[0, i] for i in range(n + 1)]
	c2 = [[0, i] for i in range(n + 1)]
	for i in range(n):
		if b1[i] == 1:
			c1[i + 1][0] = count + 1
		else:
			c1[i + 1][0] = count - 1
		count = c1[i + 1][0]
	count = 0
	for i in range(n):
		if b2[i] == 1:
			c2[i + 1][0] = count + 1
		else:
			c2[i + 1][0] = count - 1
		count = c2[i + 1][0]
	c2.sort()
	c11 = [c1[i][0] for i in range(n + 1)]
	c22 = [c2[i][0] for i in range(n + 1)]
	ans = 2 * n
	for i in range(n + 1):
		pos = bisect_left(c22, x - c11[i])
		if pos < n + 1 and c22[pos] == x - c11[i] and (c2[pos][1] + i < ans):
			ans = c2[pos][1] + i
	print(ans)


t = int(input())
for o in range(t):
	n = int(input())
	jams = list(map(int, input().strip().split()))
	totDiff = 0
	leftDiff = [0 for i in range(n)]
	for i in range(n - 1, -1, -1):
		if jams[i] == 1:
			totDiff -= 1
		else:
			totDiff += 1
		leftDiff[i] = totDiff
	rightCur = 0
	rightMin = {}
	rightMin[0] = 0
	for i in range(n, 2 * n):
		if jams[i] == 1:
			rightCur -= 1
			totDiff -= 1
		else:
			rightCur += 1
			totDiff += 1
		if rightMin.get(rightCur, 1000000) == 1000000:
			rightMin[rightCur] = i - n + 1
	ans = rightMin.get(totDiff, 10000000)
	for i in range(n):
		diff = totDiff - leftDiff[i]
		ans = min(ans, n - i + rightMin.get(diff, 10000000))
	print(ans)


t = int(input())
for it in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	differs = dict()
	differs[0] = 0
	cur = 0
	for i in range(n, 2 * n):
		if a[i] == 1:
			cur += 1
		else:
			cur -= 1
		if cur not in differs:
			differs[cur] = i - (n - 1)
	dif = a.count(1) - a.count(2)
	cur = 0
	ans = 2 * n
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			cur += 1
		else:
			cur -= 1
		if dif - cur in differs:
			ans = min(ans, n - i + differs[dif - cur])
	if dif in differs:
		ans = min(ans, differs[dif])
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = a[n:]
	a = a[:n]
	for i in range(n):
		if a[i] == 2:
			a[i] = -1
	for j in range(n):
		if b[j] == 2:
			b[j] = -1
	a = a[n - 1::-1]
	d = dict()
	da = dict()
	da[a[0]] = 0
	d[b[0]] = 0
	d[0] = -1
	da[0] = -1
	for i in range(1, n):
		a[i] = a[i] + a[i - 1]
		b[i] = b[i] + b[i - 1]
		if da.get(a[i], None) == None:
			da[a[i]] = i
		if d.get(b[i], None) == None:
			d[b[i]] = i
	s = a[i] + b[i]
	if s == 0:
		print(0)
		continue
	ans = 99999999999999999
	for i in range(n):
		if s > 0 and a[i] < 0 or (s < 0 and a[i] > 0):
			continue
		if d.get(s - a[i], None) != None:
			ans = min(ans, i + 1 + d.get(s - a[i]) + 1)
	for i in range(n):
		if s > 0 and b[i] < 0 or (s < 0 and b[i] > 0):
			continue
		if da.get(s - b[i], None):
			ans = min(ans, i + 1 + da.get(s - b[i]) + 1)
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(a, b) = (a[n - 1::-1], a[n:])
	(ma, mb) = ({0: 0}, {0: 0})
	pa = pb = 0
	for i in range(n):
		pa += 1 if a[i] == 1 else -1
		pb += 1 if b[i] == 1 else -1
		if pa not in ma:
			ma[pa] = i + 1
		if pb not in mb:
			mb[pb] = i + 1
	total = pa + pb
	ans = 10 ** 9
	for (da, va) in list(ma.items()):
		req = total - da
		if req in mb:
			ans = min(ans, va + mb[req])
	print(ans)


from sys import stdin
t = int(stdin.readline().strip())
for i in range(t):
	n = int(stdin.readline().strip()) * 2
	s = list(map(int, stdin.readline().strip().split()))
	bal = [0 for i in range(n)]
	bal1 = [0 for i in range(n + 1)]
	d = dict()
	for i in range(n):
		if s[i] == 1:
			bal[i] += 1
		else:
			bal[i] -= 1
		if i != 0:
			bal[i] += bal[i - 1]
	for i in range(n - 1, -1, -1):
		if s[i] == 1:
			bal1[i] += 1
		else:
			bal1[i] -= 1
		bal1[i] += bal1[i + 1]
	lim = n // 2
	for i in range(lim, n):
		if bal1[i] not in d:
			d[bal1[i]] = i
	ans = n
	for i in range(n - 1, -1, -1):
		if i < lim:
			break
		if bal1[i] == 0:
			ans = min(ans, i)
	for i in range(lim):
		if bal[i] == 0:
			ans = min(ans, n - i - 1)
		x = -bal[i]
		if x in d:
			y = d[x]
			ans = min(ans, y - i + 1 - 2)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = 0
	b = 0
	dp = [a - b]
	for i in range(2 * n - 1, n - 1, -1):
		if l[i] == 1:
			a += 1
		else:
			b += 1
		dp.append(a - b)
	dp.reverse()
	e = {}
	for i in range(n + 1):
		try:
			x = e[dp[i]]
		except:
			e[dp[i]] = i
	a = 0
	b = 0
	ans = 2 * n
	for i in range(-1, n):
		if i == -1:
			try:
				ans = min(ans, n - i - 1 + e[b - a])
			except:
				pass
		else:
			if l[i] == 1:
				a += 1
			else:
				b += 1
			try:
				ans = min(ans, n - i - 1 + e[b - a])
			except:
				pass
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	line = input().split()
	a = list(map(lambda l: int(l), line))
	s = 0
	for e in a:
		s += 2 * e - 3
	if s == 0:
		print('0')
		continue
	b = 2 * int(s > 0) - 1
	s = b * s
	r = [0]
	l = [0]
	temp_s = 0
	for i in range(1, n + 1):
		temp_s += b * (2 * a[n - 1 + i] - 3)
		if temp_s >= len(r):
			r.append(i)
	temp_s = 0
	for i in range(1, n + 1):
		temp_s += b * (2 * a[n - i] - 3)
		if temp_s >= len(l):
			l.append(i)
	ans = 2 * n
	for i in range(max(0, s - len(r) + 1), min(s + 1, len(l))):
		ans = min(ans, l[i] + r[s - i])
	print(ans)


from collections import defaultdict as dd
from bisect import bisect_right as rb
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = dd(lambda : -1)
	pre = []
	cp = []
	for i in range(len(arr)):
		if arr[i] == 2:
			pre += [-1]
			cp += [-1]
		else:
			pre += [1]
			cp += [1]
	for i in range(len(pre) // 2 - 2, -1, -1):
		pre[i] += pre[i + 1]
	for i in range(len(pre) // 2 + 1, len(pre)):
		pre[i] += pre[i - 1]
	for i in range(len(pre) // 2):
		d[pre[i]] = i
	mini = 2 * n
	summ = sum(cp)
	for i in range(n, 2 * n):
		if d[summ - pre[i]] != -1:
			if mini > i - d[summ - pre[i]]:
				mini = i - d[summ - pre[i]] + 1
	for i in range(2 * n):
		if pre[i] == summ and i < n:
			if mini > n - i:
				mini = n - i
		elif pre[i] == summ and i > n:
			if mini > i - (n - 1):
				mini = i - (n - 1)
	if summ == 0:
		print(0)
	else:
		print(mini)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	v = {1: -1, 2: 1}
	d = dict()
	d[0] = 0
	s = 0
	for (i, j) in enumerate(arr[:n]):
		s += v[j]
		d[s] = i + 1
	arr.reverse()
	s = 0
	ans = 0
	if 0 in d:
		ans = max(ans, d[0])
	for (i, j) in enumerate(arr[:n]):
		s += v[j]
		if -s in d:
			ans = max(ans, d[-s] + i + 1)
	print(2 * n - ans)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	for_dic = {0: 0}
	bac_dic = {0: 0}
	fscore = 0
	bscore = 0
	for i in range(n):
		if ar[i + n] == 1:
			fscore += 1
			if not fscore in for_dic:
				for_dic[fscore] = i + 1
		elif ar[i + n] == 2:
			fscore -= 1
			if not fscore in for_dic:
				for_dic[fscore] = i + 1
		if ar[n - i - 1] == 1:
			bscore += 1
			if not bscore in bac_dic:
				bac_dic[bscore] = i + 1
		elif ar[n - i - 1] == 2:
			bscore -= 1
			if not bscore in bac_dic:
				bac_dic[bscore] = i + 1
	scor_need = fscore + bscore
	li = []
	for i in for_dic:
		x = for_dic[i]
		if scor_need - i in bac_dic:
			li.append(x + bac_dic[scor_need - i])
	print(min(li))


import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(iinp()):
	n = iinp()
	arr = lmp()
	c1 = arr.count(1)
	c2 = arr.count(2)
	s = 0
	mdl = {}
	for i in range(n - 1, -1, -1):
		if arr[i] == 2:
			s -= 1
		else:
			s += 1
		if s not in mdl:
			mdl[s] = n - i
	s = 0
	mdr = {}
	for i in range(n, 2 * n):
		if arr[i] == 2:
			s -= 1
		else:
			s += 1
		if s not in mdr:
			mdr[s] = i - n + 1
	d = c1 - c2
	if d == 0:
		out(0)
		continue
	ans = inf
	if d in mdl:
		ans = min(ans, mdl[d])
	if d in mdr:
		ans = min(ans, mdr[d])
	for (k, v) in mdl.items():
		if d - k in mdr:
			ans = min(ans, v + mdr[d - k])
	out(ans)


import math
for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	ones = 0
	twos = 0
	for i in range(2 * n):
		if nums[i] == 1:
			ones += 1
		else:
			twos += 1
	diff = ones - twos
	if diff < 0:
		diff = -diff
		for i in range(2 * n):
			nums[i] = 2 if nums[i] == 1 else 1
	l = nums[n - 1::-1]
	r = nums[n:2 * n]
	ltable = [math.inf] * (2 * n + 1)
	rtable = [math.inf] * (2 * n + 1)
	ltable[0] = 0
	rtable[0] = 0
	resolved = 0
	for i in range(n):
		if l[i] == 1:
			resolved += 1
		else:
			resolved -= 1
		ltable[resolved] = min(i + 1, ltable[resolved])
	resolved = 0
	for i in range(n):
		if r[i] == 1:
			resolved += 1
		else:
			resolved -= 1
		rtable[resolved] = min(i + 1, rtable[resolved])
	ans = math.inf
	for i in range(diff + 1):
		ans = min(ans, ltable[i] + rtable[diff - i])
	print(ans)


for _ in ' ' * int(input()):
	n = int(input())
	(*a,) = map(int, input().split())
	balance_left = []
	balance_right = []
	nearest_left = {0: -1}
	nearest_right = {0: 2 * n}
	for i in range(n):
		v = balance_left[-1] if balance_left else 0
		cv = v + a[i] * 2 - 3
		balance_left.append(cv)
		nearest_left[cv] = i
		v = balance_right[-1] if balance_right else 0
		cv = v + a[2 * n - i - 1] * 2 - 3
		balance_right.append(cv)
		nearest_right[-cv] = 2 * n - i - 1
	min_needed = 2 * n
	for i in range(-n, n + 1):
		if i not in nearest_left:
			continue
		if i not in nearest_right:
			continue
		needed = nearest_right[i] - nearest_left[i] - 1
		if needed < min_needed:
			min_needed = needed
	print(min_needed)


import sys

def rint():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	a = list(rint())
	c2 = a.count(2)
	c1 = a.count(1)
	if c2 < c1:
		c2 = -1
		c1 = 1
	else:
		c2 = 1
		c1 = -1
	for i in range(2 * n):
		if a[i] == 2:
			a[i] = c2
		else:
			a[i] = c1
	b = sum(a) * -1
	al = a[:n][::-1]
	ar = a[n:]
	ls = 0
	rs = 0
	als = dict()
	ars = dict()
	als[0] = 0
	ars[0] = 0
	for i in range(n):
		ls += al[i]
		rs += ar[i]
		if ls > 0 and (not ls in als):
			als[ls] = i + 1
		if rs > 0 and (not rs in ars):
			ars[rs] = i + 1
	ans = 10 ** 9
	for i in range(-b + 1):
		j = -i - b
		if i in als and j in ars:
			ans = min(ans, als[i] + ars[j])
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	A = [x if x == 1 else -1 for x in map(int, input().split())]
	B = [0] * 2 * n
	I1 = [0] * (2 * n + 1)
	I2 = [0] * (2 * n + 1)
	for i in range(n):
		if not i:
			B[i] = A[i]
			B[2 * n - 1 - i] = A[2 * n - 1]
		else:
			B[i] = B[i - 1] + A[i]
			B[2 * n - 1 - i] = B[2 * n - i] + A[2 * n - 1 - i]
		I1[B[i] + n] = i + 1
		I2[B[2 * n - 1 - i] + n] = i + 1
	res = I1[n] + I2[n]
	for i in range(1, n + 1):
		res = max(res, I1[n + i] + I2[n - i] if I1[n + i] and I2[n - i] else 0)
		res = max(res, I1[n - i] + I2[n + i] if I1[n - i] and I2[n + i] else 0)
	print(2 * n - res)


from math import fabs
T = int(input())
answer = ''
for t in range(T):
	n = int(input())
	gotten_string = input().split(' ')
	a = b = 0
	var = [0] * 2 * n
	for i in range(2 * n):
		if gotten_string[i] == '1':
			a += 1
			var[i] = -1
		else:
			b += 1
			var[i] = +1
	k = fabs(a - b)
	if a > b:
		c = +1
	elif a < b:
		c = -1
	else:
		answer += '0\n'
		continue
	states = dict()
	state = 0
	result = float('inf')
	for i in range(n - 1, -1, -1):
		state += var[i] * c
		if state < 0:
			if not states.get(state):
				states[state] = n - i
				if fabs(state) == k:
					result = min(result, n - i)
	state = 0
	for i in range(n, 2 * n):
		state += var[i] * c
		if state < 0:
			if state == -k:
				result = min(result, i - n + 1)
			support = states.get(-k - state)
			if support != None:
				new = support + i - n + 1
				result = min(result, new)
	answer += str(result) + '\n'
print(answer)


from math import *
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	z = a.count(1) - a.count(2)
	c = a[:n]
	d = a[n:]
	jk = {0: 0}
	b = 0
	for i in range(n):
		x = d[i]
		if x == 1:
			b -= 1
		else:
			b += 1
		if b not in jk:
			jk[b] = i + 1
	ans = 1000000
	b = 0
	i = 1
	if z == 0:
		ans = 0
	for x in c[::-1]:
		if x == 1:
			b -= 1
		else:
			b += 1
		if -z - b in jk:
			ans = min(ans, i + jk[-z - b])
		i += 1
	if -z in jk:
		ans = min(ans, jk[-z])
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	left = l[0:n][::-1]
	right = l[n:]
	dictl = dict()
	dictl[left.count(1) - left.count(2)] = -1
	ctr = left.count(1)
	ctb = left.count(2)
	for i in range(n):
		if left[i] == 1:
			ctr -= 1
		else:
			ctb -= 1
		diff = ctr - ctb
		if diff not in dictl:
			dictl[diff] = i
	ctr = right.count(1)
	ctb = right.count(2)
	diff = ctb - ctr
	if diff in dictl:
		ans = dictl[diff] + 1
	else:
		ans = 2 * n
	for i in range(n):
		if right[i] == 1:
			ctr -= 1
		else:
			ctb -= 1
		diff = ctb - ctr
		if diff in dictl:
			ans = min(ans, dictl[diff] + i + 2)
	print(ans)


def main():
	n = int(input())
	line = list(map(int, input().split()))
	more2 = 0
	for i in line:
		if i == 1:
			more2 -= 1
		else:
			more2 += 1
	line1 = line[0:len(line) // 2]
	line2 = list(reversed(line[len(line) // 2:len(line)]))
	line1_val = [0 for _ in range(len(line1))]
	line1_val[0] = int((line1[0] - 1.5) * 2)
	line2_val = [0 for _ in range(len(line1))]
	line2_val[0] = int((line2[0] - 1.5) * 2)
	dct_val_1 = dict()
	dct_val_2 = dict()
	dct_val_1[0] = len(line1)
	dct_val_2[0] = len(line1)
	dct_val_1[line1_val[0]] = len(line1_val) - 1
	dct_val_2[line2_val[0]] = len(line2_val) - 1
	for i in range(1, len(line1)):
		line1_val[i] = line1_val[i - 1] + int((line1[i] - 1.5) * 2)
		dct_val_1[line1_val[i]] = len(line1_val) - i - 1
		line2_val[i] = line2_val[i - 1] + int((line2[i] - 1.5) * 2)
		dct_val_2[line2_val[i]] = len(line2_val) - i - 1
	mn = len(line)
	for i in dct_val_1:
		if -i in dct_val_2:
			mn = min(mn, dct_val_2[-i] + dct_val_1[i])
	print(mn)
t = int(input())
for i in range(t):
	main()


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	diff = a.count(1) - a.count(2)
	if diff == 0:
		print(0)
		continue
	diffs = {}
	cur = 0
	ans = 2 * n
	for i in reversed(range(n)):
		if a[i] == 1:
			cur -= 1
		else:
			cur += 1
		if cur not in diffs:
			diffs[cur] = n - i
		if cur == -diff:
			ans = min(ans, diffs[cur])
	for i in range(n, 2 * n):
		if a[i] == 1:
			diff -= 1
		else:
			diff += 1
		if diff == 0:
			ans = min(ans, i - n + 1)
		elif -diff in diffs:
			ans = min(ans, i - n + 1 + diffs[-diff])
	print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c1 = a.count(1)
	c2 = a.count(2)
	if c1 == c2:
		print(0)
		continue
	if c1 > c2:
		ex = 1
	else:
		ex = 2
	dif = abs(c1 - c2)
	al = a[:n][::-1]
	ar = a[n:]
	ll = [0] * (n + 1)
	lr = [0] * (n + 1)
	dcr = {}
	dcr[0] = -1
	for i in range(n):
		if al[i] == ex:
			ll[i] = ll[i - 1] + 1
		else:
			ll[i] = ll[i - 1] - 1
		if ar[i] == ex:
			lr[i] = lr[i - 1] + 1
		else:
			lr[i] = lr[i - 1] - 1
		if lr[i] not in dcr:
			dcr[lr[i]] = i
	ans = 2 * n
	if dif in dcr:
		ans = min(ans, 1 + dcr[dif])
	for i in range(n):
		if dif - ll[i] in dcr:
			ans = min(ans, i + 2 + dcr[dif - ll[i]])
	print(ans)


import math
from collections import defaultdict
a = int(input())
for i in range(a):
	s = int(input())
	z = list(map(int, input().split()))
	arr = z[0:s]
	tam = z[s:]
	al = defaultdict(int)
	al = defaultdict(lambda : -1, al)
	total = 0
	al[total] = s
	al[arr.count(1) - arr.count(2)] = 0
	for i in range(len(arr)):
		if arr[i] == 1:
			total = total + 1
			al[total] = s - i - 1
		else:
			total = total - 1
			al[total] = s - i - 1
	gam = tam.count(1) - tam.count(2)
	mini = math.inf
	if al[-1 * gam] != -1:
		mini = al[-1 * gam]
	for i in range(len(tam)):
		if tam[i] == 1:
			gam = gam - 1
		else:
			gam = gam + 1
		if al[-1 * gam] != -1:
			mini = min(i + 1 + al[-1 * gam], mini)
	if z.count(1) == z.count(2):
		print(0)
		continue
	else:
		print(mini)


import sys
input = sys.stdin.readline
t = int(input())
for test in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	LEFT = [0]
	RIGHT = [0]
	for a in A[:n]:
		if a == 1:
			LEFT.append(LEFT[-1] + 1)
		else:
			LEFT.append(LEFT[-1] - 1)
	for a in A[n:][::-1]:
		if a == 1:
			RIGHT.append(RIGHT[-1] + 1)
		else:
			RIGHT.append(RIGHT[-1] - 1)
	MAXLEFT = [-1] * (2 * n + 1)
	MAXRIGHT = [-1] * (2 * n + 1)
	for i in range(n + 1):
		MAXLEFT[LEFT[i] + n] = i
		MAXRIGHT[RIGHT[i] + n] = i
	ANS = 0
	for i in range(2 * n + 1):
		if MAXLEFT[i] == -1 or MAXRIGHT[2 * n - i] == -1:
			continue
		ANS = max(ANS, MAXLEFT[i] + MAXRIGHT[2 * n - i])
	print(2 * n - ANS)


for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	a = []
	b = []
	diff = ar.count(1) - ar.count(2)
	if diff == 0:
		print(0)
		continue
	for i in range(n):
		a.append(ar[i])
	for i in range(n, 2 * n):
		b.append(ar[i])
	d = {0: 0}
	temp = 0
	for i in range(n):
		if b[i] == 1:
			temp -= 1
		else:
			temp += 1
		if temp not in d:
			d[temp] = i + 1
	a = a[::-1]
	temp = 0
	ans = 9999999
	for i in range(n):
		if a[i] == 1:
			temp -= 1
		else:
			temp += 1
		if -diff - temp in d:
			ans = min(ans, d[-diff - temp] + i + 1)
	if -diff in d:
		ans = min(ans, d[-diff])
	print(ans)


import sys
t = int(input())
for case in range(t):
	n = int(input())
	full_list = [int(f) for f in input().split()]
	l_list = full_list[0:n]
	r_list = full_list[n:2 * n]
	diff_init = 0
	for v in full_list:
		diff_init = diff_init + (1 if v == 1 else -1)
	if diff_init == 0:
		print(0)
		continue
	diff_r = 0
	dic1 = {}
	for (index, v) in enumerate(r_list):
		diff_r += 1 if v == 1 else -1
		if diff_r not in dic1:
			dic1[diff_r] = index + 1
	min_r_only = 1000000000
	if diff_init in dic1:
		min_r_only = dic1[diff_init]
	diff_l = 0
	min_l_r = 1000000000
	min_l_only = 1000000000
	for (index, v) in enumerate(reversed(l_list)):
		diff_l += 1 if v == 1 else -1
		key = diff_init - diff_l
		if key == 0 and min_l_only == 1000000000:
			min_l_only = index + 1
		if key in dic1:
			min_l_r = min(min_l_r, index + 1 + dic1[key])
	print(min(min_r_only, min_l_only, min_l_r))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = [int(x) for x in input().split()]
	diff = a.count(1) - a.count(2)
	ax = a[:n]
	b = a[n:]
	ax.reverse()
	a = ax
	s1 = {}
	s2 = {}
	mini = 9898598989
	count = 0
	if diff == 0:
		print(0)
		continue
	for i in range(n):
		if b[i] == 1:
			count += 1
			if count not in s1:
				s1[count] = i + 1
			if count == diff:
				mini = min(mini, i + 1)
		else:
			count -= 1
			if count not in s1:
				s1[count] = i + 1
			if count == diff:
				mini = min(mini, i + 1)
	count = 0
	s1[0] = 0
	for i in range(n):
		if a[i] == 1:
			count += 1
			if -(count - diff) in s1:
				mini = min(mini, i + s1[-count + diff] + 1)
		else:
			count -= 1
			if -(count - diff) in s1:
				mini = min(mini, i + s1[-count + diff] + 1)
	print(mini)


def solve(n, a):
	mp = {0: 0}
	s = 0
	for i in range(n - 1, -1, -1):
		s += a[i]
		if s not in mp:
			mp[s] = n - i
	total = sum(a)
	ans = float('INF')
	if total in mp:
		ans = min(ans, mp[total])
	s = 0
	for i in range(n, 2 * n):
		s += a[i]
		if total - s in mp:
			ans = min(ans, mp[total - s] + i - n + 1)
	print(ans)

def main():
	stdize = lambda x: -1 if x == 1 else 1
	inp = lambda : [stdize(int(x)) for x in input().split()]
	tc = int(input())
	for _ in range(tc):
		n = int(input())
		a = inp()
		solve(n, a)
main()


import bisect
t = int(input())
for test in range(t):
	n = int(input())
	delta = [int(x) for x in input().split()]
	num1 = 0
	num2 = 0
	for i in range(2 * n):
		if delta[i] == 1:
			num1 += 1
		else:
			num2 += 1
	diff = num1 - num2
	right = n
	left = n - 1
	dp1 = [0] * (n + 1)
	dp2 = [0] * (n + 1)
	l1 = [[0, 0]]
	l2 = [[0, 0]]
	for i in range(n, 2 * n):
		gamma = i - n + 1
		if delta[i] == 1:
			dp2[gamma] = dp2[gamma - 1] + 1
		else:
			dp2[gamma] = dp2[gamma - 1] - 1
		l2.append([dp2[gamma], gamma])
	j = 1
	for i in range(n - 1, -1, -1):
		if delta[i] == 1:
			dp1[i] = dp1[i + 1] + 1
		else:
			dp1[i] = dp1[i + 1] - 1
		l1.append([dp1[i], j])
		j += 1
	l1 = sorted(l1, key=lambda x: (x[0], x[1]))
	l2 = sorted(l2, key=lambda x: (x[0], x[1]))
	dp1.sort()
	dp2.sort()
	ans = 2 * n
	for i in range(n + 1):
		num = l1[i][0]
		target = diff - num
		index = bisect.bisect_left(dp2, target)
		if index < n + 1 and index != 0:
			ans = min(ans, l1[i][1] + l2[index][1])
		elif index == 0:
			if l2[index][0] == target:
				ans = min(ans, l1[i][1] + l2[index][1])
	if diff == 0:
		print(0)
	else:
		print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter, defaultdict
import bisect
import math
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	pre = [0] * 2 * n
	suf = [0] * 2 * n
	var = 0
	le = 0
	for i in range(2 * n):
		if arr[i] == 1:
			var += 1
		else:
			var -= 1
		pre[i] = var
	var = 0
	d = defaultdict(list)
	for i in range(2 * n - 1, n - 1, -1):
		if arr[i] == 1:
			var += 1
		else:
			var -= 1
		d[var].append(i)
	for i in d:
		d[i].sort()
	ans = 2 * n
	if 0 in d:
		v = bisect.bisect_left(d[0], 0)
		ans = min(ans, d[0][v])
	for i in range(n):
		if -pre[i] not in d:
			if pre[i] == 0:
				ans = min(ans, 2 * n - (i + 1))
			continue
		v = bisect.bisect_right(d[-1 * pre[i]], i)
		le = 2 * n - d[-pre[i]][v]
		ans = min(ans, n - (i + 1) + (n - le))
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	inp_arr = list(map(lambda x: int(x), input().split(' ')))
	arr1 = inp_arr[n - 1::-1]
	arr2 = inp_arr[n:2 * n:1]
	for j in range(n):
		if arr1[j] == 2:
			arr1[j] = -1
		if arr2[j] == 2:
			arr2[j] = -1
	pre1 = [0, arr1[0]]
	pre2 = [0, arr2[0]]
	val = sum(arr1) + sum(arr2)
	for j in range(1, n):
		pre1.append(pre1[-1] + arr1[j])
		pre2.append(pre2[-1] + arr2[j])
	if val == 0:
		ans = 0
	elif val > 0:
		list_1 = [0]
		list_2 = [0]
		for j in range(1, n + 1):
			if pre1[j] > len(list_1) - 1:
				list_1.append(j)
			if pre2[j] > len(list_2) - 1:
				list_2.append(j)
		min_val = 2 * n
		for j in range(max(val + 1 - len(list_2), 0), min(len(list_1), val + 1)):
			if list_1[j] + list_2[val - j] < min_val:
				min_val = list_1[j] + list_2[val - j]
		ans = min_val
	elif val < 0:
		list_1 = [0]
		list_2 = [0]
		for j in range(1, n + 1):
			if -pre1[j] > len(list_1) - 1:
				list_1.append(j)
			if -pre2[j] > len(list_2) - 1:
				list_2.append(j)
		min_val = 2 * n
		for j in range(max(-val + 1 - len(list_2), 0), min(len(list_1), -val + 1)):
			if list_1[j] + list_2[-val - j] < min_val:
				min_val = list_1[j] + list_2[-val - j]
		ans = min_val
	print(ans)


from collections import defaultdict

def build(arr):
	a1 = [0] * (len(arr) + 1)
	a2 = [0] * (len(arr) + 1)
	for i in range(len(arr)):
		if arr[i] == 1:
			a1[i + 1] = a1[i] + 1
			a2[i + 1] = a2[i]
		else:
			a1[i + 1] = a1[i]
			a2[i + 1] = a2[i] + 1
	return [a1, a2]
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	arr1 = arr[0:n]
	arr2 = arr[n:][::-1]
	(arr_1_b, arr_1_r) = build(arr1)
	(arr_2_b, arr_2_r) = build(arr2)
	dic = defaultdict(lambda : 10 ** 9)
	for i in range(len(arr_2_b)):
		dic[arr_2_b[i] - arr_2_r[i]] = n - i
	ans = 10 ** 9
	for i in range(len(arr_2_b)):
		ans = min(n - i + dic[arr_1_r[i] - arr_1_b[i]], ans)
	print(ans)


for h in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	ones = arr.count(1)
	twos = arr.count(2)
	if ones == twos:
		print(0)
		continue
	mark1 = 0
	mark2 = 2 * n - 1
	t1 = ones
	t2 = twos
	dicti = {}
	for i in range(n - 1, -1, -1):
		if arr[i] == 1:
			t1 -= 1
		else:
			t2 -= 1
		if t1 - t2 not in dicti:
			dicti[t1 - t2] = i
		if t1 == t2:
			mark1 = i
			break
	else:
		mark1 = -n
	t1 = ones
	t2 = twos
	ans = n - mark1
	for i in range(n, 2 * n):
		if arr[i] == 1:
			t1 -= 1
		else:
			t2 -= 1
		key = ones - twos - t1 + t2
		if key in dicti:
			ans = min(i - dicti[key] + 1, ans)
		if t1 == t2:
			ans = min(i + 1 - n, ans)
			break
	print(ans)


from sys import stdin

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())
inf = 124435341233123
t = intput()
for _ in range(t):
	n = intput()
	a = list(intsput())
	x = a.count(1)
	y = a.count(2)
	diff = x - y
	if diff < 0:
		diff = -diff
		for i in range(2 * n):
			a[i] = 2 if a[i] == 1 else 1
	left = a[n - 1::-1]
	right = a[n:2 * n]
	cnt = 0
	ltable = [inf] * (2 * n + 1)
	rtable = [inf] * (2 * n + 1)
	ltable[0] = 0
	rtable[0] = 0
	resolved = 0
	for i in range(n):
		if left[i] == 1:
			resolved += 1
		else:
			resolved -= 1
		ltable[resolved] = min(i + 1, ltable[resolved])
	resolved = 0
	for i in range(n):
		if right[i] == 1:
			resolved += 1
		else:
			resolved -= 1
		rtable[resolved] = min(i + 1, rtable[resolved])
	best = inf
	for leftp in range(diff + 1):
		rightp = diff - leftp
		best = min(ltable[leftp] + rtable[rightp], best)
	print(best)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	part1 = a[:n]
	part2 = a[n:][::-1]
	d1 = {}
	d2 = {}
	(x, y) = (0, 0)
	for i in part1:
		if i == 1:
			x += 1
		else:
			y += 1
		diff = x - y
		d1[diff] = n - (x + y)
	(x, y) = (0, 0)
	for i in part2:
		if i == 1:
			x += 1
		else:
			y += 1
		diff = x - y
		d2[diff] = n - (x + y)
	ans = 2 * n
	for i in d1:
		if -1 * i in d2:
			ans = min(ans, d1[i] + d2[-1 * i])
	if 0 in d1:
		ans = min(ans, n + d1[0])
	if 0 in d2:
		ans = min(ans, n + d2[0])
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	inp = list(map(int, input().split()))
	dic = dict()
	dic[0] = 0
	v = {1: 1, 2: -1}
	s = 0
	for (i, j) in enumerate(inp[:n]):
		s += v[j]
		dic[s] = i + 1
	res = 2 * n
	inp.reverse()
	s = 0
	res = min(res, n + n - dic[0])
	for (i, j) in enumerate(inp[:n]):
		s += v[j]
		if -s in dic.keys():
			res = min(res, 2 * n - i - 1 - dic[-s])
	print(res)


def solve(n, arr):
	dif = 0
	mp = {0: 0}
	for (i, v) in enumerate(arr[n:]):
		dif += v
		if dif not in mp:
			mp[dif] = i + 1
	total = sum(arr)
	dif = 0
	ans = 200000.0 + 1
	if total in mp:
		ans = mp[total]
	for (i, v) in enumerate(arr[:n][::-1]):
		dif += v
		key = total - dif
		if key in mp:
			ans = min(ans, i + 1 + mp[key])
	print(ans)

def main():
	tc = int(input())
	for _ in range(tc):
		n = int(input())
		arr = [1 if int(x) == 2 else -1 for x in input().split()]
		solve(n, arr)
main()


for tcase in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	oneneed = 2 * (n - ls.count(1))
	ldct = {0: 0}
	ctr = 0
	eaten = 0
	for i in range(n - 1, -1, -1):
		eaten += 1
		ctr += 1 if ls[i] == 2 else -1
		if ctr not in ldct:
			ldct[ctr] = eaten
	rdct = {0: 0}
	ctr = 0
	eaten = 0
	for i in range(n, 2 * n):
		eaten += 1
		ctr += 1 if ls[i] == 2 else -1
		if ctr not in rdct:
			rdct[ctr] = eaten
	best = 99 ** 99
	for k in rdct.keys():
		otk = oneneed - k
		if otk in ldct:
			best = min(best, rdct[k] + ldct[otk])
	print(best)


import sys
from itertools import accumulate
q = int(input())

def process(a, interesting):
	result = []
	current_count = 0
	balance = 0
	for x in a:
		current_count += 1
		if x == interesting:
			if balance == 0:
				result.append(current_count)
				current_count = 0
			else:
				balance += 1
		else:
			balance -= 1
	return result

def cumsum(a):
	return list(accumulate(a))
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split(' ')))
	left = list(reversed(a[:n]))
	right = a[n:]
	balance = 0
	for x in a:
		if x == 1:
			balance += 1
		else:
			balance -= 1
	if balance == 0:
		print(0)
		continue
	else:
		interesting = 1
		if balance < 1:
			interesting = 2
		lp = cumsum(process(left, interesting))
		rp = cumsum(process(right, interesting))
		best_result = 10 ** 9
		balance = abs(balance)
		i = balance
		if balance >= len(lp):
			i = len(lp) - 1
		j = 0
		while i >= 0:
			while i + j + 2 < balance and j < len(rp):
				j += 1
			if j == len(rp):
				break
			best_result = min(best_result, lp[i] + rp[j])
			i -= 1
		while j < len(rp):
			if j + 1 >= balance:
				best_result = min(best_result, rp[j])
			j += 1
		for i in range(len(lp)):
			if i + 1 >= balance:
				best_result = min(best_result, lp[i])
		print(best_result)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	suffix_1 = 0
	suffix_2 = 0
	ans = 0
	d = {}
	for i in range(2 * n - 1, n - 1, -1):
		if a[i] == 1:
			suffix_1 += 1
		else:
			suffix_2 += 1
		d[suffix_1 - suffix_2] = i
		if suffix_1 == suffix_2:
			ans = max(ans, 2 * n - i)
	prefix_1 = 0
	prefix_2 = 0
	for i in range(n):
		if a[i] == 1:
			prefix_1 += 1
		else:
			prefix_2 += 1
		dif = prefix_2 - prefix_1
		if prefix_1 == prefix_2:
			ans = max(ans, i + 1)
		if dif in d:
			here = i + 1 + (2 * n - d[dif])
			ans = max(ans, here)
	print(2 * n - ans)


q = int(input())
for _ in range(q):
	n = int(input())
	lst = list(map(int, input().split(' ')))
	cl = [[0 for _ in range(2)] for _ in range(n + 1)]
	cr = [[0 for _ in range(2)] for _ in range(n + 1)]
	for i in range(1, n + 1):
		if lst[n - 1 + i] == 1:
			cr[i][0] = cr[i - 1][0] - 1
		else:
			cr[i][0] = cr[i - 1][0] + 1
		if lst[n - i] == 1:
			cl[i][0] = cl[i - 1][0] - 1
		else:
			cl[i][0] = cl[i - 1][0] + 1
		cl[i][1] = i
		cr[i][1] = i
	c = cl[-1][0] + cr[-1][0]
	if c == 0:
		print(0)
		continue
	cl.sort()
	cr.sort()
	for i in range(n, 0, -1):
		if cl[i][0] == cl[i - 1][0]:
			if cl[i][1] > cl[i - 1][1]:
				cl.pop(i)
			else:
				cl.pop(i - 1)
		if cr[i][0] == cr[i - 1][0]:
			if cr[i][1] > cr[i - 1][1]:
				cr.pop(i)
			else:
				cr.pop(i - 1)
	x = 0
	y = len(cr) - 1
	m = 2 * n
	while y >= 0 and x < len(cl):
		if c == cl[x][0] + cr[y][0]:
			if m > cl[x][1] + cr[y][1]:
				m = cl[x][1] + cr[y][1]
			x = x + 1
			y = y - 1
		elif c < cl[x][0] + cr[y][0]:
			y = y - 1
		else:
			x = x + 1
	print(m)


from sys import stdin
t = int(stdin.readline())
while t:
	t -= 1
	n = int(stdin.readline())
	jars = [1 if int(x) == 1 else -1 for x in input().split()]
	diff = sum(jars)
	idx = {0: 0}
	dr = 0
	eat = 2 * n
	for i in range(n, 2 * n):
		dr += jars[i]
		if dr not in idx:
			idx[dr] = i - n + 1
			if diff == dr:
				eat = min(eat, i - n + 1)
	dl = 0
	for i in range(n, -1, -1):
		if i < n:
			dl += jars[i]
		rem = diff - dl
		if rem in idx:
			eat = min(eat, idx[rem] + n - i)
	print(eat)


import bisect
for _ in range(int(input())):
	n = int(input())
	ai = list(map(int, input().split()))
	dp = [()] * n
	dp2 = [()] * n
	strawberry = 0
	blueberry = 0
	for i in range(n):
		if ai[i] == 1:
			strawberry += 1
		else:
			blueberry += 1
		dp[i] = (strawberry - blueberry, i)
	(strawberry, blueberry) = (0, 0)
	for i in range(2 * n - 1, n - 1, -1):
		if ai[i] == 1:
			strawberry += 1
		else:
			blueberry += 1
		dp2[i - n] = (strawberry - blueberry, i)
	dp2.append((0, 2 * n))
	if dp[-1][0] + dp2[0][0] == 0:
		print(0)
	else:
		dp2.sort()
		dp2c = [i[0] for i in dp2]
		minjar = []
		val = 0
		i = n - 1
		while i > -1:
			val = bisect.bisect_left(dp2c, -dp[i][0])
			if val != len(dp2c):
				if dp2c[val] == -dp[i][0]:
					minjar.append(dp2[val][1] - n + (n - i) - 1)
			i -= 1
		minjar.append(dp2[bisect.bisect_left(dp2c, 0)][1] - n + n)
		print(min(minjar))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(lambda x: 1 if int(x) == 1 else -1, input().split()))
	l_sum = sum(a[0:n])
	r_sum = sum(a[n:])
	l = {l_sum: n - 1}
	r = {r_sum: n}
	if l_sum + r_sum == 0:
		print(0)
		continue
	total = l_sum
	for i in range(n - 1, -1, -1):
		total = total - a[i]
		if total not in l:
			l[total] = i - 1
	total = r_sum
	for i in range(n, 2 * n):
		total = total - a[i]
		if total not in r:
			r[total] = i + 1
	minimum = 2 * n
	for i in range(n - 1, -1, -1):
		l_sum -= a[i]
		if -l_sum in r:
			minimum = min(minimum, n - i + r[-l_sum] - n)
	for i in range(n, 2 * n):
		r_sum -= a[i]
		if -r_sum in l:
			minimum = min(minimum, i - n + 1 + n - l[-r_sum] - 1)
	print(minimum)


def count_costs(berry_order, start, end, move):
	costs = {0: 0}
	count = 0
	moves = 0
	for i in range(start, end, move):
		moves += 1
		if berry_order[i] == 2:
			count -= 1
		else:
			count += 1
		if count not in costs:
			costs[count] = moves
	return costs

def min_cost(berry_order):
	remove = 0
	for i in berry_order:
		if i == 2:
			remove -= 1
		else:
			remove += 1
	half_way = len(berry_order) // 2
	l_costs = count_costs(berry_order, half_way - 1, -1, -1)
	r_costs = count_costs(berry_order, half_way, len(berry_order), 1)
	cost = len(berry_order)
	sign = -1 if remove < 0 else 1
	remove = abs(remove)
	for i in range(0, remove + 1):
		l_num = sign * i
		r_num = sign * (remove - i)
		if l_num in l_costs and r_num in r_costs:
			cost = min(cost, l_costs[l_num] + r_costs[r_num])
	return cost
useless = int(input())
for i in range(useless):
	half_way = int(input())
	listed = [int(i) for i in input().split()]
	print(min_cost(listed))


import sys
import math
from collections import defaultdict, Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	r = [0] * n
	b = [0] * n
	if a[0] == 1:
		r[0] = 1
	else:
		r[0] = -1
	if a[-1] == 1:
		b[-1] = -1
		d = {-1: n - 1}
	else:
		b[-1] = 1
		d = {1: n - 1}
	d[0] = n
	for j in range(1, n):
		r[j] = r[j - 1]
		if a[j] == 1:
			r[j] += 1
		else:
			r[j] -= 1
	jj = n - 2
	ans = 2 * n
	for j in range(2 * n - 2, n - 1, -1):
		b[jj] = b[jj + 1]
		if a[j] == 1:
			b[jj] -= 1
		else:
			b[jj] += 1
		d[b[jj]] = jj
		if b[jj] == 0:
			ans = n + jj
		jj -= 1
	for j in range(n):
		if d.get(r[j]) != None:
			ans = min(ans, d[r[j]] + n - j - 1)
	print(ans)


import sys
import io, os
input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	L = A[0:n]
	R = A[n:]
	L.reverse()
	L1 = [0] * (n + 1)
	L2 = [0] * (n + 1)
	for (i, l) in enumerate(L):
		L1[i + 1] = L1[i]
		L2[i + 1] = L2[i]
		if l == 1:
			L1[i + 1] += 1
		else:
			L2[i + 1] += 1
	R1 = [0] * (n + 1)
	R2 = [0] * (n + 1)
	for (i, r) in enumerate(R):
		R1[i + 1] = R1[i]
		R2[i + 1] = R2[i]
		if r == 1:
			R1[i + 1] += 1
		else:
			R2[i + 1] += 1
	d = {}
	for j in range(n + 1):
		if R1[j] - R2[j] not in d:
			d[R1[j] - R2[j]] = j
	ans = 2 * n
	for i in range(n + 1):
		p = R1[-1] - R2[-1] + L1[-1] - L2[-1] - (L1[i] - L2[i])
		if p in d:
			j = d[p]
			ans = min(i + j, ans)
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	t = int(input())
	diff = 0
	l = list(map(int, input().split()))
	for j in range(2 * t):
		if l[j] == 1:
			diff += 1
		else:
			diff -= 1
	if diff == 0:
		print(0)
		continue
	d = dict()
	diffl = 0
	x = set()
	for j in range(t - 1, -1, -1):
		if l[j] == 1:
			diffl += 1
		else:
			diffl -= 1
		if diffl not in x:
			d.update({diffl: t - j})
			x.add(diffl)
	d1 = dict()
	diffr = 0
	x1 = set()
	for j in range(t, 2 * t):
		if l[j] == 1:
			diffr += 1
		else:
			diffr -= 1
		if diffr not in x1:
			d1.update({diffr: j - t + 1})
			x1.add(diffr)
	ans = 9999999999999
	for i in d:
		c = diff - i
		if c == 0:
			zx = d[i]
			ans = min(ans, zx)
		elif c in d1.keys():
			zx = d[i] + d1[c]
			ans = min(ans, zx)
	for i in d1:
		c = diff - i
		if c == 0:
			zx = d1[i]
			ans = min(ans, zx)
		elif c in d.keys():
			zx = d1[i] + d[c]
			ans = min(ans, zx)
	print(ans)


fg = int(input())
for ghj in range(fg):
	input()
	l = input().split(' ')
	for k in range(0, len(l)):
		if l[k] == '1':
			l[k] = -1
		if l[k] == '2':
			l[k] = 1
	n = len(l) // 2
	s = 0
	h = ['' for i in range(0, len(l) + 1)]
	o = ['' for i in range(0, len(l) + 1)]
	h[n] = -1
	o[n] = -1
	for i in range(0, n):
		s += int(l[i])
		h[s + n] = i
	su = 0
	for j in range(0, n):
		su -= int(l[len(l) - j - 1])
		o[su + n] = j
	mn = len(l)
	for p in range(0, len(l) + 1):
		if o[p] != '' and h[p] != '':
			if len(l) - o[p] - h[p] - 2 < mn:
				mn = len(l) - o[p] - h[p] - 2
	print(mn)


from collections import defaultdict
from itertools import accumulate
for _ in range(int(input())):
	n = int(input())
	l = tuple(map(lambda x: 1 if x == '1' else -1, input().split()))
	max_so_far = 0
	left = {0: 0}
	right = {0: 0}
	count = 1
	for i in accumulate(l[0:n]):
		left[i] = count
		count += 1
	count = 1
	for i in accumulate(l[-1:n - 1:-1]):
		right[i] = count
		count += 1
	for k in left:
		if -k in right:
			max_so_far = max(max_so_far, left[k] + right[-k])
	print(2 * n - max_so_far)


t = int(input())

def solve(arr):
	right = {}
	left = {}
	diff_left = 0
	diff_right = 0
	for i in range(len(arr) // 2 - 1, -1, -1):
		if arr[i] == 1:
			if diff_left + 1 > 0:
				left[diff_left + 1] = min(len(arr) // 2 - i, left.get(diff_left + 1, 10 ** 10))
			diff_left += 1
		if arr[i] == 2:
			if diff_left - 1 > 0:
				left[diff_left - 1] = min(len(arr) // 2 - i, left.get(diff_left - 1, 10 ** 10))
			diff_left -= 1
	for i in range(len(arr) // 2, len(arr)):
		if arr[i] == 1:
			if diff_right + 1 > 0:
				right[diff_right + 1] = min(i - len(arr) // 2 + 1, right.get(diff_right + 1, 10 ** 10))
			diff_right += 1
		if arr[i] == 2:
			if diff_right - 1 > 0:
				right[diff_right - 1] = min(i - len(arr) // 2 + 1, right.get(diff_right - 1, 10 ** 10))
			diff_right -= 1
	if diff_left + diff_right == 0:
		return 0
	ans = 10 ** 10
	right[0] = 0
	left[0] = 0
	for i in range(diff_left + diff_right + 1):
		if i in right and diff_left + diff_right - i in left:
			if right[i] + left[diff_left + diff_right - i] < ans:
				ans = right.get(i, 0) + left.get(diff_left + diff_right - i, 0)
	return ans
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr.count(1) < arr.count(2):
		arr = [3 - num for num in arr]
	print(solve(arr))


t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(x) for x in input().split()]
	diff = s.count(1) - s.count(2)
	kk = dict()
	c = 0
	tot = 0
	for i in range(n, len(s)):
		if kk.get(c) == None:
			kk[c] = tot
		else:
			kk[c] = min(kk[c], tot)
		tot += 1
		if s[i] == 1:
			c += 1
		else:
			c -= 1
	if kk.get(c) == None:
		kk[c] = tot
	else:
		kk[c] = min(kk[c], tot)
	c = 0
	tot = 0
	ans = 2 * n
	for i in range(n - 1, -1, -1):
		if kk.get(diff - c) != None:
			ans = min(ans, tot + kk[diff - c])
		tot += 1
		if s[i] == 1:
			c += 1
		else:
			c -= 1
	if kk.get(diff - c) != None:
		ans = min(ans, tot + kk[diff - c])
	print(ans)


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	a = list(mints())
	c = dict()
	c[0] = 2 * n
	d = 0
	for i in range(2 * n - 1, n - 1, -1):
		if a[i] == 1:
			d += 1
		else:
			d -= 1
		c[d] = i
	d = 0
	r = 2 * n
	r = min(r, n + c[0] - n)
	for i in range(n):
		if a[i] == 1:
			d += 1
		else:
			d -= 1
		if -d in c:
			r = min(r, n - i - 1 + c[-d] - n)
	return r
for i in range(mint()):
	print(solve())


for i in range(int(input())):
	n = int(input())
	al = list(map(int, input().split()))
	cur_ans = 2 * n
	mem = {}
	cs = 0
	for i in range(n):
		if al[i] == 1:
			cs += 1
		else:
			cs -= 1
		mem[cs] = i
		if cs == 0:
			cur_ans = min(cur_ans, 2 * n - i - 1)
	cs = 0
	for i in range(2 * n - 1, n - 1, -1):
		if al[i] == 1:
			cs -= 1
		else:
			cs += 1
		if cs in mem:
			cur_ans = min(cur_ans, i - mem[cs] - 1)
		if cs == 0:
			cur_ans = min(cur_ans, i)
	print(cur_ans)


t = int(input())
for _ in range(0, t):
	n = int(input())
	a = [int(i) for i in input().split()]
	(nos, nob) = (a.count(1), a.count(2))
	if nos == nob:
		ans = 0
	else:
		(s, b) = (0, 0)
		ans = 2 * n
		diff = {}
		for i in range(0, n):
			if a[i] == 1:
				s += 1
			else:
				b += 1
			diff[s - b] = i
			if b == s:
				ans = min(ans, 2 * n - i - 1)
		(s, b) = (0, 0)
		for i in range(2 * n - 1, n - 1, -1):
			if a[i] == 1:
				s += 1
			else:
				b += 1
			if b - s in diff:
				ans = min(ans, i - diff[b - s] - 1)
			if b == s:
				ans = min(ans, i)
	print(ans)


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
test = int_input()
for _ in range(test):
	n = int_input()
	jars = list_input()
	Type = {1: 1, 2: -1}
	dicti = {}
	DIFF = 0
	dicti[0] = 0
	for (i, ch) in enumerate(jars[:n]):
		DIFF += Type[ch]
		dicti[DIFF] = i + 1
	ans = 0
	jars.reverse()
	if 0 in dicti:
		ans = dicti[0]
	DIFF = 0
	for (i, ch) in enumerate(jars[:n]):
		DIFF += Type[ch]
		if -DIFF in dicti:
			ans = max(ans, dicti[-DIFF] + i + 1)
	print(2 * n - ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	jars = list(map(int, input().split()))
	red = 0
	blue = 0
	for s in range(len(jars)):
		if jars[s] == 1:
			red += 1
		else:
			blue += 1
	diff = max(red, blue) - min(red, blue)
	if red == blue:
		print(0)
	else:
		left = jars[:n]
		left.reverse()
		right = jars[n:]
		if red > blue:
			dict1 = {}
			dict2 = {}
			for s in range(diff):
				dict1[s + 1] = []
				dict2[s + 1] = []
			count1 = 0
			for s in range(len(left)):
				if left[s] == 1:
					count1 += 1
				else:
					count1 -= 1
				if count1 > 0 and count1 <= diff:
					dict1[count1].append(s + 1)
			count2 = 0
			for s in range(len(right)):
				if right[s] == 1:
					count2 += 1
				else:
					count2 -= 1
				if count2 > 0 and count2 <= diff:
					dict2[count2].append(s + 1)
			minsofar = 2 * n
			for s in range(1, diff):
				move1 = dict1[diff - s]
				move2 = dict2[s]
				if len(move1) != 0 and len(move2) != 0:
					path = move1[0] + move2[0]
					if path < minsofar:
						minsofar = path
			move1 = dict1[diff]
			move2 = dict2[diff]
			if len(move1) != 0:
				minny = move1[0]
			else:
				minny = 2 * n
			if len(move2) != 0:
				minny1 = move2[0]
			else:
				minny1 = 2 * n
			if min(minny, minny1) < minsofar:
				minsofar = min(minny, minny1)
			print(minsofar)
		elif blue > red:
			dict1 = {}
			dict2 = {}
			for s in range(diff):
				dict1[s + 1] = []
				dict2[s + 1] = []
			count1 = 0
			for s in range(len(left)):
				if left[s] == 2:
					count1 += 1
				else:
					count1 -= 1
				if count1 > 0 and count1 <= diff:
					dict1[count1].append(s + 1)
			count2 = 0
			for s in range(len(right)):
				if right[s] == 2:
					count2 += 1
				else:
					count2 -= 1
				if count2 > 0 and count2 <= diff:
					dict2[count2].append(s + 1)
			minsofar = 2 * n
			for s in range(1, diff):
				move1 = dict1[diff - s]
				move2 = dict2[s]
				if len(move1) != 0 and len(move2) != 0:
					path = move1[0] + move2[0]
					if path < minsofar:
						minsofar = path
			move1 = dict1[diff]
			move2 = dict2[diff]
			if len(move1) != 0:
				minny = move1[0]
			else:
				minny = 2 * n
			if len(move2) != 0:
				minny1 = move2[0]
			else:
				minny1 = 2 * n
			if min(minny, minny1) < minsofar:
				minsofar = min(minny, minny1)
			print(minsofar)


from math import *
from collections import *
from random import *
from bisect import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	ld = {}
	rd = {}
	x = a.count(1) - a.count(2)
	if abs(x) == 2 * n:
		print(2 * n)
		continue
	if x == 0:
		print(0)
		continue
	a1 = 0
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			a1 += 1
		else:
			a1 -= 1
		try:
			ld[a1] = min(ld[a1], n - i)
		except:
			ld[a1] = n - i
	a1 = 0
	for i in range(n, 2 * n):
		if a[i] == 1:
			a1 += 1
		else:
			a1 -= 1
		try:
			rd[a1] = min(rd[a1], i - n + 1)
		except:
			rd[a1] = i - n + 1
	an = float('inf')
	for i in ld.keys():
		need = x - i
		if need in rd:
			an = min(an, ld[i] + rd[need])
	if x in ld:
		an = min(an, ld[x])
	if x in rd:
		an = min(an, rd[x])
	print(an)


import sys, math, itertools, collections, bisect
input = lambda : sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0
count = 0
pro = 1

def solve():
	n = int(input())
	data = list(map(int, input().split()))
	d1 = data[:n]
	d2 = data[n:]
	mindata1 = [inf] * (2 * n + 1)
	mindata1[n] = 0
	mindata2 = [inf] * (2 * n + 1)
	mindata2[n] = 0
	count = n
	for (i, di) in enumerate(d2):
		if di == 1:
			count += 1
		else:
			count -= 1
		mindata2[count] = min(mindata2[count], i + 1)
	count = n
	d1.reverse()
	for (i, di) in enumerate(d1):
		if di == 1:
			count += 1
		else:
			count -= 1
		mindata1[count] = min(mindata1[count], i + 1)
	s = 0
	for di in data:
		if di == 1:
			s += 1
		else:
			s -= 1
	need = -s
	ans = inf
	for i in range(2 * n + 1):
		if 0 <= n + s - (i - n) < 2 * n + 1:
			ans = min(ans, mindata1[i] + mindata2[n + s - (i - n)], mindata1[n + s - (i - n)] + mindata2[i])
	print(ans)
q = int(input())
for i in range(q):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	p = a.count(1)
	q = 2 * n - p
	d = p - q
	if d == 0:
		print(0)
		continue
	c = 0
	di = {0: n}
	l = 2 * n
	for j in range(n, 2 * n, 1):
		if a[j] == 1:
			c = c + 1
		else:
			c = c - 1
		if d - c == 0:
			l = min(l, j - n + 1)
		if c not in di:
			di[c] = j + 1
	c = 0
	for j in range(n - 1, -1, -1):
		if a[j] == 1:
			c = c + 1
		else:
			c = c - 1
		if d - c in di:
			l = min(l, di[d - c] - j)
	print(l)


from collections import defaultdict
for _ in range(int(input())):
	N = int(input())
	List = [int(x) for x in input().split()]
	one = List.count(1)
	two = List.count(2)
	Needed = two - one
	if Needed == 0:
		print(0)
		continue
	first = []
	second = []
	prev = 0
	for i in range(N - 1, -1, -1):
		if List[i] == 1:
			prev -= 1
			first.append(prev)
		else:
			prev += 1
			first.append(prev)
	prev = 0
	for i in range(N, N << 1):
		if List[i] == 1:
			prev -= 1
			second.append(prev)
		else:
			prev += 1
			second.append(prev)
	Dict = defaultdict(int)
	for i in range(N):
		if Dict[second[i]] == 0:
			Dict[second[i]] = i + 1
	if Dict[Needed]:
		ans = Dict[Needed]
	else:
		ans = 10 ** 9
	for i in range(N):
		if first[i] == Needed:
			ans = min(ans, i + 1)
		elif Dict[Needed - first[i]]:
			temp = i + 1 + Dict[Needed - first[i]]
			ans = min(ans, temp)
	print(ans)


from collections import defaultdict
import sys

def input():
	return sys.stdin.readline().rstrip()

def slv():
	n = int(input())
	seq = list(map(int, input().split()))

	def f(x):
		if x == 1:
			return 1
		return -1
	seq = list(map(f, seq))
	dpl = [0] * (n + 1)
	dif = 0
	for i in range(n):
		dif += seq[i]
		dpl[i + 1] = dif
	dpr = [0] * (n + 1)
	dif = 0
	seq.reverse()
	for i in range(n):
		dif += seq[i]
		dpr[i + 1] = dif
	ans = 1 << 128
	d = defaultdict(int)
	for i in range(n + 1):
		v = dpr[i]
		d[v] = i
	for i in range(n + 1):
		if -dpl[i] in d.keys():
			ans = min(ans, 2 * n - i - d[-dpl[i]])
	print(ans)
	return

def main():
	t = int(input())
	for i in range(t):
		slv()
	return
main()


import sys
from collections import Counter, defaultdict
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = [a - 2 if a == 1 else a - 1 for a in LIST()]
	C = Counter(A)
	diff = abs(C[-1] - C[1])
	if diff == 0:
		print(0)
		continue
	B = A[N:]
	A = A[:N][::-1]
	A = [0] + list(accumulate(A))
	B = [0] + list(accumulate(B))
	D1 = defaultdict(lambda : INF)
	D2 = defaultdict(lambda : INF)
	for i in range(N, -1, -1):
		D1[A[i]] = i
		D2[B[i]] = i
	ans = INF
	for i in range(diff + 1):
		a = i
		b = diff - i
		if C[-1] - C[1] > 0:
			a = -a
			b = -b
		try:
			idx1 = D1[a]
			idx2 = D2[b]
			ans = min(ans, idx1 + idx2)
		except:
			continue
	print(ans)