t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    if a.count(-1)==len(a):
        print(0,1)
    else:
        d=list()
        for i in range(n):
            if i+1 < n and a[i]==-1 and a[i+1]!=-1:
                d.append(a[i+1])
            if i-1 >=0 and a[i]==-1 and a[i-1]!=-1:
                d.append(a[i-1])
        m=0
        for  i in range(n-1):
            if a[i]!=-1 and a[i+1]!=-1:
                m=max(m,abs(a[i]-a[i+1]))
        d.sort()
        s=d[-1]+d[0]
        if s%2==0:
            k=s//2
            for  i in range(n):
                if a[i]==-1:
                    a[i]=k
            for i in range(1,n):
                m=max(m,abs(a[i]-a[i-1]))
            print(m,k)
        else:
            t1=s//2
            t2=t1+1
            v=a.copy()
            for  i in range(n):
                if a[i]==-1:
                    a[i]=t1
                if v[i]==-1:
                    v[i]=t2
            q=m
            for i in range(1,n):
                m=max(m,abs(a[i]-a[i-1]))
                q=max(q,abs(v[i]-v[i-1]))
            if m<q:
                print(m,t1)
            else:
                print(q,t2)


t=int(input())
for _ in range(t):
    n=int(input())
    a=list(map(int,input().split()))
    if a.count(-1)==len(a):
        print(0,1)
    else:
        d={}
        if len(a)>1:
            if a[1]==-1 and a[0]!=-1:
                d[a[0]]=1

        for i in range(1,n-1):
            if a[i]==-1 and a[i+1]!=-1:
                if a[i+1] not in d:
                    d[a[i+1]]=1
                else:
                    d[a[i+1]]+=1
            if a[i]==-1 and a[i-1]!=-1:
                if a[i+1] not in d:
                    d[a[i+1]]=1
                else:
                    d[a[i+1]]+=1
        if a[-1]==-1 and a[-2]!=-1:
            if a[-2] not in d:
                    d[a[-2]]=1
            else:
                d[a[-2]]+=1
        m=0
        for  i in range(n-1):
            if a[i]!=-1 and a[i+1]!=-1:
                m=max(m,abs(a[i]-a[i+1]))

        s=0
        for i in d:
            s+=i
        k=s//len(d)
        for  i in range(n):
            if a[i]==-1:
                a[i]=k
        for i in range(1,n):
            m=max(m,a[i]-a[i-1])
        print(m,k)


import math
import statistics
t=int(input())
for i in range(t):
	n=int(input())
	a=list(map(int,input().split()))
	b=[]
	c=list(a)
	diffl=[]
	ans=0
	for i in range(len(a)):
		if(a[i]==-1):
			if(i>0 and a[i-1]!=-1):
				b.append(a[i-1])
			if(i<n-1 and a[i+1]!=-1):
				b.append(a[i+1])
	b.sort()
	if(len(b)==0):
		ans=12
		diff=0
	else:
		ans=(b[0]+b[-1])//2
		for l in range(0,len(c)):
			if(c[l]==-1):
				c[l]=ans
		for j in range(1,len(a)):
		    diffl.append(abs(c[j]-c[j-1]))
		diff=max(diffl)
	print(diff,ans)


import math
import statistics
t=int(input())
for i in range(t):
	n=int(input())
	a=list(map(int,input().split()))
	b=[]
	c=list(a)
	diffl=[]
	ans=0
	for i in a:
		if(i>=0):
			b.append(i)
	if(len(b)==0):
		ans=12
		diff=0
	else:
		x=math.floor(statistics.median(b))
		y=math.floor(statistics.mean(b))
		if(x<=y and x<=max(a)):
			ans=x
		else:
			ans=y
		for l in range(0,len(c)):

			if(c[l]==-1):
				c[l]=ans
		for j in range(0,len(a)-1):
		    diffl.append(c[j+1]-c[j])
		diff=max(diffl)
	print(diff,ans)


import math
import statistics
t=int(input())
for i in range(t):
	n=int(input())
	a=list(map(int,input().split()))
	b=[]
	for i in a:
		if(i>=0):
			b.append(i)
	if(len(b)==0):
		x=12
		diff=0
	else:
		x=math.floor(statistics.mean(b))
		diff=max(b)-x
	print(diff,x)


import math
import statistics
t=int(input())
for i in range(t):
	n=int(input())
	a=list(map(int,input().split()))
	b=[]
	c=list(a)
	diffl=[]
	ans=0
	for i in a:
		if(i>=0):
			b.append(i)
	b.sort()
	if(len(b)==0):
		ans=12
		diff=0
	else:
		ans=(b[0]+b[-1])//2
		for l in range(0,len(c)):
			if(c[l]==-1):
				c[l]=ans
		for j in range(1,len(a)):
		    diffl.append(abs(c[j]-c[j-1]))
		diff=max(diffl)
	print(diff,ans)


import math
import statistics
t=int(input())
for i in range(t):
	n=int(input())
	a=list(map(int,input().split()))
	b=[]
	ans=0
	for i in a:
		if(i>=0):
			b.append(i)
	if(len(b)==0):
		x=12
		diff=0
	else:
		x=math.floor(statistics.median(b))
		y=math.floor(statistics.mean(b))
		if(x<=y and x<=max(a)):
			ans=x
		else:
			ans=y
		diff=max(b)-ans
	print(diff,ans)


import math
import statistics
t=int(input())
for i in range(t):
	n=int(input())
	a=list(map(int,input().split()))
	b=[]
	c=list(a)
	diffl=[]
	ans=0
	for i in a:
		if(i>=0):
			b.append(i)
	if(len(b)==0):
		ans=12
		diff=0
	else:
		x=math.floor(statistics.median(b))
		y=math.floor(statistics.mean(b))
		if(x<=y and x<=max(a)):
			ans=x
		else:
			ans=y
		for l in range(0,len(c)):

			if(c[l]==-1):
				c[l]=ans
		for j in range(1,len(a)):
		    diffl.append(abs(c[j]-c[j-1]))
		diff=max(diffl)
	print(diff,ans)


for _ in range(int(input())):
    n=int(input())
    a=[]
    b=[]
    l=list(map(int,input().split()))
    if l.count(-1)==n:
        print(0,0)
    else:
        for i in range(n):
            if l[i]!=-1:
                if i==0:
                    if l[i+1]==-1:
                        a.append(l[i])
                elif i==n-1:
                    if l[i-1]==-1:
                        a.append(l[i])
                else:
                    if l[i+1]==-1 or l[i-1]==-1:
                        a.append(l[i])
        k=(max(a)+min(a))//2
        for i in range(n):
            if l[i]==-1:
                if i==0:
                    if l[i+1]!=-1:
                        b.append(abs(l[i+1]-k))
                elif i==n-1:
                    if l[i-1]!=-1:
                        b.append(abs(l[i-1]-k))
                else:
                    if l[i-1]!=-1:
                        b.append(abs(l[i-1]-k))
                    if l[i+1]!=-1:
                        b.append(abs(l[i+1]-k))
        print(max(b),k)


