for _ in range(int(input())):
n=int(input())
l=list(map(int, input().split()))
a=l[:n]
b=l[n:]
d={}
x=0
y=0
for i in range(n):
if a[i]==1:
x+=1
else:
y+=1
dif=x-y
d[dif]=i
ans=2*n
x=0
y=0
for i in range(n-1,-1,-1):
if b[i]==1:
x+=1
else:
y+=1
dif=y-x
if dif in d:
ans=min(ans, i+n-d[dif]-1)
if 0 in d:
ans=min(ans, n+n-d[0]-1)
if x==y:
ans=min(ans,n)
l=l[::-1]
a=l[:n]
b=l[n:]
d={}
x=0
y=0
for i in range(n):
if a[i]==1:
x+=1
else:
y+=1
dif=x-y
d[dif]=i
x=0
y=0
for i in range(n-1,-1,-1):
if b[i]==1:
x+=1
else:
y+=1
dif=y-x
if dif in d:
ans=min(ans, i+n-d[dif]-1)
if 0 in d:
ans=min(ans, n+n-d[0]-1)
if x==y:
ans=min(ans,n)
print(ans)
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(0)
#define endl '\n'
#define int long long
#define ar array<int, 2>
#define arr array<int, 3>
const int N = 2e5 + 5, M = 2 * N;
const int inf = 0x3f3f3f3f;
int mod = 998244353; //1e9+7;
int t, n, m, k;
signed main()
{
ios;
#ifdef DEBUG
freopen("../1.in", "r", stdin);
#endif
// 那时候刷的可起劲了。这题。
// 主要是1 2 换成-1 1 这样的设定。
// 然后就是贪心的哈希。。和类似两数之和的两个集合的配对。。
// 有点类似二分图。。
cin >> t;
while (t--)
{
cin >> n;
vector<int> sum(2 * n + 1);
map<int, int> mp;
mp[0] = 0;
for (int i = 1; i <= 2 * n; ++i)
{
int x;
cin >> x;
sum[i] = sum[i - 1] + (x > 1 ? -1 : 1);
if (i <= n)
mp[sum[i]] = i;
}
int ans = 2 * n;
for (int i = n; i <= 2 * n; ++i)
{
int tmp = sum[i] - sum[2 * n];
if (mp.count(tmp))
ans = min(i - mp[tmp], ans);
}
cout << ans << endl;
}
};
215. Kth Largest Element in an Array | 198. House Robber |
153. Find Minimum in Rotated Sorted Array | 150. Evaluate Reverse Polish Notation |
144. Binary Tree Preorder Traversal | 137. Single Number II |
130. Surrounded Regions | 129. Sum Root to Leaf Numbers |
120. Triangle | 102. Binary Tree Level Order Traversal |
96. Unique Binary Search Trees | 75. Sort Colors |
74. Search a 2D Matrix | 71. Simplify Path |
62. Unique Paths | 50. Pow(x, n) |
43. Multiply Strings | 34. Find First and Last Position of Element in Sorted Array |
33. Search in Rotated Sorted Array | 17. Letter Combinations of a Phone Number |
5. Longest Palindromic Substring | 3. Longest Substring Without Repeating Characters |
1312. Minimum Insertion Steps to Make a String Palindrome | 1092. Shortest Common Supersequence |
1044. Longest Duplicate Substring | 1032. Stream of Characters |
987. Vertical Order Traversal of a Binary Tree | 952. Largest Component Size by Common Factor |
212. Word Search II | 174. Dungeon Game |