for _ in range(int(input())):
    n=int(input())
    a=[]
    b=[]
    l=list(map(int,input().split()))
    if l.count(-1)==n:
        print(0,0)
    else:
        for i in range(n):
            if l[i]!=-1:
                if i==0:
                    if l[i+1]==-1:
                        a.append(l[i])
                elif i==n-1:
                    if l[i-1]==-1:
                        a.append(l[i])
                else:
                    if l[i+1]==-1 or l[i-1]==-1:
                        a.append(l[i])
        k=(max(a)+min(a))//2
        for i in range(n):
            if l[i]==-1:
                l[i]=k
        for i in range(1,n):
            b.append(abs(l[i]-l[i-1]))
        print(max(b),k)


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    b = []
    m = 0
    for i in range(n):
        if(a[i] == -1):
            if(i >0) and (a[i-1] != -1):
                b.append(a[i-1])
            if(i < n-1) and (a[i+1] != -1):
                b.append(a[i+1])
    if(len(b) != 0):
        m = (max(b) + min(b))//2

    c = [m if j==-1 else j for j in a]
    k =0
    for t in range(n-1):
        k = max(k, abs(c[t+1] - c[t]))
    print(k, m)


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    c = a.count(-1)
    c1 = a.count(0)
    if(c+c1 == n):
        print("0 0")
    elif(n ==2):
        if(a[0] == -1) and (a[1] == -1):
            print("0 0")
        elif(a[0] == -1):
            print("0", a[1])
        elif(a[1] == -1):
            print("0", a[0])
        else:
            print(abs(a[1] - a[0]), "0")
    else:
        t = 1
        b = []
        if(a[0] == -1) and (a[1] != -1):
            b.append(a[1])
        if(a[n-1] == -1) and (a[n-2] != -1):
            b.append(a[n-2])
        for j in range(1, n-1):
            if(a[j] == -1):
                if(a[j-1] != -1):
                    if(a[j-1] in b):
                        continue
                    else:
                        b.append(a[j-1])
                else:
                    continue
                if(a[j+1] != -1):
                    if(a[j+1] in b):
                        continue
                    else:
                        b.append(a[j+1])
                else:
                    continue
            else:
                t = 0
        k = (max(b) + min(b))//2
        if(a[0] == -1):
            a[0] = k
        m = 0
        for i in range(1, n):
            if(a[i] == -1):
                a[i] = k
            else:
                t = 0
            if(abs(a[i] - a[i-1]) > m):
                m = abs(a[i] - a[i-1])
            else:
                t = 0
        print(m, k)


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    c = a.count(-1)
    if(c == n):
        print("0 0")
    else:
        k = (sum(a)+c)//(n-c)
        m = 0
        if(a[0] == -1):
            a[0] = k
        for i in range(1, n):
            if(a[i] == -1):
                a[i] = k
            if(abs(a[i] - a[i-1]) > m):
                m = abs(a[i] - a[i-1])
        print(m, k)


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    c = a.count(-1)
    c1 = a.count(0)
    if(c == n):
        print("0 0")
    elif(c+c1 == n):
        print("0 0")
    else:
        b = []
        for j in range(1, n-1):
            if(a[j] == -1):
                if(a[j-1] != -1):
                    if(a[j-1] in b):
                        continue
                    else:
                        b.append(a[j-1])
                else:
                    continue
                if(a[j+1] != -1):
                    if(a[j+1] in b):
                        continue
                    else:
                        b.append(a[j+1])
                else:
                    continue
        k1 = (sum(b))//len(b)
        k2 = k1 +1
        m1 = 0
        m2 = 0
        d = [None]*(n)
        if(a[0] == -1):
            a[0] = k1
            d[0] = k2
        else:
            d[0] = a[0]
        for i in range(1, n):
            if(a[i] == -1):
                a[i] = k1
                d[i] = k2
            else:
                d[i] = a[i]
            if(abs(a[i] - a[i-1]) > m1):
                m1 = abs(a[i] - a[i-1])
            if(abs(d[i] - d[i-1]) > m2):
                m2 = abs(d[i] - d[i-1])
        if(m1 <= m2):
            print(m1, k1)
        else:
            print(m2, k2)


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    c = a.count(-1)
    c1 = a.count(0)
    if(c == n):
        print("0 0")
    elif(c+c1 == n):
        print("0 0")
    elif(n ==2):
        if(a[0] == -1) and (a[1] == -1):
            print("0 0")
        elif(a[0] == -1):
            print("0", a[1])
        else:
            print("0", a[0])
    else:
        b = []
        for j in range(1, n-1):
            if(a[j] == -1):
                if(a[j-1] != -1):
                    if(a[j-1] in b):
                        continue
                    else:
                        b.append(a[j-1])
                else:
                    continue
                if(a[j+1] != -1):
                    if(a[j+1] in b):
                        continue
                    else:
                        b.append(a[j+1])
                else:
                    continue
        k1 = (sum(b))//len(b)
        k2 = k1 +1
        m1 = 0
        m2 = 0
        d = [None]*(n)
        if(a[0] == -1):
            a[0] = k1
            d[0] = k2
        else:
            d[0] = a[0]
        for i in range(1, n):
            if(a[i] == -1):
                a[i] = k1
                d[i] = k2
            else:
                d[i] = a[i]
            if(abs(a[i] - a[i-1]) > m1):
                m1 = abs(a[i] - a[i-1])
            if(abs(d[i] - d[i-1]) > m2):
                m2 = abs(d[i] - d[i-1])
        if(m1 <= m2):
            print(m1, k1)
        else:
            print(m2, k2)


t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))

    cnt = 1 if a[0] != -1 and a[1] == -1 else 0
    maxdif = 0
    max_ai = a[0]
    min_ai = a[0] if a[0] != -1 and a[1] == -1 else 10**9
    for i in range(1,n-1):
        if a[i-1] != -1 and a[i] != -1:
            maxdif = max(maxdif,abs(a[i]-a[i-1]))
        if a[i] != -1 and (a[i-1] == -1 or a[i+1] == -1):
            min_ai = min(min_ai,a[i])
            max_ai = max(max_ai,a[i])
            cnt += 1
    if a[n-2] != -1 and a[n-1] != -1:
            maxdif = max(maxdif,abs(a[n-1]-a[n-2]))
    if a[n-1] != -1 and a[n-2] == -1:
            min_ai = min(min_ai,a[n-1])
            max_ai = max(max_ai,a[n-1])
            cnt += 1

    if cnt != 0:
        avg = (max_ai+min_ai)//2
        print(max(max_ai-avg,maxdif),avg)
    else:
        print(0,0)


t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    total = a[0] if a[0] != -1 and a[1] == -1 else 0
    cnt = 1 if a[0] != -1 and a[1] == -1 else 0
    maxdif = 0
    max_ai = a[0]
    for i in range(1,n-1):
        max_ai = max(max_ai,a[i])
        if a[i-1] != -1 and a[i] != -1:
            maxdif = max(maxdif,abs(a[i]-a[i-1]))
        if a[i] != -1 and (a[i-1] == -1 or a[i+1] == -1):
            total += a[i]
            cnt += 1
    max_ai = max(max_ai,a[n-1])
    if a[n-2] != -1 and a[n-1] != -1:
            maxdif = max(maxdif,abs(a[n-1]-a[n-2]))
    if a[n-1] != -1 and a[n-2] == -1:
            total += a[n-1]
            cnt += 1

    if cnt != 0:
        avg = total//cnt
        print(max(max_ai-avg,maxdif),avg)
    else:
        print(0,0)


t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))
    total = a[0] if a[0] != -1 else 0
    cnt = 1 if a[0] != -1 else 0
    maxdif = 0
    max_ai = a[0]
    for i in range(1,n):
        max_ai = max(max_ai,a[i])
        if a[i-1] != -1 and a[i] != -1:
            maxdif = max(maxdif,abs(a[i]-a[i-1]))
        if a[i] != -1:
            total += a[i]
            cnt += 1

    if cnt != 0:
        avg = total//cnt
        print(max(max_ai-avg,maxdif),avg)
    else:
        print(0,0)


t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))

    cnt = 1 if a[0] != -1 and a[1] == -1 else 0
    maxdif = 0
    max_ai = a[0] if a[0] != -1 and a[1] == -1 else 0
    min_ai = a[0] if a[0] != -1 and a[1] == -1 else 10**9
    for i in range(1,n-1):
        if a[i-1] != -1 and a[i] != -1:
            maxdif = max(maxdif,abs(a[i]-a[i-1]))
        if a[i] != -1 and (a[i-1] == -1 or a[i+1] == -1):
            min_ai = min(min_ai,a[i])
            max_ai = max(max_ai,a[i])
            cnt += 1
    if a[n-2] != -1 and a[n-1] != -1:
            maxdif = max(maxdif,abs(a[n-1]-a[n-2]))
    if a[n-1] != -1 and a[n-2] == -1:
            min_ai = min(min_ai,a[n-1])
            max_ai = max(max_ai,a[n-1])
            cnt += 1

    if cnt != 0:
        avg = (max_ai+min_ai)//2
        print(max(max_ai-avg,maxdif),avg)
    else:
        print(0,0)


t = int(input())
for i in range(t):
    n = int(input())
    a = list(map(int,input().split()))

    cnt = 0
    maxdif = 0
    max_ai = a[0]
    min_ai = a[0] if a[0] != -1 and a[1] == -1 else 10**9
    for i in range(1,n-1):
        if a[i-1] != -1 and a[i] != -1:
            maxdif = max(maxdif,abs(a[i]-a[i-1]))
        if a[i] != -1 and (a[i-1] == -1 or a[i+1] == -1):
            min_ai = min(min_ai,a[i])
            max_ai = max(max_ai,a[i])
            cnt += 1
    if a[n-2] != -1 and a[n-1] != -1:
            maxdif = max(maxdif,abs(a[n-1]-a[n-2]))
    if a[n-1] != -1 and a[n-2] == -1:
            min_ai = min(min_ai,a[n-1])
            max_ai = max(max_ai,a[n-1])
            cnt += 1

    if cnt != 0:
        avg = (max_ai+min_ai)//2
        print(max(max_ai-avg,maxdif),avg)
    else:
        print(0,0)


t = int(input())
for z in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ma = 0
    mi = 10**9
    maM = 0
    i = 0
    j = 1
    while j < n:
        if a[j] == -1 and a[i] != -1:
            if a[i] > ma:
                ma = a[i]
            if a[i] < mi:
                mi = a[i]
        if a[i] == -1 and a[j] != -1:
            if a[j] > ma:
                ma = a[j]
            if a[j] < mi:
                mi = a[j]
        if a[i] != -1 and a[j] != -1:
            if abs(a[i] - a[j]) > maM:
                maM = abs(a[i] - a[j])
        i+=1
        j+=1
    k = (ma + mi)//2
    m1 = max(abs(ma - k), abs(mi - k))
    m = max(m1, maM)
    print(m, k)


t = int(input())
for z in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    ma = 0
    mi = 10**9
    maM = 0
    i = 0
    j = 1
    f = 0
    while j < n:
        if a[j] == -1 and a[i] != -1:
            f = 1
            if a[i] > ma:
                ma = a[i]
            if a[i] < mi:
                mi = a[i]
        if a[i] == -1 and a[j] != -1:
            f = 1
            if a[j] > ma:
                ma = a[j]
            if a[j] < mi:
                mi = a[j]
        if a[i] != -1 and a[j] != -1:
            if abs(a[i] - a[j]) > maM:
                maM = abs(a[i] - a[j])
        i+=1
        j+=1
    k = (ma + mi)//2
    m1 = max(abs(ma - k), abs(mi - k))
    m = max(m1, maM)
    if f == 0 and maM == 0:
        print(0, k)
    else:
        print(m, k)


I=input
for _ in[0]*int(I()):
 I();a=[*map(int,I().split())];b=[y
for x,y,z in zip([0]+a,a,a[1:]+[0])if
0>x|z<y]or[0];l=min(b);m=max([(max(b)-l+1)//2]+[abs(x-y)for
x,y in zip(a,a[1:])if~x&~y and x^y]);print(m,l+m)


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]]:
            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]]:
            closest_r[right[j]] = j
        j += 1
        i += 1

    maxx = 0
    mi = 2*n
    for i in range(n):
        li = left[i]
        if li == diff or (diff-li > 0 and li + closest_r[diff-li] == diff):
            mi = i+1
    for i in range(n):
        ri = right[i]
        if ri == diff or (diff-ri > 0 and ri + closest_l[diff-ri] == diff):
            mi = i+1

    print(mi)


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 i + closest_r[diff-li] + 1 < mi and diff-li > 0 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 i + closest_l[diff-ri] + 1 < mi and diff-ri > 0 and closest_l[diff-ri] >= 0 and ri + left[closest_l[diff-ri]] == diff:
            mi = i + closest_l[diff-ri] + 2

    print(mi)


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
#import random
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

#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
#show_flg=True

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])
    #print(ans)

    show('A',A)
    show(a,b)
    show(c,d)
    show('D',D)

    return ans

def solve2(n,A):
    ac=[0]

    # ac 0 .. 2*n
    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]
        #if Lsum+Rsum==0 >> ok
        r=D[n-Lsum]
        ans=min(ans,l+r)
    '''
    show(n,A[:n],A[n:])
    show(ac[:n+1],ac[n+1:])
    show(D[:n+1],D[n+1:])
    '''
    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()
#t=20

for _ in range(t):
    ans=0

    n=I()
    A=[1 if i==2 else -1 for i in LI()]
    '''
    n,A=rand()
    if solve(n,A)!=naive(n,A)[0]:
        print(solve(n,A),naive(n,A),n,A[:n],A[n:],*A)
    '''
    ans=solve2(n,A)
    print(ans)


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
#import random
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

#sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

show_flg=False
#show_flg=True

t=I()
for _ in range(t):
    ans=0
    n=I()
    A=[1 if i==2 else -1 for i in LI()]
    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])
    print(ans)


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')))


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)

if __name__ == '__main__':
    t = int(input())
    for i in range(t):
        main()


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()
    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)
    print(dct_val_1, dct_val_2)
    for i in dct_val_1:
        if i == 0:
            if 0 in dct_val_2:
                mn = min(mn,  dct_val_1[0] + dct_val_2[0])
            else:
                mn = min(mn, dct_val_1[0] + len(line1))
        elif -i in dct_val_2:
            mn = min(mn,  dct_val_2[-i] + dct_val_1[i])
    if 0 in dct_val_2:
        if 0 in dct_val_1:
            mn = min(mn, dct_val_1[0] + dct_val_2[0])
        else:
            mn = min(mn, dct_val_2[0] + len(line1))

    print(mn)

if __name__ == '__main__':
    t = int(input())
    for i in range(t):
        main()


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()
    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 == 0:
            if 0 in dct_val_2:
                mn = min(mn,  dct_val_1[0] + dct_val_2[0])
            else:
                mn = min(mn, dct_val_1[0] + len(line1))
        elif -i in dct_val_2:
            mn = min(mn,  dct_val_2[-i] + dct_val_1[i])
    if 0 in dct_val_2:
        if 0 in dct_val_1:
            mn = min(mn, dct_val_1[0] + dct_val_2[0])
        else:
            mn = min(mn, dct_val_2[0] + len(line1))

    print(mn)

if __name__ == '__main__':
    t = int(input())
    for i in range(t):
        main()


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)
    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)

if __name__ == '__main__':
    t = int(input())
    for i in range(t):
        main()


from collections import defaultdict
from itertools import accumulate
# quit()
for _ in range(int(input())):
	n = int(input())
	l = tuple(map(lambda x:1 if x=='1' else -1,input().split()))
	# print(left,right)
	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)


for l in range(int(input())):
    d=[0]
	n=int(input())
	a=map(int,input().split())

	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)


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)


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)


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

    for left_index in range(n + 1):
        if left_index < min_number_of_cans:
            for right_index in range(n + 1):
                if balance_right[right_index] + balance_left[left_index] == difference:
                    tmp_min = right_index + left_index
                    if tmp_min < min_number_of_cans:
                        min_number_of_cans = tmp_min
                    break
        else:
            break

    print(min_number_of_cans)


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

    optimal_amount_of_cans = [10 ** 6] * (n+1)
    min_number_of_cans = 10 ** 6

    for left_index in range(n+1):
        for right_index in range(n+1):
            if balance_right[right_index] + balance_left[left_index] == difference:
                optimal_amount_of_cans[left_index] = right_index + left_index
                if optimal_amount_of_cans[left_index] < min_number_of_cans:
                    min_number_of_cans = optimal_amount_of_cans[left_index]
                break

    print(min_number_of_cans)


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 = {}
    #potential_keys = set()

    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 f(m, arr):
    sum = 0
    extra = 1
    for i in range(len(arr)):
        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 = [float('inf')] * (sum + 1)
    r_map = [float('inf')] * (sum + 1)
    l_map[0] = 0
    r_map[0] = 0
    f(l_map, left)
    f(r_map, right)
    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)


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)


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
    # reverse
    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 [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
        i=0
        t=n
        while i<=t:
            for j in range(1,n+1):
                if Ar[j]+Al[i]==count:
                    minstep=min(i+j,minstep)
                    t=min(minstep,t)
                    break
            i+=1
        print(minstep)


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[l+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:
        flag=False
        i=0
        for i in range(1,2*n+1):
            if i<=n:
                if Al[i]==count or Ar[i]==count:
                    flag=True
                else:
                    for x in range(1,i):
                        if Ar[x]+Al[i-x]==count:
                            flag = True
                            break
            else:
                for x in range(i-n, n+1):
                    if Ar[x]+Al[i - x] == count:
                        flag = True
                        break
            if flag:break
        print(i)


for _ in [0]*int(input()):
    n=int(input())
    s=list(map(int,input().split()))
    A=[[0]*(n+1) for x in range(n+1)]
    count=0
    for l in range(1,n+1):
        if s[n-l]==2:
            A[0][l]=A[0][l-1]+1
            count+=1
        else:
            A[0][l]=A[0][l - 1] - 1
            count-= 1
    for r in range(1,n+1):
        if s[l+r-1] == 2:
            A[r][0]=A[r-1][0]+1
            count += 1
        else:
            A[r][0]=A[r - 1][0] - 1
            count -= 1

    if count==0:print(0)
    else:
        flag=False
        i=0
        for i in range(1,2*n+1):
            if i<=n:
                if A[i][0]==count or A[0][i]==count:
                    flag=True
                else:
                    for x in range(1,i):
                        A[x][i-x]=A[x][0]+A[0][i-x]
                        if A[x][i-x]==count:
                            flag = True
                            break
            else:
                for x in range(i-n, n+1):
                    A[x][i - x] = A[x][0] + A[0][i - x]
                    if A[x][i - x] == count:
                        flag = True
                        break
            if flag:break
        print(i)


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)


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
        i=0
        t=n
        while i<=t:
            if Al[i]==count:
                minstep = min(i, minstep)
                t = min(minstep, t)
                break
            for j in range(1,n+1):
                if Ar[j]+Al[i]==count:
                    minstep=min(i+j,minstep)
                    t=min(minstep,t)
                    break
            i+=1
        print(minstep)


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[l+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
        for i in range(1,n+1):
            for j in range(1,n+1):
                if Ar[j]+Al[i]==count:
                    minstep=min(i+j,minstep)
                    break

        print(minstep)


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)
if __name__ == "__main__":
    main()


for _ in range(int(input())):
	n=int(input())
	mat=[[(0,0) for i in range(n+2)] for j in range(n+2)]
	costs=[int(x) for x in input().split()]
	costs.append(0)

	for j in range(1,n+2):
		total=mat[j][0]
		if cost[-j]==1:
			total+=1
		else:
			total-=1

		for i in range(1,n+2):
			jar=cost[i-1]
			if jar==1:
				total+=1
			else:
				total-=1
			mat[j][i][1]=total

			if total==0:
				mat[j][i][0]=0
			else:
				mat[j][i][0]=min(1+mat[j-1][i][0],1+mat[j][i-1][0])

	print(mat[n+1][n+1])


for _ in range(int(input())):
	n=int(input())
	mat=[[[1000,0] for i in range(n+2)] for j in range(n+2)]

	costs=[int(x) for x in ['0']+input().split()]
	costs.append(0)

	for j in range(1,n+2):
		total=mat[j-1][1][1]
		if costs[-j]==1:
			total+=1
		elif costs[-j]==2:
			total-=1

		for i in range(1,n+2):
			jar=costs[i-1]
			if jar==1:
				total+=1
			elif jar==2:
				total-=1

			mat[j][i][1]=total

			if total==0:
				mat[j][i][0]=0
			else:
				mat[j][i][0]=1+min(mat[j-1][i][0],mat[j][i-1][0])

	print(mat[n+1][n+1][0])


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))


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 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)
			support = states.get(-k - state)
			if support != None:
				new = support + i - n
				result = min(result, new)

	answer += str(result+1) + '\n'

print(answer)


from collections import deque
#import snoop

#@snoop
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))


from collections import deque

tc = int(input())
for x in range(tc):
    n = int(input())
    jars =[ 1 if int(x) == 1 else -1 for x in input().split()]

    delta = sum(jars)
    #print("Delta", delta)
    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)
    #print(rp)
    dl = 0
    for i in range(n,-1,-1):
        if i < n:
            dl+=jars[i]
        #print("dl", dl)
        ch = delta-dl
        #print("looking for", ch)
        ra = rp.get(ch)
        if ra != None:
            #print("found", ra)
            steps = min (steps, ra + n - i)
    print(steps)


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:
            #print(d[diff-c]+n-i)
            ans=min(ans,d[diff-c]+n-i)
    if diff in d:
        ans=min(ans,d[diff])
    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
    # print(A)

    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]
    # print(I1)
    # print(I2)
    # print(res)

    for i in range(1,n+1):
        # print(I1[n + i], I2[n - i], I1[n + i] + I2[n - i])
        # print(I1[n - i], I2[n + i], I1[n - i] + I2[n + i])
        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)

    # print(B)

    # print()


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):
        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):
        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)


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)


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)

	print(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)


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()


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
    print(x, y)
    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()


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 == 0:
            continue
        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()


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 == 0:
            continue
        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())):
    if _ == 36:
        n = int(input())
        a = list(map(int, input().split()))
        print(n)
        print(a)
        for idx, i in enumerate(a):
            if i == 2:
                a[idx] = -1
        count = 0
        if sum(a) == 0:
            print(0)
            continue
        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 == 0:
                continue
            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)
    case()


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 ans == 10**9:
        print(2*n)
    else:
        print(ans)
for _ in range(int(input())):
    case()


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)])

    #print(ra, rb)

    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:
            #print(i, t)
            d = min(d, i+t[1])

    print(d)


import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
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 = 0, len(a)
  # while lo + 1 < hi:
  #   mid = (lo + hi) // 2
  #   if a[mid][0] <= x:
  #     lo = mid
  #   else:
  #     hi = mid
  # end = lo
  lo, hi = 0, len(a)
  while lo + 1 < hi:
    mid = (lo + hi) // 2
    if x <= a[mid][0]:
      hi = mid
    else:
      lo = mid
  if 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 - 1, -1, -1):
      if lsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("lsum ans ", ans)
    for i in range(n):
      if rsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("rsum ans ", ans)
    lsum_sorted = sorted([(x, i) for (i, x) in enumerate(lsum)])
    for i in range(n):
      have = sm + rsum[i]
      best_index = binary_search_all(-have, lsum_sorted)
      # print(i, have, best_index, lsum_sorted[best_index])
      if best_index >= 0:
        ans = min(ans, i + lsum_sorted[best_index][1] + 2)
  print(ans)
  # print(sm, lsum_sorted, lsum, rsum)


import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect            #c++ upperbound
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 = 0, len(a)
  # while lo + 1 < hi:
  #   mid = (lo + hi) // 2
  #   if a[mid][0] <= x:
  #     lo = mid
  #   else:
  #     hi = mid
  # end = lo
  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
    # print("lsum ans ", ans)
    for i in range(n):
      if rsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("rsum ans ", ans)
    dic = {}
    for i in range(n):
      if not(lsum[i] in dic):
        dic[lsum[i]] = i
    # print(dic)
    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]
        # print(i, have, best_index)
        ans = min(ans, i + best_index + 2)
  # print(sm, lsum_sorted, lsum, rsum)
  print(ans)


import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect            #c++ upperbound
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 = 0, len(a)
  # while lo + 1 < hi:
  #   mid = (lo + hi) // 2
  #   if a[mid][0] <= x:
  #     lo = mid
  #   else:
  #     hi = mid
  # end = lo
  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 - 1, -1, -1):
      if lsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("lsum ans ", ans)
    for i in range(n):
      if rsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("rsum ans ", ans)
    dic = {}
    for i in range(n):
      if not(lsum[i] in dic):
        dic[lsum[i]] = i
    # print(dic)
    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]
        # print(i, have, best_index)
        ans = min(ans, i + best_index + 2)
  # print(sm, lsum_sorted, lsum, rsum)
  print(ans)


import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
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 = 0, len(a)
  # while lo + 1 < hi:
  #   mid = (lo + hi) // 2
  #   if a[mid][0] <= x:
  #     lo = mid
  #   else:
  #     hi = mid
  # end = lo
  lo, hi = 0, len(a)
  while lo + 1 < hi:
    mid = (lo + hi) // 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 - 1, -1, -1):
      if lsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("lsum ans ", ans)
    for i in range(n):
      if rsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("rsum ans ", ans)
    lsum_sorted = sorted([(x, i) for (i, x) in enumerate(lsum)])
    for i in range(n):
      have = sm + rsum[i]
      best_index = binary_search_all(-have, lsum_sorted)
      # print(i, have, best_index, lsum_sorted[best_index])
      if best_index >= 0:
        ans = min(ans, i + lsum_sorted[best_index][1] + 2)
  print(ans)
  # print(sm, lsum_sorted, lsum, rsum)


import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
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 = 0, len(a)
  # while lo + 1 < hi:
  #   mid = (lo + hi) // 2
  #   if a[mid][0] <= x:
  #     lo = mid
  #   else:
  #     hi = mid
  # end = lo
  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 - 1, -1, -1):
      if lsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("lsum ans ", ans)
    for i in range(n):
      if rsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("rsum ans ", ans)
    lsum_sorted = sorted([(x, i) for (i, x) in enumerate(lsum)])
    for i in range(n):
      have = sm + rsum[i]
      best_index = binary_search_all(-have, lsum_sorted)
      # print(i, have, best_index, lsum_sorted[best_index])
      if best_index >= 0:
        ans = min(ans, i + lsum_sorted[best_index][1] + 2)
  # print(sm, lsum_sorted, lsum, rsum)
  print(ans)


import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect            #c++ upperbound
import math
import heapq
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 = 0, len(a)
  # while lo + 1 < hi:
  #   mid = (lo + hi) // 2
  #   if a[mid][0] <= x:
  #     lo = mid
  #   else:
  #     hi = mid
  # end = lo
  lo, hi = -1, len(a) - 1
  while lo + 1 < hi:
    mid = (lo + hi) // 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 - 1, -1, -1):
      if lsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("lsum ans ", ans)
    for i in range(n):
      if rsum[i] + sm == 0:
        ans = min(ans, i + 1)
        break
    # print("rsum ans ", ans)
    lsum_sorted = sorted([(x, i) for (i, x) in enumerate(lsum)])
    for i in range(n):
      have = sm + rsum[i]
      best_index = binary_search_all(-have, lsum_sorted)
      # print(i, have, best_index, lsum_sorted[best_index])
      if best_index >= 0:
        ans = min(ans, i + lsum_sorted[best_index][1] + 2)
  # print(sm, lsum_sorted, lsum, rsum)
  print(ans)


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())

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:
            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:
                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:
            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:
                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
    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[i] + left[diff_left + diff_right-i]
    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))


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 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
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()


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
# Code
t = intput()

for _ in range(t):
    n = intput()

    a = list(intsput())

    x = a.count(1)
    y = a.count(2)

    diff = x - y

    # flipping
    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)


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)


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):
        #forward
        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
        #reverse
        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))


t = int(input())
for it in range(t):
    n=int(input())
    a=[int(i) for i in input().split()]
    differs=dict()
    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 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)


def R(): return map(int, input().split())
def I(): return int(input())

import math
import sys

f = open('test.txt', 'w')

#f.write('haha')

mod=998244353

for _ in range(I()):
    n=I()
    a=list(R())

    cnt=0

    for i in range(2*n):
        if a[i]==1:
            cnt+=1
        else:
            cnt-=1

    if cnt==0:
        print("0")
        continue

    dr={}
    cntr=0

    dr[0]=0

    for i in range(n,2*n):
        if a[i]==1:
            cntr+=1
        else:
            cntr-=1

        if not (cntr in dr):
            dr[cntr]=i-n+1

    cntl=0

    minj=10**10

    for i in range(n,-1,-1):
        if a[i]==1:
            cntl+=1
        else:
            cntl-=1

        if i==n:
            cntl=0

        if cnt-cntl in dr:
            minj=min(minj,n-i+dr[cnt-cntl])

    print(minj)


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)]
    c2=[[0,i]for i in range(n)]
    for i in range(n):
        if b1[i]==1:
            c1[i][0]=count+1
        else:
            c1[i][0]=count-1
        count=c1[i][0]
    count=0
    for i in range(n):
        if b2[i]==1:
            c2[i][0]=count+1
        else:
            c2[i][0]=count-1
        count=c2[i][0]

    c2.sort()

    c11=[c1[i][0] for i in range(n)]
    c22=[c2[i][0] for i in range(n)]

    if x==1 or x==-1:
        if c11[i]==x or c22[i]==x:
            print(1)
            continue
    ans=2*n
    for i in range(n):
        pos=bisect_left(c22,x-c11[i])
        #print(c11[i],pos)
        if pos<n and c22[pos]==x-c11[i] and c2[pos][1]+i<ans:
            ans=c2[pos][1]+i

    print(ans+2)


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])
        #print(c11[i],pos)
        if pos<n+1 and c22[pos]==x-c11[i] and c2[pos][1]+i<ans:
            ans=c2[pos][1]+i

    print(ans)


for _ in range(input()):
    n=input()
    a=[int(i) for i in raw_input().split()]
    l=a[:n]
    a=a[n:]
    l=l[::-1]
    cr1=[0 for i in range(n)]
    cr2=[0 for i in range(n)]
    for i in range(n):
        if a[i]==1:
            cr1[i]=cr1[i-1]+1
        else:
            cr1[i]=cr1[i-1]-1
    for i in range(n):
        if l[i]==1:
            cr2[i]=cr2[i-1]+1
        else:
            cr2[i]=cr2[i-1]-1
    p=cr1[n-1]+cr2[n-1]
    dp1={}
    dp2={}
    for i in range(-n,n+1):
        dp1[i]=-1
        dp2[i]=-1
    dp1[0]=0
    dp2[0]=0
    for i in range(n):
        if dp1[cr1[i]]==-1:
            dp1[cr1[i]]=i+1
        if dp2[cr2[i]]==-1:
            dp2[cr2[i]]=i+1
    val=2*n
    start=-n
    end=n
    if p>0:
        start=start+p
    else:
        end=end+p
    for i in range(start,end+1):
        if dp1[i]!=-1 and dp2[p-i]!=-1:
            val=min(val,dp1[i]+dp2[p-i])
        if dp1[p-i]!=-1 and dp2[i]!=-1:
            val=min(val,dp1[p-i]+dp2[i])
    print val


for _ in range(input()):
    n=input()
    a=[int(i) for i in raw_input().split()]
    l=a[:n]
    a=a[n:]
    l=l[::-1]
    cr1=[0 for i in range(n)]
    cr2=[0 for i in range(n)]
    for i in range(n):
        if a[i]==1:
            cr1[i]=cr1[i-1]+1
        else:
            cr1[i]=cr1[i-1]-1
    for i in range(n):
        if l[i]==1:
            cr2[i]=cr2[i-1]+1
        else:
            cr2[i]=cr2[i-1]-1
    p=cr1[n-1]+cr2[n-1]
    dp1={}
    dp2={}
    for i in range(-n,n+1):
        dp1[i]=-1
        dp2[i]=-1
    for i in range(n):
        if dp1[cr1[i]]==-1:
            dp1[cr1[i]]=i+1
        if dp2[cr2[i]]==-1:
            dp2[cr2[i]]=i+1
    val=2*n
    start=-n
    end=n
    if p==0:
        print 0
        continue
    if p>0:
        start=start+p
    else:
        end=end-p
    for i in range(start,end+1):
        if dp1[i]!=-1 and dp2[p-i]!=-1:
            val=min(val,dp1[i]+dp2[p-i])
    print val


for _ in range(input()):
    n=input()
    a=[int(i) for i in raw_input().split()]
    l=a[:n]
    a=a[n:]
    l=l[::-1]
    cr1=[0 for i in range(n)]
    cr2=[0 for i in range(n)]
    for i in range(n):
        if a[i]==1:
            cr1[i]=cr1[i-1]+1
        else:
            cr1[i]=cr1[i-1]-1
    for i in range(n):
        if l[i]==1:
            cr2[i]=cr2[i-1]+1
        else:
            cr2[i]=cr2[i-1]-1
    p=cr1[n-1]+cr2[n-1]
    dp1={}
    dp2={}
    for i in range(-n,n+1):
        dp1[i]=-1
        dp2[i]=-1
    for i in range(n):
        if dp1[cr1[i]]==-1:
            dp1[cr1[i]]=i+1
        if dp2[cr2[i]]==-1:
            dp2[cr2[i]]=i+1
    val=2*n
    start=-n
    end=n
    if p==0:
        print 0
        continue
    if p>0:
        start=start+p
    else:
        end=end+p
    for i in range(start,end+1):
        if dp1[i]!=-1 and dp2[p-i]!=-1:
            val=min(val,dp1[i]+dp2[p-i])
        if dp1[p-i]!=-1 and dp2[i]!=-1:
            val=min(val,dp1[p-i]+dp2[i])
    print val


for _ in range(input()):
    n=input()
    a=[int(i) for i in raw_input().split()]
    l=a[:n]
    a=a[n:]
    l=l[::-1]
    cr1=[0 for i in range(n)]
    cr2=[0 for i in range(n)]
    for i in range(n):
        if a[i]==1:
            cr1[i]=cr1[i-1]+1
        else:
            cr1[i]=cr1[i-1]-1
    for i in range(n):
        if l[i]==1:
            cr2[i]=cr2[i-1]+1
        else:
            cr2[i]=cr2[i-1]-1
    p=cr1[n-1]+cr2[n-1]
    dp1={}
    dp2={}
    for i in range(-n,n+1):
        dp1[i]=-1
        dp2[i]=-1
    for i in range(n):
        if dp1[cr1[i]]==-1:
            dp1[cr1[i]]=i+1
        if dp2[cr2[i]]==-1:
            dp2[cr2[i]]=i+1
    val=2*n
    start=-n
    end=n
    if p==0:
        print 0
        continue
    if p>0:
        start=start+p
    else:
        end=end+p
    for i in range(start,end+1):
        if dp1[i]!=-1 and dp2[p-i]!=-1:
            val=min(val,dp1[i]+dp2[p-i])
    print val


for _ in range(input()):
	n=input()
	a=map(int,raw_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
	#print d
	#print p
	z=2*n
	for i in range(n,2*n+1):
		k=d[i]-x
		#print k
		if k in p:
			z=min(z,i+p[k]-n)
			#print k,z
	print z


'''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
'''

from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())
import bisect
t = input()
for _ in range(t):
	n = input()
	a = I()
	a1 = a[n:(2*n)]
	a2 = a[:n]
	# print a1,a2
	for i in range(n):
		if a1[i] == 2:
			a1[i] = 1
		else:
			a1[i] = -1
		if a2[i] == 2:
			a2[i] = 1
		else:
			a2[i] = -1
	a1.reverse()
	pre1,pre2 = [0]*(n+1),[0]*(n+1)
	d = {}
	ans = 0
	for i in range(1,n+1):
		pre1[i] = pre1[i-1] + a1[i-1]
		d[pre1[i]] = i
		if pre1[i] == 0:
			ans = i
	# print d
	for i in range(1,n+1):
		pre2[i] = pre2[i-1] + a2[i-1]
		if -pre2[i] in d:
			ans = max(ans,d[-pre2[i]]+i)
	print 2*n - ans


'''input
1
2
1 2 1 1
'''

from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())
import bisect
t = input()
for _ in range(t):
	n = input()
	a = I()
	a1 = a[n:(2*n)]
	a2 = a[:n]
	for i in range(n):
		if a1[i] == 2:
			a1[i] = 1
		else:
			a1[i] = -1
		if a2[i] == 2:
			a2[i] = 1
		else:
			a2[i] = -1
	a1.reverse()
	# print a1,a2
	pre1,pre2 = [0]*(n+1),[0]*(n+1)
	d = {}
	ans = 0
	for i in range(1,n+1):
		pre1[i] = pre1[i-1] + a1[i-1]
		d[pre1[i]] = i
		if pre1[i] == 0:
			ans = i
	# print d,pre1
	for i in range(1,n+1):
		pre2[i] = pre2[i-1] + a2[i-1]
		if pre2[i] == 0:
			ans = max(ans,i)
		if -pre2[i] in d:
			ans = max(ans,d[-pre2[i]]+i)
	print 2*n - ans


'''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
'''

from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())
import bisect
t = input()
for _ in range(t):
	n = input()
	a = I()
	a1 = a[n:(2*n)]
	a2 = a[:n]
	# print a1,a2
	for i in range(n):
		if a1[i] == 2:
			a1[i] = -1
		if a2[i] == 2:
			a2[i] = -1
	a1.reverse()
	pre1,pre2 = [0]*(n+1),[0]*(n+1)
	d = {}
	ans = 0
	for i in range(1,n+1):
		pre1[i] = pre1[i-1] + a1[i-1]
		d[pre1[i]] = i
		if pre1[i] == 0:
			ans = i
	# print d
	for i in range(1,n+1):
		pre2[i] = pre2[i-1] + a2[i-1]
		if -pre2[i] in d:
			ans = max(ans,d[-pre2[i]]+i)
	print 2*n - ans


#include<stdio.h>
int calculatenjam(int arr1[],int arr2[],int diff)
{
    int i,j,k,l,m,n,flag,cal=0,dummy,bjam,bjam1,sjam,sjam1;
    i=0,j=0,sjam=0,sjam1=0;
    while(diff)
    {
        k=i,l=j,dummy=diff,bjam=0,bjam1=0,sjam=0;sjam1=0;
        int dummy2=diff;
        while(arr1[k]!=1)
        {
            ++dummy;
            bjam++;
            k++;
        }
        while(arr2[l]!=1)
        {
            ++dummy2;
            bjam1++;
            l++;
        }
        if(arr1[k]==1&&arr2[l]==1)
        {
            if(bjam<bjam1&&k<l)
            {
                diff=dummy;
                --diff;
                cal+=(k-i);
                cal++;
                sjam++;
                i=k+1;
            }
            else if(bjam1<bjam&&l<k)
            {
                diff=dummy2;
                --diff;
                cal+=(l-j);
                cal++;
                sjam1++;
                j=l+1;
            }
            else if(bjam<bjam1&&l<k)
            {
                 diff=dummy;
                --diff;
                cal+=(k-i);
                cal++;
                sjam++;
                i=k+1;
            }
            else if(bjam1<bjam&&k<l)
            {

                diff=dummy2;
                --diff;
                cal+=(l-j);
                cal++;
                sjam1++;
                j=l+1;
            }
            else if(bjam==bjam1)
            {
                if(sjam<sjam1)
                {

                    diff=dummy;
                    --diff;
                    cal+=(k-i);
                    cal++;
                    i=k+1;
                }
                else
                {
                    diff=dummy2;
                    --diff;
                    cal+=(l-j);
                    cal++;
                    j=l+1;
                }
            }
            else if(k==l)
            {
                if(bjam<bjam1)
                {
                    diff=dummy;
                    --diff;
                    cal+=(k-i);
                    cal++;
                    i=k+1;
                }
                else
                {
                    diff=dummy2;
                    --diff;
                    cal+=(l-j);
                    cal++;
                    j=l+1;
                }
            }
        }
    }
    return(cal);
}
int calculatepjam(int arr1[],int arr2[],int diff)
{
    int i,j,k,l,m,n,flag,cal=0,dummy,bjam,bjam1,sjam,sjam1;
    if(diff>0)
    {
        i=0,j=0,sjam=0,sjam1=0,bjam=0,bjam1=0;
        while(diff)
        {
            k=i,l=j,dummy=diff,sjam=0,sjam1=0;
            int dummy2=diff;
           while(arr1[k]!=2)
            {
                ++dummy;
                sjam++;
                k++;
            }
            while(arr2[l]!=2)
            {
                ++dummy2;
                sjam1++;
                l++;
            }
            if(arr1[k]==2&&arr2[l]==2)
            {
                if(sjam<sjam1&&k<l)
               {
                diff=dummy;
                --diff;
                cal+=(k-i);
                cal++;
                bjam++;
                i=k+1;
              }
            else if(sjam1<sjam&&l<k)
            {
                diff=dummy2;
                --diff;
                cal+=(l-j);
                cal++;
                bjam1++;
                j=l+1;
            }
            else if(sjam<sjam1&&l<k)
            {
                diff=dummy;
                --diff;
                cal+=(k-i);
                cal++;
                bjam++;
                i=k+1;
            }
            else if(sjam1<sjam&&k<l)
            {

                diff=dummy2;
                --diff;
                cal+=(l-j);
                cal++;
                bjam1++;
                j=l+1;
            }
            else if(sjam==sjam1)
            {
                if(bjam<bjam1)
                {

                    diff=dummy;
                    --diff;
                    cal+=(k-i);
                    cal++;
                    i=k+1;
                }
                else
                {
                    diff=dummy2;
                    --diff;
                    cal+=(l-j);
                    cal++;
                    j=l+1;
                }
            }
            else if(k==l)
            {
                if(sjam<sjam1)
                {
                    diff=dummy;
                    --diff;
                    cal+=(k-i);
                    cal++;
                    i=k+1;
                }
                else
                {
                    diff=dummy2;
                    --diff;
                    cal+=(l-j);
                    cal++;
                    j=l+1;
                }
            }
            }
        }
    }
    return(cal);
}
int main()
{
    int i,j,t,n,arr1[100005],arr2[100005],s1jam,b1jam,s2jam,b2jam;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%d",&n);
        s1jam=0,b1jam=0,s2jam=0,b2jam=0;
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr1[n-1-j]);
            if(arr1[n-1-j]==1)
            s1jam++;
            else
            b1jam++;
        }
        for(j=0;j<n;j++)
        {
            scanf("%d",&arr2[j]);
            if(arr2[j]==1)
            s2jam++;
            else
            b2jam++;
        }
        int diff=(b2jam+b1jam)-(s1jam+s2jam);
        if(diff==0)
        printf("0\n");
        else if(diff<0)
        {
            diff=(s1jam+s2jam)-(b2jam+b1jam);
            printf("%d\n",calculatenjam(arr1,arr2,diff));
        }
        else
        printf("%d\n",calculatepjam(arr1,arr2,diff));
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int t,n,strawberry,blueberry,l,find,total,min;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int leftpos[n+1],rightpos[n+1],leftneg[n+1],rightneg[n+1];l=2*n,total=0;
        int berry[l];strawberry=0,blueberry=0,min=l;
        for(int i=0;i<l;i++)
        {
            scanf("%d",&berry[i]);
            if(berry[i]==1) strawberry++;
            else blueberry++;
            if(i<=n){leftneg[i]=-1,leftpos[i]=-1,rightneg[i]=-1,rightpos[i]=-1;}
        }
        if((strawberry==0)|(blueberry==0)){printf("%d\n",l);continue;}
        else if(strawberry==blueberry){printf("0\n");continue;}
        find=(strawberry-blueberry);
        for(int i=n-1;i>=0;i--)
        {
            if(berry[i]==1)total++;
            else total--;
            if((total>=0)&(leftpos[total]==-1))
            leftpos[total]=i;
            if((total<0)&(leftneg[(-1*total)]==-1))
            leftneg[(-1*total)]=i;
        }
        total=0;
        for(int i=n;i<l;i++)
        {
            if(berry[i]==1)total++;
            else total--;
            if((total>=0)&(rightpos[total]==-1))
            rightpos[total]=i;
            if((total<0)&(rightneg[(-1*total)]==-1))
            rightneg[(-1*total)]=i;
        }
        total=0;
        for(int i=n-1;i>=0;i--)
        {
            if(berry[i]==1) total++;
            else total--;
            if(total==find)
            min=(n-i)<min?(n-i):min;
            else
            {
                if((find-total>0)&(find-total<n+1))
                {
                    int diff=(find-total);
                    if(rightpos[diff]!=-1)
                    {
                        min=(-i+rightpos[diff]+1)<min?(-i+rightpos[diff]+1):min;
                    }
                }
                else if((find-total<0)&(total-find<n+1))
                {
                    int diff=-1*(find-total);
                    if(rightneg[diff]!=-1)
                    {
                        min=(-i+rightneg[diff]+1)<min?(-i+rightneg[diff]+1):min;
                    }
                }
            }
        }
        total=0;
        for(int i=n;i<l;i++)
        {
            if(berry[i]==1) total++;
            else total--;
            if(total==find)
            min=(i-n+1)<min?(i-n+1):min;
            else
            {
                if((find-total>0)&(find-total<n+1))
                {
                    int diff=(find-total);
                    if(leftpos[diff]!=-1)
                    {
                        min=(i-leftpos[diff]+1)<min?(i-leftpos[diff]+1):min;
                    }
                }
                else if((find-total<0)&(total-find<n+1))
                {
                    int diff=-1*(find-total);
                    if(leftneg[diff]!=-1)
                    {
                        min=(i-leftneg[diff]+1)<min?(i-leftneg[diff]+1):min;
                    }
                }
            }
        }
        printf("%d\n",min);
    }
}