#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define hell 100000000000000007 //10e18+7
#define mod 100000007 //10e9+7
const ll N = 300; // 1e6+7

ll binpow(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll inv(ll a) {
    a %= mod;
    if (a < 0) a += mod;
    ll b = mod, u = 0, v = 1;
    while (a) {
        ll t = b / a;
        b -= t * a; swap(a, b);
        u -= t * v; swap(u, v);
    }
    if (u < 0) u += mod;
    return u;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("q1.txt", "r", stdin);
    freopen("pelu13.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;
        cin >> n;

        int a[2 * n + 1] = {0};
        for (int i = 1; i <= 2 * n; i++)
        {
            int x;
            cin >> x;
            if (x == 1)
                a[i] = -1;
            else
                a[i] = 1;
        }
        for (int i = 2; i <= n; i++)
            a[i] += a[i - 1];
        for (int i = 2 * n - 1; i >= n + 1; i--)
            a[i] += a[i + 1];

        unordered_map <int, int> mp1;
        for (int i = n + 1; i <= 2 * n; i++)
        {
            if (mp1[a[i]] == 0)
                mp1[a[i]] = i;
        }
        int ans = 2 * n;
        for (int i = 1; i <= n; i++)
        {
            if (mp1[a[i] * -1] == 0)
                continue;
            ans = min(ans, mp1[a[i] * -1] - i - 1);
        }
        cout << ans << "\n";
    }

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define hell 100000000000000007 //10e18+7
#define mod 100000007 //10e9+7
const ll N = 300; // 1e6+7

ll binpow(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll inv(ll a) {
    a %= mod;
    if (a < 0) a += mod;
    ll b = mod, u = 0, v = 1;
    while (a) {
        ll t = b / a;
        b -= t * a; swap(a, b);
        u -= t * v; swap(u, v);
    }
    if (u < 0) u += mod;
    return u;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("q1.txt", "r", stdin);
    freopen("pelu13.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll arr[2 * n + 1];
        for (ll i = 1; i <= (2 * n); i++)
        {
            ll x;
            cin >> x;
            if (x == 1)
                arr[i] = 1;
            else
                arr[i] = -1;
        }
        for (ll i = 2; i <= (n); i++)
            arr[i] += arr[i - 1];
        for (ll i = (2 * n - 1); i >= (n + 1); i--)
            arr[i] += (arr[i + 1]);
        ll ans = 2 * n;
        unordered_map<ll, ll>m1;
        for (ll i = n + 1; i <= (2 * n); i++)
        {
            if (m1.find(arr[i]) == m1.end())
            {
                m1[arr[i]] = i;
            }
        }
        for (ll i = 1; i <= n; i++)
        {
            if (m1.find((-arr[i])) == m1.end())
                continue;
            else
            {
                ans = min(ans, m1[-arr[i]] - i - 1);
            }
        }
        cout << ans << endl;

    }

}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
//#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair<int, int>
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向，输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向，输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 4e5 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int n, T;
ll a[maxn], b[maxn], num[maxn];
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%d", &n);
        ll x = 0;
        for(int i = 0 ; i <= n * 8 ; ++ i) b[i] = num[i+200000] = 0;
        for(int i = 1 ; i <= n * 2 ; ++ i){
            scanf("%lld", &a[i]);
            if(a[i] == 1) x ++;
        }
        ll ex = x - (2*n-x);
        if(x == n){
            cout << "0" << endl;
            continue;
        }
        ll ans = 1e6;
        if(a[n] == 1) b[n] = 1;
        else b[n] = -1;
        if(a[n+1] == 1) b[n+1] = 1;
        else b[n+1] = -1;
        for(int i = n - 1 ; i >= 1 ; -- i){
            if(a[i] == 1) b[i]=b[i+1]+1;
            else b[i]=b[i+1]-1;
        }
        for(int i = 1 ; i <= n ; ++ i) num[b[i]+200000] = max(num[b[i]+200000],1LL*i);
        for(int i = n + 2 ; i <= n * 2 ; ++ i){
            if(a[i] == 1) b[i]=b[i-1]+1;
            else b[i]=b[i-1]-1;
        }
        //if(num[ex+20000]) ans = n
        if(num[ex+200000]) ans = n - num[ex+200000]+1;
        int t = 0;
        for(int i = n + 1 ; i <= n * 2 ; ++ i){
            if(b[i] == ex) ans = min(ans, 1LL*i-n);
            if(num[ex-b[i]+200000]){
                //cout << i << ' ' << num[ex-b[i]+100000] << endl;
                ans = min(ans, i - num[ex-b[i]+200000] + 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
//#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair<int, int>
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向，输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向，输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 4e5 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int n, T;
ll a[maxn], b[maxn];
map<int,int> num;
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%d", &n);
        ll x = 0;
        for(int i = 0 ; i <= n * 4 ; ++ i) b[i] = 0; num.clear();
        for(int i = 1 ; i <= n * 2 ; ++ i){
            scanf("%lld", &a[i]);
            if(a[i] == 1) x ++;
        }
        ll ex = x - (2*n-x);
        if(x == n){
            cout << "0" << endl;
            continue;
        }
        ll ans = 1e6;
        if(a[n] == 1) b[n] = 1;
        else b[n] = -1;
        if(a[n+1] == 1) b[n+1] = 1;
        else b[n+1] = -1;
        for(int i = n - 1 ; i >= 1 ; -- i){
            if(a[i] == 1) b[i]=b[i+1]+1;
            else b[i]=b[i+1]-1;
        }
        for(int i = 1 ; i <= n ; ++ i) num[b[i]] = max(num[b[i]],i);
        for(int i = n + 2 ; i <= n * 2 ; ++ i){
            if(a[i] == 1) b[i]=b[i-1]+1;
            else b[i]=b[i-1]-1;
        }
        //if(num[ex+20000]) ans = n
        if(num.count(ex) != 0) ans = n - num[ex]+1;
        int t = 0;
        for(int i = n + 1 ; i <= n * 2 ; ++ i){
            if(b[i] == ex) ans = min(ans, 1LL*i-n);
            if(num.count(ex-b[i]) != 0){
                //cout << i << ' ' << num[ex-b[i]+100000] << endl;
                ans = min((int)ans, i - num[ex-b[i]] + 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
//#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair<int, int>
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向，输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向，输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 4e5 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int n, T;
int a[maxn], b[maxn], num[maxn];
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%d", &n);
        int x = 0;
        for(int i = 0 ; i <= n * 8 ; ++ i) b[i] = num[i+200000] = 0;
        for(int i = 1 ; i <= n * 2 ; ++ i){
            scanf("%d", &a[i]);
            if(a[i] == 1) x ++;
        }
        int ex = x - (2*n-x);
        if(x == n){
            cout << "0" << endl;
            continue;
        }
        int ans = 1e6;
        if(a[n] == 1) b[n] = 1;
        else b[n] = -1;
        if(a[n+1] == 1) b[n+1] = 1;
        else b[n+1] = -1;
        for(int i = n - 1 ; i >= 1 ; -- i){
            if(a[i] == 1) b[i]=b[i+1]+1;
            else b[i]=b[i+1]-1;
        }
        for(int i = 1 ; i <= n ; ++ i) num[b[i]+200000] = max(num[b[i]+200000],i);
        for(int i = n + 2 ; i <= n * 2 ; ++ i){
            if(a[i] == 1) b[i]=b[i-1]+1;
            else b[i]=b[i-1]-1;
        }
        for(int i = n + 1 ; i <= n * 2 ; ++ i){
            if(num[ex-b[i]+200000]){
                //cout << i << ' ' << num[ex-b[i]+100000] << endl;
                ans = min(ans, i - num[ex-b[i]+200000] + 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
//#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair<int, int>
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向，输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向，输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 4e5 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int n, T;
ll a[maxn], b[maxn], num[maxn];
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%d", &n);
        ll x = 0;
        for(int i = 0 ; i <= n * 8 ; ++ i) b[i] = num[i+200000] = 0;
        for(int i = 1 ; i <= n * 2 ; ++ i){
            scanf("%lld", &a[i]);
            if(a[i] == 1) x ++;
        }
        ll ex = x - (2*n-x);
        if(x == n){
            cout << "0" << endl;
            continue;
        }
        ll ans = 1e6;
        if(a[n] == 1) b[n] = 1;
        else b[n] = -1;
        if(a[n+1] == 1) b[n+1] = 1;
        else b[n+1] = -1;
        for(int i = n - 1 ; i >= 1 ; -- i){
            if(a[i] == 1) b[i]=b[i+1]+1;
            else b[i]=b[i+1]-1;
        }
        for(int i = 1 ; i <= n ; ++ i) num[b[i]+200000] = max(num[b[i]+200000],1LL*i);
        for(int i = n + 2 ; i <= n * 2 ; ++ i){
            if(a[i] == 1) b[i]=b[i-1]+1;
            else b[i]=b[i-1]-1;
        }
        //if(num[ex+20000]) ans = n
        if(num[ex+200000]) ans = n - num[ex+200000]+1;
        int t = 0;
        for(int i = n + 1 ; i <= n * 2 ; ++ i){
            t += b[i];
            if(t == ex) ans = min(ans, 1LL*i-n);
            if(num[ex-b[i]+200000]){
                //cout << i << ' ' << num[ex-b[i]+100000] << endl;
                ans = min(ans, i - num[ex-b[i]+200000] + 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
//#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair<int, int>
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向，输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向，输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 4e5 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int n, T;
ll a[maxn], b[maxn], num[maxn];
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%d", &n);
        ll x = 0;
        for(int i = 0 ; i <= n * 8 ; ++ i) b[i] = num[i+200000] = 0;
        for(int i = 1 ; i <= n * 2 ; ++ i){
            scanf("%lld", &a[i]);
            if(a[i] == 1) x ++;
        }
        ll ex = x - (2*n-x);
        if(x == n){
            cout << "0" << endl;
            continue;
        }
        ll ans = 1e6;
        if(a[n] == 1) b[n] = 1;
        else b[n] = -1;
        if(a[n+1] == 1) b[n+1] = 1;
        else b[n+1] = -1;
        for(int i = n - 1 ; i >= 1 ; -- i){
            if(a[i] == 1) b[i]=b[i+1]+1;
            else b[i]=b[i+1]-1;
        }
        for(int i = 1 ; i <= n ; ++ i) num[b[i]+200000] = max(num[b[i]+200000],1LL*i);
        for(int i = n + 2 ; i <= n * 2 ; ++ i){
            if(a[i] == 1) b[i]=b[i-1]+1;
            else b[i]=b[i-1]-1;
        }
        //if(num[ex+20000]) ans = n
        if(num[ex+200000]) ans = n - num[ex+200000]+1;
        for(int i = n + 1 ; i <= n * 2 ; ++ i){
            if(num[ex-b[i]+200000]){
                //cout << i << ' ' << num[ex-b[i]+100000] << endl;
                ans = min(ans, i - num[ex-b[i]+200000] + 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
//#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair<int, int>
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向，输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向，输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 4e5 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int n, T;
ll a[maxn], b[maxn];
map<int,int> num;
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%d", &n);
        ll x = 0;
        for(int i = 0 ; i <= n * 4 ; ++ i) b[i] = 0; num.clear();
        for(int i = 1 ; i <= n * 2 ; ++ i){
            scanf("%lld", &a[i]);
            if(a[i] == 1) x ++;
        }
        ll ex = x - (2*n-x);
        if(x == n){
            cout << "0" << endl;
            continue;
        }
        ll ans = 1e6;
        if(a[n] == 1) b[n] = 1;
        else b[n] = -1;
        if(a[n+1] == 1) b[n+1] = 1;
        else b[n+1] = -1;
        for(int i = n - 1 ; i >= 1 ; -- i){
            if(a[i] == 1) b[i]=b[i+1]+1;
            else b[i]=b[i+1]-1;
        }
        for(int i = 1 ; i <= n ; ++ i) num[b[i]] = max(num[b[i]],i);
        for(int i = n + 2 ; i <= n * 2 ; ++ i){
            if(a[i] == 1) b[i]=b[i-1]+1;
            else b[i]=b[i-1]-1;
        }
        //if(num[ex+20000]) ans = n
        if(num[ex]) ans = n - num[ex]+1;
        int t = 0;
        for(int i = n + 1 ; i <= n * 2 ; ++ i){
            if(b[i] == ex) ans = min(ans, 1LL*i-n);
            if(num.count(ex-b[i])){
                //cout << i << ' ' << num[ex-b[i]+100000] << endl;
                ans = min((int)ans, i - num[ex-b[i]] + 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
//#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair<int, int>
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向，输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向，输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 4e5 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int n, T;
ll a[maxn], b[maxn], num[maxn];
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%d", &n);
        ll x = 0;
        for(int i = 0 ; i <= n * 8 ; ++ i) b[i] = 0;
        clr(num, 0);
        for(int i = 1 ; i <= n * 2 ; ++ i){
            scanf("%lld", &a[i]);
            if(a[i] == 1) x ++;
        }
        ll ex = x - (2*n-x);
        if(x == n){
            cout << "0" << endl;
            continue;
        }
        ll ans = 1e6;
        if(a[n] == 1) b[n] = 1;
        else b[n] = -1;
        if(a[n+1] == 1) b[n+1] = 1;
        else b[n+1] = -1;
        for(int i = n - 1 ; i >= 1 ; -- i){
            if(a[i] == 1) b[i]=b[i+1]+1;
            else b[i]=b[i+1]-1;
        }
        for(int i = 1 ; i <= n ; ++ i) num[b[i]+200000] = max(num[b[i]+200000],1LL*i);
        for(int i = n + 2 ; i <= n * 2 ; ++ i){
            if(a[i] == 1) b[i]=b[i-1]+1;
            else b[i]=b[i-1]-1;
        }
        //if(num[ex+20000]) ans = n
        if(num[ex+200000]) ans = n - num[ex+200000]+1;
        int t = 0;
        for(int i = n + 1 ; i <= n * 2 ; ++ i){
            if(b[i] == ex) ans = min(ans, 1LL*i-n);
            if(num[ex-b[i]+200000]){
                //cout << i << ' ' << num[ex-b[i]+100000] << endl;
                ans = min(ans, i - num[ex-b[i]+200000] + 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
//#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair<int, int>
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向，输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向，输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 4e5 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int n, T;
ll a[maxn], b[maxn], num[maxn];
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%d", &n);
        ll x = 0;
        for(int i = 0 ; i <= n * 8 ; ++ i) b[i] = num[i+200000] = 0;
        for(int i = 1 ; i <= n * 2 ; ++ i){
            scanf("%lld", &a[i]);
            if(a[i] == 1) x ++;
        }
        ll ex = x - (2*n-x);
        if(x == n){
            cout << "0" << endl;
            continue;
        }
        ll ans = 1e6;
        if(a[n] == 1) b[n] = 1;
        else b[n] = -1;
        if(a[n+1] == 1) b[n+1] = 1;
        else b[n+1] = -1;
        for(int i = n - 1 ; i >= 1 ; -- i){
            if(a[i] == 1) b[i]=b[i+1]+1;
            else b[i]=b[i+1]-1;
        }
        for(int i = 1 ; i <= n ; ++ i) num[b[i]+200000] = max(num[b[i]+200000],1LL*i);
        for(int i = n + 2 ; i <= n * 2 ; ++ i){
            if(a[i] == 1) b[i]=b[i-1]+1;
            else b[i]=b[i-1]-1;
        }
        //if(num[ex+20000]) ans = n
        if(num[ex+200000]) ans = n - num[ex+200000]+1;
        int t = 0;
        for(int i = n + 1 ; i <= n * 2 ; ++ i){
            t += b[i];
            if(t == ex) ans = min(ans, i-n);
            if(num[ex-b[i]+200000]){
                //cout << i << ' ' << num[ex-b[i]+100000] << endl;
                ans = min(ans, i - num[ex-b[i]+200000] + 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<bitset>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
//#define lb long double
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ull unsigned long long
#define endl '\n'
#define clr(a, b) memset(a, b, sizeof(a))
#define lowbit(x) x & -x
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define PB push_back
#define POP pop_back
#define max_ll 9223372036854775807
#define PII pair<int, int>
#define random(x) (rand()%x)
//srand((ll)time(0));
//freopen("E://one.txt","r",stdin); //输入重定向，输入数据将从in.txt文件中读取
//freopen("E://oneout.txt","w",stdout); //输出重定向，输出数据将保存在out.txt文件中
//std::ios::sync_with_stdio(false);
const double eps = 1e-14;
const double pi = acos(-1);
const int maxn = 2e5 + 100;//30000000
const int maxm = 2e5 + 10;
const ll mod = 1e9 + 7;
const int hash_mod = 19260817;
const int inf = 2147483647;
int n, T;
int a[maxn], b[maxn], num[maxn];
int main()
{
    scanf("%d", &T);
    while(T --){
        scanf("%d", &n);
        int x = 0;
        for(int i = 0 ; i <= n * 4 ; ++ i) b[i] = num[i+100000] = 0;
        for(int i = 1 ; i <= n * 2 ; ++ i){
            scanf("%d", &a[i]);
            if(a[i] == 1) x ++;
        }
        int ex = x - (2*n-x);
        if(x == n){
            cout << "0" << endl;
            continue;
        }
        int ans = 1e6;
        if(a[n] == 1) b[n] = 1;
        else b[n] = -1;
        if(a[n+1] == 1) b[n+1] = 1;
        else b[n+1] = -1;
        for(int i = n - 1 ; i >= 1 ; -- i){
            if(a[i] == 1) b[i]=b[i+1]+1;
            else b[i]=b[i+1]-1;
        }
        for(int i = 1 ; i <= n ; ++ i) num[b[i]+100000] = max(num[b[i]+100000],i);
        for(int i = n + 2 ; i <= n * 2 ; ++ i){
            if(a[i] == 1) b[i]=b[i-1]+1;
            else b[i]=b[i-1]-1;
        }
        for(int i = n + 1 ; i <= n * 2 ; ++ i){
            if(num[ex-b[i]+100000]){
                ans = min(ans, i - num[ex-b[i]+100000] + 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int a[N], cnt[2];
int32_t main()
{
    int t=in();
    while(t--){
        int n=in();
        for(int i=1; i<=2*n; i++) a[i]=in();
        cnt[1]=cnt[2]=0;
        map<int, int> mp;
        mp[0]=2*n+1;
        for(int i=2*n; i>=n+1; i--){
            cnt[a[i]]++;
            int d=cnt[1]-cnt[2];
            mp[d]=i;
        }
        int ans=mp[0]-1;
        cnt[1]=cnt[2]=0;
        for(int i=1; i<=n; i++){
            cnt[a[i]]++;
            int d=cnt[1]-cnt[2];
            if(mp.find(-d)!=mp.end()){
                int nw=mp[-d]-i-1;
                ans=min(ans, nw);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int a[N], cnt[2];
int32_t main()
{
    int t=in();
    while(t--){
        int n=in();
        for(int i=1; i<=2*n; i++) a[i]=in();
        cnt[1]=cnt[2]=0;
        map<int, int> mp;
        mp[0]=2*n+1;
        for(int i=2*n; i>=n+1; i--){
            cnt[a[i]]++;
            int d=cnt[1]-cnt[2];
            mp[d]=i;
        }
        int ans=mp[0]-1;
        cnt[1]=cnt[2]=0;
        for(int i=1; i<=n; i++){
            cnt[a[i]]++;
            int d=cnt[2]-cnt[1];
            if(mp.find(d)!=mp.end()){
                int nw=mp[d]-i-1;
                ans=min(ans, nw);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int a[N], cnt[2];
int32_t main()
{
    int t=in();
    while(t--){
        int n=in();
        for(int i=1; i<=2*n; i++) a[i]=in();
        cnt[1]=cnt[2]=0;
        map<int, int> mp;
        mp[0]=2*n+1;
        for(int i=2*n; i>=n+1; i--){
            cnt[a[i]]++;
            int d=cnt[1]-cnt[2];
            mp[d]=i;
        }
        int ans=mp[0]-1;
        cnt[1]=cnt[2]=0;
        for(int i=1; i<=n; i++){
            cnt[a[i]]++;
            int d=cnt[2]-cnt[1];
            if(mp.find(d)!=mp.end()){
                int p=mp[d];
                int nw=p-i-1;
                ans=min(ans, nw);
            }
        }
        cout<<ans<<nl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int a[N], cnt[2];
int32_t main()
{
    int t=in();
    while(t--){
        int n=in();
        for(int i=1; i<=2*n; i++) a[i]=in();
        cnt[1]=cnt[2]=0;
        map<int, int> mp;
        mp[0]=2*n+1;
        for(int i=2*n; i>=n+1; i--){
            cnt[a[i]]++;
            int d=cnt[1]-cnt[2];
            mp[d]=i;
        }
        int ans=mp[0]-1;
        cnt[1]=cnt[2]=0;
        for(int i=1; i<=n; i++){
            cnt[a[i]]++;
            int d=cnt[2]-cnt[1];
            if(mp.find(d)!=mp.end()){
                int p=mp[d];
                int nw=p-i-1;
                ans=min(ans, nw);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int a[N], cnt[2];
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        for(int i=1; i<=2*n; i++) cin>>a[i];
        cnt[1]=cnt[2]=0;
        map<int, int> mp;
        mp[0]=2*n+1;
        for(int i=2*n; i>=n+1; i--){
            cnt[a[i]]++;
            cerr<<cnt[1]<<' '<<cnt[2];
            int d=cnt[1]-cnt[2];
            mp[d]=i;
        }
        int ans=mp[0]-1;
        cnt[1]=cnt[2]=0;
        for(int i=1; i<=n; i++){
            cnt[a[i]]++;
            cerr<<cnt[1]<<' '<<cnt[2];
            int d=cnt[2]-cnt[1];
            if(mp.find(d)!=mp.end()){
                int p=mp[d];
                int nw=p-i-1;
                ans=min(ans, nw);
            }
        }
        cout<<ans<<nl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int a[N], cnt[2];
int32_t main()
{
    int t=in();
    while(t--){
        int n=in();
        for(int i=1; i<=2*n; i++) cin>>a[i];
        cnt[1]=cnt[2]=0;
        map<int, int> mp;
        mp[0]=2*n+1;
        for(int i=2*n; i>=n+1; i--){
            cnt[a[i]]++;
            int d=cnt[1]-cnt[2];
            mp[d]=i;
        }
        int ans=mp[0]-1;
        cnt[1]=cnt[2]=0;
        for(int i=1; i<=n; i++){
            cnt[a[i]]++;
            int d=cnt[2]-cnt[1];
            if(mp.find(d)!=mp.end()){
                int p=mp[d];
                int nw=p-i-1;
                ans=min(ans, nw);
            }
        }
        cout<<ans<<nl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int a[N], cnt[2];
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        for(int i=1; i<=2*n; i++) cin>>a[i];
        cnt[1]=cnt[2]=0;
        map<int, int> mp;
        mp[0]=2*n+1;
        for(int i=2*n; i>=n+1; i--){
            cnt[a[i]]++;
            int d=cnt[1]-cnt[2];
            mp[d]=i;
        }
        int ans=mp[0]-1;
        cnt[1]=cnt[2]=0;
        for(int i=1; i<=n; i++){
            cnt[a[i]]++;
            int d=cnt[2]-cnt[1];
            if(mp.find(d)!=mp.end()){
                int p=mp[d];
                int nw=p-i-1;
                ans=min(ans, nw);
            }
        }
        cout<<ans<<nl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d",&a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

int a[N], cnt[3];
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t; cin>>t;
    while(t--){
        int n; cin>>n;
        for(int i=1; i<=2*n; i++) cin>>a[i];
        cnt[1]=cnt[2]=0;
        map<int, int> mp;
        mp[0]=2*n+1;
        for(int i=2*n; i>=n+1; i--){
            cnt[a[i]]++;
            int d=cnt[1]-cnt[2];
            mp[d]=i;
        }
        int ans=mp[0]-1;
        cnt[1]=cnt[2]=0;
        for(int i=1; i<=n; i++){
            cnt[a[i]]++;
            int d=cnt[2]-cnt[1];
            if(mp.find(d)!=mp.end()){
                int p=mp[d];
                int nw=p-i-1;
                ans=min(ans, nw);
            }
        }
        cout<<ans<<nl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
int t,n;
int a[200005],sum[200005];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n;
		n*=2;
		map<int,int>mp1,mp2;
		int s1=0,s2=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]==1)
			s1++;
			else
			s2++;
		}
		memset(sum,0,sizeof(sum));
		for(int i=n/2+1;i<=n;i++)
		{
			if(a[i]==1)
			{
				sum[i]=sum[i-1]+1;
			}
			else
			{
				sum[i]=sum[i-1]-1;
			}
			if(sum[i]!=0&&!mp1[sum[i]])
			{
				mp1[sum[i]]=i;
			}
		}
		memset(sum,0,sizeof(sum));
		for(int i=n/2;i>=1;i--)
		{
			if(a[i]==1)
			{
				sum[i]=sum[i+1]+1;
			}
			else
			{
				sum[i]=sum[i+1]-1;
			}
			if(sum[i]!=0&&!mp2[sum[i]])
			{
				mp2[sum[i]]=i;
			}
		}
		if(s1==s2)
		{
			cout<<0<<endl;
		}
		else if(s1>s2)
		{
			int ans=inf;
			int cz=s1-s2;
			if(mp1[cz])
			{
				ans=min(ans,mp1[cz]-n/2);
			}
			if(mp2[cz])
			{
				ans=min(ans,n/2-mp2[cz]+1);
			}
			for(int i=1;i<cz;i++)
			{
				if(mp1[i]&&mp2[cz-i])
				{
					ans=min(ans,mp1[i]-mp2[cz-i]+1);
				}
			}
			cout<<ans<<endl;
		}
		else
		{
			int ans=inf;
			int cz=s2-s1;
			if(mp1[-cz])
			{
				ans=min(ans,mp1[-cz]-n/2);
			}
			if(mp2[-cz])
			{
				ans=min(ans,n/2-mp2[-cz]+1);
			}
			for(int i=1;i<cz;i++)
			{
				if(mp1[-i]&&mp2[-cz+i])
				{
					ans=min(ans,mp1[-i]-mp2[-cz+i]+1);
				}
			}
			cout<<ans<<endl;
		}
	}

}


#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 400005
using namespace std;
int t,n;
int a[maxn];
int s1[maxn],s2[maxn];
inline int read()
{
    int num=0, w=0;
    char ch=0;
    while (!isdigit(ch)) {
        w|=ch=='-';
        ch = getchar();
    }
    while (isdigit(ch)) {
        num = (num<<3) + (num<<1) + (ch^48);
        ch = getchar();
    }
    return w? -num: num;
}
vector<int>v[maxn];
int main()
{
	t=read();
	while(t--)
	{
		map<int,int>mp,mp2;
		memset(s1,0,sizeof(s1));
		memset(s2,0,sizeof(s2));
		n=read();
		int sum1=0,sum2=0;
		for(int i=1;i<=2*n;i++)
		{
			a[i]=read();
			if(a[i]==1)
			sum1++;
			else
			sum2++;
		}
		for(int i=n+1;i<=2*n;i++)
		{
			if(a[i]==1)
			{
				s1[i]=s1[i-1]+1;

			}
			else
			s1[i]=s1[i-1]-1;
			if(s1[i]!=0&&!mp[s1[i]])
			{
				mp[s1[i]]=i;
			}
		}
		for(int i=n;i>=1;i--)
		{
			if(a[i]==1)
			{
				s2[i]=s2[i+1]+1;
			}
			else
			{
				s2[i]=s2[i+1]-1;
			}
			if(s2[i]!=0&&!mp2[s2[i]])
			{
				mp2[s2[i]]=i;
			}
		}
		int ans=inf;
		if(sum1==sum2)
		{
			cout<<0<<endl;
			continue;
		}
		else if(sum1>sum2)
		{
			int cz=sum1-sum2;
			if(mp[cz])
			ans=min(ans,mp[cz]-n);
			if(mp2[cz])
			{
				ans=min(ans,n-mp2[cz]+1);
			}
			for(int i=1;i<=sum1-sum2;i++)
			{
				if(mp[i]&&mp[cz-i])
				ans=min(ans,mp[i]-mp2[cz-i]+1);
			}
		}
		else
		{
			int cz=sum1-sum2;
			if(mp[cz])
			ans=min(ans,mp[cz]-n);
			if(mp2[cz])
			{
				ans=min(ans,n-mp2[cz]+1);
			}
			for(int i=1;i<=sum2-sum1;i++)
			{
				if(mp[-i]&&mp[-cz+i])
				ans=min(ans,mp[-i]-mp2[-cz+i]+1);
			}
		}
		ans=min(ans,2*n);
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 200005
using namespace std;
int t,n;
int tree[maxn],tree2[maxn];
int lowbit(int x)
{
	return x&-x;
}
void add(int pos,int x)
{
	for(int i=pos;i<=2*n;i+=lowbit(i))
	{
		tree[i]+=x;
	}
}
int sum(int pos)
{
	int ans=0;
	for(int i=pos;i>=1;i-=lowbit(i))
	{
		ans+=tree[i];
	}
	return ans;
}
void add2(int pos,int x)
{
	for(int i=pos;i<=2*n;i+=lowbit(i))
	{
		tree2[i]+=x;
	}
}
int sum2(int pos)
{
	int ans=0;
	for(int i=pos;i>=1;i-=lowbit(i))
	{
		ans+=tree2[i];
	}
	return ans;
}
inline int read()
{
    int num=0, w=0;
    char ch=0;
    while (!isdigit(ch)) {
        w|=ch=='-';
        ch = getchar();
    }
    while (isdigit(ch)) {
        num = (num<<3) + (num<<1) + (ch^48);
        ch = getchar();
    }
    return w? -num: num;
}
vector<int>v[maxn];
int main()
{
	t=read();
	while(t--)
	{
		n=read();
		int tmp;
		memset(tree,0,sizeof(tree));
		memset(tree2,0,sizeof(tree2));
		for(int i=1;i<=2*n;i++)
		{
			cin>>tmp;
			if(tmp==1)
			{
				add(i,1);
			}
			else
			{
				add2(i,1);
			}
		}
		if(sum(2*n)==sum2(2*n))
		{
			cout<<0<<endl;
			continue;
		}
		int ans=inf;
		for(int i=n;i>=1;i--)
		{
			for(int j=n+1;j<=2*n;j++)
			{
				if((j-i+1)%2==0)
				{
					if(sum(2*n)-sum(j)+sum(i-1)==sum2(2*n)-sum2(j)+sum2(i-1))
					{
						ans=min(ans,j-i+1);
					}
				}
			}
		}
		ans=min(ans,2*n);
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 400005
using namespace std;
int t,n;
int a[maxn];
int s1[maxn],s2[maxn];
inline int read()
{
    int num=0, w=0;
    char ch=0;
    while (!isdigit(ch)) {
        w|=ch=='-';
        ch = getchar();
    }
    while (isdigit(ch)) {
        num = (num<<3) + (num<<1) + (ch^48);
        ch = getchar();
    }
    return w? -num: num;
}
vector<int>v[maxn];
int main()
{
	t=read();
	while(t--)
	{
		map<int,int>mp,mp2;
		n=read();
		int sum1=0,sum2=0;
		for(int i=1;i<=2*n;i++)
		{
			a[i]=read();
			if(a[i]==1)
			sum1++;
			else
			sum2++;
		}
		for(int i=n+1;i<=2*n;i++)
		{
			if(a[i]==1)
			{
				s1[i]=s1[i-1]+1;

			}
			else
			s1[i]=s1[i-1]-1;
			if(s1[i]!=0&&!mp[s1[i]])
			{
				mp[s1[i]]=i;
			}
		}
		for(int i=n;i>=1;i--)
		{
			if(a[i]==1)
			{
				s2[i]=s2[i+1]+1;
			}
			else
			{
				s2[i]=s2[i+1]-1;
			}
			if(s2[i]!=0&&!mp2[s2[i]])
			{
				mp2[s2[i]]=i;
			}
		}
		int ans=inf;
		if(sum1==sum2)
		{
			cout<<0<<endl;
		}
		else if(sum1>sum2)
		{
			int cz=sum1-sum2;
			if(mp[cz])
			ans=min(ans,mp[cz]-n);
			if(mp2[cz])
			{
				ans=min(ans,n-mp2[cz]+1);
			}
			for(int i=1;i<=sum1-sum2;i++)
			{
				if(mp[i]&&mp[cz-i])
				ans=min(ans,mp[i]-mp2[cz-i]+1);
			}
		}
		else
		{
			int cz=sum1-sum2;
			if(mp[cz])
			ans=min(ans,mp[cz]-n);
			if(mp2[cz])
			{
				ans=min(ans,n-mp2[cz]+1);
			}
			for(int i=1;i<=sum2-sum1;i++)
			{
				if(mp[-i]&&mp[-cz+i])
				ans=min(ans,mp[-i]-mp2[-cz+i]+1);
			}
		}
		ans=min(ans,2*n);
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 400005
using namespace std;
int t,n;
int tree[maxn],tree2[maxn];
int lowbit(int x)
{
	return x&-x;
}
void add(int pos,int x)
{
	for(int i=pos;i<=2*n;i+=lowbit(i))
	{
		tree[i]+=x;
	}
}
int sum(int pos)
{
	int ans=0;
	for(int i=pos;i>=1;i-=lowbit(i))
	{
		ans+=tree[i];
	}
	return ans;
}
void add2(int pos,int x)
{
	for(int i=pos;i<=2*n;i+=lowbit(i))
	{
		tree2[i]+=x;
	}
}
int sum2(int pos)
{
	int ans=0;
	for(int i=pos;i>=1;i-=lowbit(i))
	{
		ans+=tree2[i];
	}
	return ans;
}
inline int read()
{
    int num=0, w=0;
    char ch=0;
    while (!isdigit(ch)) {
        w|=ch=='-';
        ch = getchar();
    }
    while (isdigit(ch)) {
        num = (num<<3) + (num<<1) + (ch^48);
        ch = getchar();
    }
    return w? -num: num;
}
vector<int>v[maxn];
int main()
{
	t=read();
	while(t--)
	{
		n=read();
		int tmp;
		memset(tree,0,sizeof(tree));
		memset(tree2,0,sizeof(tree2));
		for(int i=1;i<=2*n;i++)
		{
			cin>>tmp;
			if(tmp==1)
			{
				add(i,1);
			}
			else
			{
				add2(i,1);
			}
		}
		if(sum(2*n)==sum2(2*n))
		{
			cout<<0<<endl;
			continue;
		}
		int ans=inf;
		for(int i=n;i>=1;i--)
		{
			for(int j=n+1;j<=2*n;j++)
			{
				if((j-i+1)%2==0)
				{
					if(sum(2*n)-sum(j)+sum(i-1)==sum2(2*n)-sum2(j)+sum2(i-1))
					{
						ans=min(ans,j-i+1);
					}
				}
			}
		}
		for(int i=n;i>=1;i--)
		{
			int j=n;
				if((j-i+1)%2==0)
				{
					if(sum(2*n)-sum(j)+sum(i-1)==sum2(2*n)-sum2(j)+sum2(i-1))
					{
						ans=min(ans,j-i+1);
					}
				}

		}
		for(int j=n+1;j<=2*n;j++)
		{
			int i=n+1;
				if((j-i+1)%2==0)
				{
					if(sum(2*n)-sum(j)+sum(i-1)==sum2(2*n)-sum2(j)+sum2(i-1))
					{
						ans=min(ans,j-i+1);
					}
				}

		}
		ans=min(ans,2*n);
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 400005
using namespace std;
int t,n;
int tree[maxn],tree2[maxn];
int lowbit(int x)
{
	return x&-x;
}
void add(int pos,int x)
{
	for(int i=pos;i<=2*n;i+=lowbit(i))
	{
		tree[i]+=x;
	}
}
int sum(int pos)
{
	int ans=0;
	for(int i=pos;i>=1;i-=lowbit(i))
	{
		ans+=tree[i];
	}
	return ans;
}
void add2(int pos,int x)
{
	for(int i=pos;i<=2*n;i+=lowbit(i))
	{
		tree2[i]+=x;
	}
}
int sum2(int pos)
{
	int ans=0;
	for(int i=pos;i>=1;i-=lowbit(i))
	{
		ans+=tree2[i];
	}
	return ans;
}
inline int read()
{
    int num=0, w=0;
    char ch=0;
    while (!isdigit(ch)) {
        w|=ch=='-';
        ch = getchar();
    }
    while (isdigit(ch)) {
        num = (num<<3) + (num<<1) + (ch^48);
        ch = getchar();
    }
    return w? -num: num;
}
vector<int>v[maxn];
int main()
{
	t=read();
	while(t--)
	{
		n=read();
		int tmp;
		memset(tree,0,sizeof(tree));
		memset(tree2,0,sizeof(tree2));
		for(int i=1;i<=2*n;i++)
		{
			cin>>tmp;
			if(tmp==1)
			{
				add(i,1);
			}
			else
			{
				add2(i,1);
			}
		}
		if(sum(2*n)==sum2(2*n))
		{
			cout<<0<<endl;
			continue;
		}
		int ans=inf;
		for(int i=n;i>=1;i--)
		{
			for(int j=n+1;j<=2*n;j++)
			{
				if((j-i+1)%2==0)
				{
					if(sum(2*n)-sum(j)+sum(i-1)==sum2(2*n)-sum2(j)+sum2(i-1))
					{
						ans=min(ans,j-i+1);
					}
				}
			}
		}
		for(int i=n;i>=1;i--)
		{
			j=n;
				if((j-i+1)%2==0)
				{
					if(sum(2*n)-sum(j)+sum(i-1)==sum2(2*n)-sum2(j)+sum2(i-1))
					{
						ans=min(ans,j-i+1);
					}
				}

		}
		for(int j=n+1;j<=2*n;j++)
		{
			i=n+1;
				if((j-i+1)%2==0)
				{
					if(sum(2*n)-sum(j)+sum(i-1)==sum2(2*n)-sum2(j)+sum2(i-1))
					{
						ans=min(ans,j-i+1);
					}
				}

		}
		ans=min(ans,2*n);
		cout<<ans<<endl;
	}
	return 0;
}


// https://codeforces.com/contest/1278/problem/C

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fi first
#define se second
#define cerr if(false) cerr
#define watch(x) cerr << (#x) << " is " << (x) << endl;
int main() {
    ios::sync_with_stdio(0);
    cin.sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    while(t--) {
        int n;
        cin >> n;

        int a[(n*2)+50];
        for(int &x: a) {
            x = 0;
        }

        int bal = 0;
        for(int i = 1; i <= (n*2); i++) {
            int _;
            cin >> _;

            if(_ == 1) {
                a[i] = 1;
                bal++;
            } else if(_ == 2) {
                a[i] = -1;
                bal--;
            }
        }

        // Don't have to remove any
        if(bal == 0) {
            cout << 0 << endl;
            continue;
        }

        watch(bal)

        unordered_map<int, set<int>> pos;
        unordered_map<int, set<int, greater<int>>> posRev;

        for(int i = 1; i <= n; i++) {
            a[i] += a[i-1];
        }

        for(int i = n*2; i >= n+1; i--) {
            a[i] += a[i+1];
        }

        for(int i = 1; i <= 2*n; i++) {
            cerr << a[i] << " ";
        }
        cerr << endl;

        for(int i = 1; i <= n*2; i++) {
            pos[a[i]].emplace(i);
            posRev[a[i]].emplace(i);
            cerr << "emplacing " << i << " to " << a[i] << endl;
        }

        for(auto x: posRev) {
            cerr << x.first << ":";
            for(int y: x.second) {
                cerr << y << " ";
            }
            cerr << endl;
        }

        // cerr << *lower_bound(posRev[-1].begin(), posRev[-1].end(), 4) << endl;

        int best = INT_MAX;
        for(int i = 1; i <= n; i++) {
            int l = a[i];
            cerr << "trying " << i << endl;
            watch(a[i])
            int get = -a[i];
            watch(get)
            if(posRev.find(get) != posRev.end()) {
                int r = *lower_bound(posRev[get].begin(), posRev[get].end(), n+1);
                watch(r)
                // if(r != posRev.end())
                if(i < r) {
                    int rem = n*2 - (i + ((n*2)-r+1));
                    watch(i)
                    watch(((n*2)-r+1))
                    cerr << "remove " << rem << endl;
                    best = min(best, rem);
                }
            }
            cerr << endl;
        }

        if(best != INT_MAX) {
            cout << best << endl;
        } else {
            cout << n*2 << endl;
        }
    }
}

/*
1
3
1 2 1 1 2 1
*/


// https://codeforces.com/contest/1278/problem/C

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fi first
#define se second
#define cerr if(false) cerr
#define watch(x) cerr << (#x) << " is " << (x) << endl;
int main() {
    ios::sync_with_stdio(0);
    cin.sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    while(t--) {
        int n;
        cin >> n;

        int a[(n*2)+50];
        for(int &x: a) {
            x = 0;
        }

        int bal = 0;
        for(int i = 1; i <= (n*2); i++) {
            int _;
            cin >> _;

            if(_ == 1) {
                a[i] = 1;
                bal++;
            } else if(_ == 2) {
                a[i] = -1;
                bal--;
            }
        }

        // Don't have to remove any
        if(bal == 0) {
            cout << 0 << endl;
            continue;
        }

        watch(bal)

        unordered_map<int, set<int>> pos;
        unordered_map<int, set<int, greater<int>>> posRev;

        for(int i = 1; i <= n; i++) {
            a[i] += a[i-1];
        }

        for(int i = n*2; i >= n+1; i--) {
            a[i] += a[i+1];
        }

        for(int i = 1; i <= 2*n; i++) {
            cerr << a[i] << " ";
        }
        cerr << endl;

        for(int i = 1; i <= n*2; i++) {
            pos[a[i]].emplace(i);
            posRev[a[i]].emplace(i);
            cerr << "emplacing " << i << " to " << a[i] << endl;
        }

        for(auto x: posRev) {
            cerr << x.first << ":";
            for(int y: x.second) {
                cerr << y << " ";
            }
            cerr << endl;
        }

        // cerr << *lower_bound(posRev[-1].begin(), posRev[-1].end(), 4) << endl;

        int best = INT_MAX;
        for(int i = 1; i <= n; i++) {
            int l = a[i];
            cerr << "trying " << i << endl;
            watch(a[i])
            int get = -a[i];
            watch(get)
            if(posRev.find(get) != posRev.end()) {
                int r = *lower_bound(posRev[get].begin(), posRev[get].end(), n+1);
                watch(r)
                if(lower_bound(posRev[get].begin(), posRev[get].end(), n+1) != posRev[get].end())
                if(i < r) {
                    int rem = n*2 - (i + ((n*2)-r+1));
                    watch(i)
                    watch(((n*2)-r+1))
                    cerr << "remove " << rem << endl;
                    best = min(best, rem);
                }
            }
            cerr << endl;
        }

        if(best != INT_MAX) {
            cout << best << endl;
        } else {
            cout << n*2 << endl;
        }
    }
}

/*
1
3
1 2 1 1 2 1
*/


// https://codeforces.com/contest/1278/problem/C

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fi first
#define se second
#define cerr if(false) cerr
#define watch(x) cerr << (#x) << " is " << (x) << endl;
int main() {
    ios::sync_with_stdio(0);
    cin.sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    while(t--) {
        int n;
        cin >> n;

        int a[(n*2)+50];

        int c1 = 0;
        int c2= 0 ;
        for(int i = 1; i <= (n*2); i++) {
            cin >> a[i];
            if(a[i] == 1) c1++;
            if(a[i] == 2) c2++;
        }

        unordered_map<int, int> diff;

        diff[0] = 0;
        int cur = 0;

        for(int i = n+1; i <= 2*n; i++) {
            if(a[i] == 1) {
                cur++;
            } else {
                cur--;
            }

            if(!diff.count(cur)) {
                diff[cur] = i-n;
            }
        }

        int ans = INT_MAX;
        int orig = c1-c2;

        watch(orig)

        cur = 0;
        for(int i = n; i >= 1; i--) {
            if(a[i] == 1) {
                cur++;
            } else {
                cur--;
            }

            if(diff.count(orig-cur)) {
                ans = min(ans, n-i+1+diff[orig-cur]);
            }
        }

        if(diff.count(orig)) {
            ans = min(ans, diff[orig]);
        }

        cout << ans << endl;
    }
}

/*
1
3
1 2 1 1 2 1
*/


// https://codeforces.com/contest/1278/problem/C

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fi first
#define se second
// #define cerr if(false) cerr
// #define watch(x) cerr << (#x) << " is " << (x) << endl;
int main() {
    ios::sync_with_stdio(0);
    cin.sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    while(t--) {
        int n;
        cin >> n;

        int a[(n*2)+50];

        int c1 = 0;
        int c2= 0 ;
        for(int i = 1; i <= (n*2); i++) {
            cin >> a[i];
            if(a[i] == 1) c1++;
            if(a[i] == 2) c2++;
        }

        unordered_map<int, int> diff;

        diff[0] = 0;
        int cur = 0;

        for(int i = n+1; i <= 2*n; i++) {
            if(a[i] == 1) {
                cur++;
            } else {
                cur--;
            }

            if(!diff.count(cur)) {
                diff[cur] = i-n;
            }
        }

        int ans = INT_MAX;
        int orig = c1-c2;

        watch(orig)

        cur = 0;
        for(int i = n; i >= 1; i--) {
            if(a[i] == 1) {
                cur++;
            } else {
                cur--;
            }

            if(diff.count(orig-cur)) {
                ans = min(ans, n-i+1+diff[orig-cur]);
            }
        }

        if(diff.count(orig)) {
            ans = min(ans, diff[orig]);
        }

        cout << ans << endl;
    }
}

/*
1
3
1 2 1 1 2 1
*/


// https://codeforces.com/contest/1278/problem/C

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fi first
#define se second
#define cerr if(false) cerr
#define watch(x) cerr << (#x) << " is " << (x) << endl;
int main() {
    ios::sync_with_stdio(0);
    cin.sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;

    while(t--) {
        int n;
        cin >> n;

        int a[(n*2)+50];
        for(int &x: a) {
            x = 0;
        }

        int bal = 0;
        for(int i = 1; i <= (n*2); i++) {
            int _;
            cin >> _;

            if(_ == 1) {
                a[i] = 1;
                bal++;
            } else if(_ == 2) {
                a[i] = -1;
                bal--;
            }
        }

        // Don't have to remove any
        if(bal == 0) {
            cout << 0 << endl;
            continue;
        }

        unordered_map<int, deque<int>> pos;

        for(int i = 1; i <= n; i++) {
            a[i] += a[i-1];
        }

        for(int i = n*2; i >= n+1; i--) {
            a[i] += a[i+1];
        }

        for(int i = 1; i <= 2*n; i++) {
            cerr << a[i] << " ";
        }
        cerr << endl;

        for(int i = 1; i <= n*2; i++) {
            pos[a[i]].emplace_back(i);
        }

        for(auto &x: pos) {
            sort(x.second.begin(), x.second.end());
        }

        int best = INT_MAX;
        for(int i = 1; i <= n; i++) {
            int l = a[i];
            cerr << "trying " << i << endl;
            watch(-a[i])
            if(pos.find(-a[i]) != pos.end()) {
                int r = *lower_bound(pos[-a[i]].begin(), pos[-a[i]].end(), l+1);
                watch(r)
                if(i < r) {
                    cerr << "remove " << (((n*2)-r+1)+i) << endl;
                    best = min(best, (n*2) - (((n*2)-r+1)+i));
                }
            }
            cerr << endl;
        }

        if(best != INT_MAX) {
            cout << best << endl;
        } else {
            cout << n*2 << endl;
        }
    }
}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int a[200010];
int dif[600060];

int mainn(){
    int n;scanf("%d",&n);
    for (int i=1;i<=2*n;++i) scanf("%d",&a[i]);
    for (int i=0;i<=n;++i)
        dif[n+i]=dif[n-i]=0;
    int num1=0,num0=0;
    for (int i=1;i<=n;++i){
        if (a[i]==1) num1++;
        else num0++;
        dif[num1-num0+n]=i;
    }
    num1=0;num0=0;
    int ans=dif[n];
    for (int i=2*n;i>n;--i){
        if (a[i]==1) num1++;
        else num0++;
        if (num0==num1 && 2*n-i+1>ans) ans=2*n-i+1;
        if (dif[num0-num1+n] && dif[num0-num1+n]+2*n-i+1>ans )
            ans=dif[num0-num1+n]+2*n-i+1;
    }
    printf("%d\n",2*n-ans);

}

int main()
{
    int t;scanf("%d",&t);
    while (t--) mainn();

}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int a[200010];
int sum[5][200010];

int mainn(){
    int n;scanf("%d",&n);
    for (int i=1;i<=2*n;++i) scanf("%d",&a[i]);
    sum[1][0]=sum[2][0]=0;
    for (int i=1;i<=2*n;++i){
        sum[1][i]=sum[1][i-1];
        sum[2][i]=sum[2][i-1];
        sum[ a[i] ][i]++;
    }

    int ans=2*n,ll=0,rr=n;
    while (ll<=rr){
        int mid=(ll+rr)/2;
        int flag=0;
        for (int i=0;i+mid*2<=2*n;++i){
            int l=i+1;int r=i+mid*2;
            if (l<=n+1 && r>=n)
                if ( sum[1][2*n]-(sum[1][r]-sum[1][i]) == sum[2][2*n]-(sum[2][r]-sum[2][i]) )
                    flag=1;
        }
        if (flag){
            ans=mid*2;rr=mid-1;
        }else ll=mid+1;
    }
    printf("%d\n",ans);
}

int main()
{
    int t;scanf("%d",&t);
    while (t--) mainn();

}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int a[200010];
int dif[600060];

int mainn(){
    int n;scanf("%d",&n);
    for (int i=1;i<=2*n;++i) scanf("%d",&a[i]);
    for (int i=0;i<=2*n;++i)
        dif[n+i]=dif[n-i]=0;
    int num1=0,num0=0;
    for (int i=1;i<=n;++i){
        if (a[i]==1) num1++;
        else num0++;
        dif[num1-num0+n]=i;
    }
    num1=0;num0=0;
    int ans=0;
    for (int i=2*n;i>n;--i){
        if (a[i]==1) num1++;
        else num0++;
        if (num0==num1 && 2*n-i+1>ans) ans=2*n-i+1;
        if (dif[num0-num1+n] && dif[num0-num1+n]+2*n-i+1>ans )
            ans=dif[num0-num1+n]+2*n-i+1;
    }
    printf("%d\n",2*n-ans);

}

int main()
{
    int t;scanf("%d",&t);
    while (t--) mainn();

}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int a[200010];
int sum[5][200010];

int mainn(){
    int n;scanf("%d",&n);
    for (int i=n;i>0;--i) scanf("%d",&a[i]);
    for (int i=0;i<n;++i) scanf("%d",&a[2*n-i]);
    sum[1][0]=sum[2][0]=0;
    for (int i=1;i<=2*n;++i){
        sum[1][i]=sum[1][i-1];
        sum[2][i]=sum[2][i-1];
        sum[ a[i] ][i]++;
    }

    int ans=0,ll=0,rr=n;
    while (ll<=rr){
        int mid=(ll+rr)/2;
        int flag=0;
        for (int i=n;i+mid*2>=n && i>=0;--i)
        if (i+mid*2<=2*n)
            if ( sum[1][i+mid*2]-sum[1][i] == sum[2][i+mid*2]-sum[2][i] )
            {
                   flag=1;
                    //printf("%d %d %d\n",i+1,i+mid*2,mid*2);
            }
        if(flag){
            ans=mid*2;ll=mid+1;
        }
        else
            rr=mid-1;
    }
    printf("%d\n",2*n-ans);
}

int main()
{
    int t;scanf("%d",&t);
    while (t--) mainn();

}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int a[200010];
int dif[600060];

int mainn(){
    int n;scanf("%d",&n);
    for (int i=1;i<=2*n;++i) scanf("%d",&a[i]);
    for (int i=0;i<=2*n;++i)
        dif[n+i]=dif[n-i]=0;
    int num1=0,num0=0;
    for (int i=1;i<=n;++i){
        if (a[i]==1) num1++;
        else num0++;
        dif[num1-num0+n]=i;
    }
    num1=0;num0=0;
    int ans=dif[n];
    for (int i=2*n;i>n;--i){
        if (a[i]==1) num1++;
        else num0++;
        if (num0==num1 && 2*n-i+1>ans) ans=2*n-i+1;
        if (dif[num0-num1+n] && dif[num0-num1+n]+2*n-i+1>ans )
            ans=dif[num0-num1+n]+2*n-i+1;
    }
    printf("%d\n",2*n-ans);

}

int main()
{
    int t;scanf("%d",&t);
    while (t--) mainn();

}


#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int a[200010];
int sum[5][200010];

int mainn(){
    int n;scanf("%d",&n);
    for (int i=n;i>0;--i) scanf("%d",&a[i]);
    for (int i=0;i<n;++i) scanf("%d",&a[2*n-i]);
    sum[1][0]=sum[2][0]=0;
    for (int i=1;i<=2*n;++i){
        sum[1][i]=sum[1][i-1];
        sum[2][i]=sum[2][i-1];
        sum[ a[i] ][i]++;
    }

    int ans=0,ll=0,rr=n;
    while (ll<=rr){
        int mid=(ll+rr)/2;
        int flag=0;
        for (int i=0;i+mid*2<=2*n;++i)
            if ( sum[1][i+mid*2]-sum[1][i] == sum[2][i+mid*2]-sum[2][i] )
            {
                   flag=1;
                    //printf("%d %d %d\n",i+1,i+mid*2,mid*2);
            }
        if(flag){
            ans=mid*2;ll=mid+1;
        }
        else
            rr=mid-1;
    }
    printf("%d\n",2*n-ans);
}

int main()
{
    int t;scanf("%d",&t);
    while (t--) mainn();

}


#include<bits/stdc++.h>
#define f(i,j) for(ll i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
#define inf 999999999
#define MOD 1000000007
#define pcp

using namespace std;
ll mod=200001;
void Solve();
int  main()
{
    #ifdef pc
    freopen("input.txt","r",stdin);
    mod=1001;
    #endif
    Solve();
    return 0;
}

void Solve()
{
    ll m,n,k,t,mx=0;
    cin >> t;
    while(t--)
    {
        cin>>n;
        int num[2*n],c1=0,c2=0;
        f(i,2*n)
        {
            cin>>num[i];
            if(num[i]==1) c1++;
            else c2++;
        }
        if(c1==c2) cout<<0<<endl;
        else if(c1>c2)
        {
            int nf[c1-c2+1];
            int ns[c1-c2+1];
            int final[c1-c2];
            f(i,c1-c2+1) nf[i]=inf;
            f(i,c1-c2+1) ns[i]=inf;
            nf[0]=ns[0]=0;
            int cnt=0;
            for(int i=n;i<2*n;i++)
            {
                if(num[i]==1) cnt++;
                else cnt--;
                if(cnt>0) if(ns[cnt]==inf) ns[cnt]=i+1-n;
                if(cnt==c1-c2) break;
            }
            cnt=0;
            for(int i=n-1;i>=0;i--)
            {
                if(num[i]==1) cnt++;
                else cnt--;
                if(cnt>0) if(nf[cnt]==inf) nf[cnt]=n-i;
                if(cnt==c1-c2) break;
            }
            int res=2*n;
            for(int i=0;i<=c1-c2;i++)
            {
                if(ns[i]+nf[c1-c2-i] < res)res= ns[i]+nf[c1-c2-i];
            }
            cout<<res<<endl;
        }
        else
        {
            int nf[c1-c2+1];
            int ns[c1-c2+1];
            int final[c1-c2];
            f(i,c1-c2+1) nf[i]=inf;
            f(i,c1-c2+1) ns[i]=inf;
            int cnt=0;
            nf[0]=ns[0]=0;
            for(int i=n;i<2*n;i++)
            {
                if(num[i]==2) cnt++;
                else cnt--;
                if(cnt>0) if(ns[cnt]==inf) ns[cnt]=i+1-n;
                if(cnt==c1-c2) break;
            }
            cnt=0;
            for(int i=n-1;i>=0;i--)
            {
                if(num[i]==2) cnt++;
                else cnt--;
                if(cnt>0) if(nf[cnt]==inf) nf[cnt]=n-i;
                if(cnt==c1-c2) break;
            }
            int res=2*n;
            for(int i=0;i<=c1-c2;i++)
            {
                if(ns[i]+nf[c1-c2-i] < res)res= ns[i]+nf[c1-c2-i];
            }
            cout<<res<<endl;
        }

    }
}


#include<bits/stdc++.h>
#define f(i,j) for(ll i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
#define inf 999999999
#define MOD 1000000007
#define pcd

using namespace std;
ll mod=200001;
void Solve();
int  main()
{
    #ifdef pc
    freopen("input.txt","r",stdin);
    mod=1001;
    #endif
    Solve();
    return 0;
}

void Solve()
{
    ll m,n,k,t,mx=0;
    cin >> t;
    while(t--)
    {
        //cout<<100-t<<"  ";
        int a,b,c;
        cin>>a >>b;
        if(a>b) c=a-b;
        else c=b-a;
        if(c==0) cout<<0<<endl;
        else
        {
            int x=sqrt(c*2);
            if(x*(x+1)<c*2)x++;
            if(x*(x+1) == c*2) cout<<x<<endl;
            else
            {
                int y =(x*(x+1))/2-c;
                if(y%2==(x+1)%2) cout<<x+1<<endl;
                else cout<<x+2<<endl;
            }
        }
    }
}


#include<bits/stdc++.h>
#define f(i,j) for(ll i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
#define inf 999999999
#define MOD 1000000007
#define pcd

using namespace std;
ll mod=200001;
void Solve();
int  main()
{
    #ifdef pc
    freopen("input.txt","r",stdin);
    mod=1001;
    #endif
    Solve();
    return 0;
}

void Solve()
{
    ll m,n,k,t,mx=0;
    cin >> t;
    while(t--)
    {
        cin>>n;
        int num[2*n],c1=0,c2=0;
        f(i,2*n)
        {
            cin>>num[i];
            if(num[i]==1) c1++;
            else c2++;
        }
        if(c1==c2) cout<<0<<endl;
        else if(c1>c2)
        {
            int nf[c1-c2];
            int ns[c1-c2];
            int final[c1-c2];
            f(i,c1-c2) nf[i];
            f(i,c1-c2) ns[i];
            int cnt=0;
            for(int i=n;i<2*n;i++)
            {
                if(num[i]==1) cnt++;
                else cnt--;
                if(cnt>0) if(ns[cnt]==0) ns[cnt]=i+1-n;
                if(cnt==c1-c2) break;
            }
            cnt=0;
            for(int i=0;i<n;i++)
            {
                if(num[i]==1) cnt++;
                else cnt--;
                if(cnt>0) if(nf[cnt]==0) nf[cnt]=i+1;
                if(cnt==c1-c2) break;
            }
            int res=2*n;
            for(int i=0;i<=c1-c2;i++)
            {
                if(ns[i]+nf[c1-c2-i] < res)res= ns[i]+nf[c1-c2-i];
            }
            cout<<res<<endl;
        }
        else
        {
            int tt=c2;
            c2=c1;
            c1=c2;
            int nf[c1-c2];
            int ns[c1-c2];
            int final[c1-c2];
            f(i,c1-c2) nf[i];
            f(i,c1-c2) ns[i];
            int cnt=0;
            for(int i=n;i<2*n;i++)
            {
                if(num[i]==2) cnt++;
                else cnt--;
                if(cnt>0) if(ns[cnt]==0) ns[cnt]=i+1-n;
                if(cnt==c1-c2) break;
            }
            cnt=0;
            for(int i=0;i<n;i++)
            {
                if(num[i]==2) cnt++;
                else cnt--;
                if(cnt>0) if(nf[cnt]==0) nf[cnt]=i+1;
                if(cnt==c1-c2) break;
            }
            int res=2*n;
            for(int i=0;i<=c1-c2;i++)
            {
                if(ns[i]+nf[c1-c2-i] < res)res = ns[i]+nf[c1-c2-i];
            }
            cout<<res<<endl;
        }

    }
}


#include<bits/stdc++.h>
#define f(i,j) for(ll i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
#define inf 999999999
#define MOD 1000000007
#define pcd

using namespace std;
ll mod=200001;
void Solve();
int  main()
{
    #ifdef pc
    freopen("input.txt","r",stdin);
    mod=1001;
    #endif
    Solve();
    return 0;
}

void Solve()
{
    ll m,n,k,t,mx=0;
    cin >> t;
    while(t--)
    {
        cin>>n;
        int num[2*n],c1=0,c2=0;
        f(i,2*n)
        {
            cin>>num[i];
            if(num[i]==1) c1++;
            else c2++;
        }
        if(c1==c2) cout<<0<<endl;
        else if(c1>c2)
        {
            int nf[c1-c2];
            int ns[c1-c2];
            int final[c1-c2];
            f(i,c1-c2) nf[i]=inf;
            f(i,c1-c2) ns[i]=inf;
            int cnt=0;
            for(int i=n;i<2*n;i++)
            {
                if(num[i]==1) cnt++;
                else cnt--;
                if(cnt>0) if(ns[cnt]==inf) ns[cnt]=i+1-n;
                if(cnt==c1-c2) break;
            }
            cnt=0;
            for(int i=n-1;i>=0;i--)
            {
                if(num[i]==1) cnt++;
                else cnt--;
                if(cnt>0) if(nf[cnt]==inf) nf[cnt]=n-i;
                if(cnt==c1-c2) break;
            }
            int res=2*n;
            for(int i=0;i<=c1-c2;i++)
            {
                if(ns[i]+nf[c1-c2-i] < res)res= ns[i]+nf[c1-c2-i];
            }
            cout<<res<<endl;
        }
        else
        {
            int tt=c2;
            c2=c1;
            c1=c2;
            int nf[c1-c2];
            int ns[c1-c2];
            int final[c1-c2];
            f(i,c1-c2) nf[i]=inf;
            f(i,c1-c2) ns[i]=inf;
            int cnt=0;
            for(int i=n;i<2*n;i++)
            {
                if(num[i]==2) cnt++;
                else cnt--;
                if(cnt>0) if(ns[cnt]==inf) ns[cnt]=i+1-n;
                if(cnt==c1-c2) break;
            }
            cnt=0;
            for(int i=n-1;i>=0;i--)
            {
                if(num[i]==2) cnt++;
                else cnt--;
                if(cnt>0) if(nf[cnt]==inf) nf[cnt]=n-i;
                if(cnt==c1-c2) break;
            }
            int res=2*n;
            for(int i=0;i<=c1-c2;i++)
            {
                if(ns[i]+nf[c1-c2-i] < res)res= ns[i]+nf[c1-c2-i];
            }
            cout<<res<<endl;
        }

    }
}


#include<bits/stdc++.h>
#define f(i,j) for(ll i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
#define inf 999999999
#define MOD 1000000007
#define pcd

using namespace std;
ll mod=200001;
void Solve();
int  main()
{
    #ifdef pc
    freopen("input.txt","r",stdin);
    mod=1001;
    #endif
    Solve();
    return 0;
}

void Solve()
{
    ll m,n,k,t,mx=0;
    cin >> t;
    while(t--)
    {
        cin>>n;
        int num[2*n],c1=0,c2=0;
        f(i,2*n)
        {
            cin>>num[i];
            if(num[i]==1) c1++;
            else c2++;
        }
        if(c1==c2) cout<<0<<endl;
        else if(c1>c2)
        {
            int nf[c1-c2+1];
            int ns[c1-c2+1];
            int final[c1-c2];
            f(i,c1-c2+1) nf[i]=inf;
            f(i,c1-c2+1) ns[i]=inf;
            int cnt=0;
            for(int i=n;i<2*n;i++)
            {
                if(num[i]==1) cnt++;
                else cnt--;
                if(cnt>0) if(ns[cnt]==inf) ns[cnt]=i+1-n;
                if(cnt==c1-c2) break;
            }
            cnt=0;
            for(int i=n-1;i>=0;i--)
            {
                if(num[i]==1) cnt++;
                else cnt--;
                if(cnt>0) if(nf[cnt]==inf) nf[cnt]=n-i;
                if(cnt==c1-c2) break;
            }
            int res=2*n;
            for(int i=0;i<=c1-c2;i++)
            {
                if(ns[i]+nf[c1-c2-i] < res)res= ns[i]+nf[c1-c2-i];
            }
            cout<<res<<endl;
        }
        else
        {
            int nf[c1-c2+1];
            int ns[c1-c2+1];
            int final[c1-c2];
            f(i,c1-c2+1) nf[i]=inf;
            f(i,c1-c2+1) ns[i]=inf;
            int cnt=0;
            for(int i=n;i<2*n;i++)
            {
                if(num[i]==2) cnt++;
                else cnt--;
                if(cnt>0) if(ns[cnt]==inf) ns[cnt]=i+1-n;
                if(cnt==c1-c2) break;
            }
            cnt=0;
            for(int i=n-1;i>=0;i--)
            {
                if(num[i]==2) cnt++;
                else cnt--;
                if(cnt>0) if(nf[cnt]==inf) nf[cnt]=n-i;
                if(cnt==c1-c2) break;
            }
            int res=2*n;
            for(int i=0;i<=c1-c2;i++)
            {
                if(ns[i]+nf[c1-c2-i] < res)res= ns[i]+nf[c1-c2-i];
            }
            cout<<res<<endl;
        }

    }
}


#include<bits/stdc++.h>
#define f(i,j) for(ll i=0;i<j;i++)
#define s(i) scanf("%d",&i)
#define ss(i) scanf("%s",i)
#define s2(i,j) scanf("%d %d",&i,&j)
#define s3(i,j,k) scanf("%d %d %d",&i,&j,&k)
#define ll long long int
#define inf 999999999
#define MOD 1000000007
#define pcp

using namespace std;
ll mod=200001;
void Solve();
int  main()
{
    #ifdef pc
    freopen("input.txt","r",stdin);
    mod=1001;
    #endif
    Solve();
    return 0;
}

void Solve()
{
    ll m,n,k,t,mx=0;
    cin >> t;
    while(t--)
    {
        cin>>n;
        int num[2*n],c1=0,c2=0;
        f(i,2*n)
        {
            cin>>num[i];
            if(num[i]==1) c1++;
            else c2++;
        }
        if(c1==c2) cout<<0<<endl;
        else if(c1>c2)
        {
            int nf[c1-c2+1];
            int ns[c1-c2+1];
            int final[c1-c2];
            f(i,c1-c2+1) nf[i]=inf;
            f(i,c1-c2+1) ns[i]=inf;
            nf[0]=ns[0]=0;
            int cnt=0;
            for(int i=n;i<2*n;i++)
            {
                if(num[i]==1) cnt++;
                else cnt--;
                if(cnt>0) if(ns[cnt]==inf) ns[cnt]=i+1-n;
                if(cnt==c1-c2) break;
            }
            cnt=0;
            for(int i=n-1;i>=0;i--)
            {
                if(num[i]==1) cnt++;
                else cnt--;
                if(cnt>0) if(nf[cnt]==inf) nf[cnt]=n-i;
                if(cnt==c1-c2) break;
            }
            int res=2*n;
            for(int i=0;i<=c1-c2;i++)
            {
                if(ns[i]+nf[c1-c2-i] < res)res= ns[i]+nf[c1-c2-i];
            }
            cout<<res<<endl;
        }
        else
        {
            int xx=c1;
            c1=c2;
            c2=xx;
            int nf[c1-c2+1];
            int ns[c1-c2+1];
            int final[c1-c2];
            f(i,c1-c2+1) nf[i]=inf;
            f(i,c1-c2+1) ns[i]=inf;
            int cnt=0;
            nf[0]=ns[0]=0;
            for(int i=n;i<2*n;i++)
            {
                if(num[i]==2) cnt++;
                else cnt--;
                if(cnt>0) if(ns[cnt]==inf) ns[cnt]=i+1-n;
                if(cnt==c1-c2) break;
            }
            cnt=0;
            for(int i=n-1;i>=0;i--)
            {
                if(num[i]==2) cnt++;
                else cnt--;
                if(cnt>0) if(nf[cnt]==inf) nf[cnt]=n-i;
                if(cnt==c1-c2) break;
            }
            int res=2*n;
            for(int i=0;i<=c1-c2;i++)
            {
                if(ns[i]+nf[c1-c2-i] < res)res= ns[i]+nf[c1-c2-i];
            }
            cout<<res<<endl;
        }

    }
}


#include <bits/stdc++.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#define pb push_back
#define fi first
#define se second
#define lson(r) (r<<1)
#define rson(r) ((r<<1)|1)
#define RED 1
#define BLACK 2
using namespace std;

typedef long long ll;

const int MAXN = 2e5+7;
const int MAXV = 507;
const int MAXE = 507;
const int INF = 0x3f3f3f3f;
int n;

int row[MAXN];
unordered_map<int, int> ump;

int main()
{
    //freopen("c.in", "r", stdin);
    int T;
    cin >> T;
    for (int cas = 1; cas <= T; cas++)
    {
        cin >> n;
        ump.clear();
        int sumBlack = 0, sumRed = 0, tmp = 0, tar = 0, ans = 2*n;
        for (int i = 0; i < 2*n; i++)
        {
            cin >> row[i];
            if (row[i] == BLACK) sumBlack++;
            else sumRed++;
        }
        for (int i = n-1; i >= 0; i--)
        {
            if (row[i] == BLACK)
            {
                tmp++;
            }
            else if (row[i] == RED)
            {
                tmp--;
            }
            if (ump.find(tmp) == ump.end())
            {
                ump[tmp] = i;
            }
         //   cout << tmp << " ";
        }
        //cout << ";";
        tmp = 0;
        tar = sumBlack - sumRed;
        if (tar == 0)
        {
            cout << 0 << endl;
            continue;
        }
        for (int i = n; i < 2*n; i++)
        {
            if (row[i] == BLACK) tmp++;
            else tmp--;
            //cout << tmp << " ";
            int d = tar - tmp, pos;
            if (ump.find(d) == ump.end()) continue;
            else pos = ump[d];
            ans = min(ans, i-pos+1);
        }
        //cout << endl;
        //cout << tar << endl;
        cout << ans << endl;
    };
    return 0;
}


#include <bits/stdc++.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#define pb push_back
#define fi first
#define se second
#define lson(r) (r<<1)
#define rson(r) ((r<<1)|1)
#define RED 1
#define BLUE 2
using namespace std;

typedef long long ll;

const int MAXN = 2e5+7;
const int MAXV = 507;
const int MAXE = 507;
const int INF = 0x3f3f3f3f;

int row[MAXN];
int sumRed[MAXN], sumBlue[MAXN];
int n, blue = 0, red = 0;
bool check(int len, int mid)
{
    int leftBegin = max(0, n-len);
    int toEatRed = red - mid, toEatBlue = blue - mid;
    for (int l = leftBegin; l <= n && l+len-1 < 2*n; l++)
    {
        int eatBlue = sumBlue[l+len-1] - (l == 0 ? 0 : sumBlue[l-1]);
        int eatRed = sumRed[l+len-1] - (l == 0 ? 0 : sumRed[l-1]);
        // cout << l << " " << eatRed << " " << eatBlue << endl;
        if(eatRed == toEatRed && eatBlue == toEatBlue) return true;
    }
    return false;
}
int main()
{
   // freopen("c.in", "r", stdin);
    int T;
    cin >> T;
    for (int cas = 1; cas <= T; cas++)
    {
        int ans = 0;
        cin >> n;
        memset(sumRed, 0, sizeof(sumRed));
        memset(sumBlue, 0, sizeof(sumBlue));
        red = 0;
        blue = 0;
        for (int i = 0; i < 2*n; i++)
        {
            scanf("%d", &row[i]);
            if (row[i] == RED)
            {
                sumRed[i] = 1;
                red++;
            }
            else
            {
                sumBlue[i] = 1;
                blue++;
            }
            if (i == 0) continue;
            sumBlue[i] += sumBlue[i-1];
            sumRed[i] += sumRed[i-1];
        }
        //bisearch the how many jars should remain.
        int right = min(blue, red), left = 0;
        while(left < right)
        {
            int mid = (left+right) >> 1;
            int toEat = 2*n - 2*mid;
            bool flag = check(toEat, mid);
            //cout << left << " " << right << " " << mid << " " << flag << " " << toEat << endl;
            if (flag) left = mid+1;
            else right = mid;
        }
        if (!check(2*n-2*left, left)) left--;
        cout << 2*n-2*left << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#define pb push_back
#define fi first
#define se second
#define lson(r) (r<<1)
#define rson(r) ((r<<1)|1)
#define RED 1
#define BLACK 2
using namespace std;

typedef long long ll;

const int MAXN = 2e5+7;
const int MAXV = 507;
const int MAXE = 507;
const int INF = 0x3f3f3f3f;
int n;

int row[MAXN];
unordered_map<int, int> ump;

int main()
{
    //freopen("c.in", "r", stdin);
    int T;
    cin >> T;
    for (int cas = 1; cas <= T; cas++)
    {
        cin >> n;
        ump.clear();
        //this initialization when you don't have to eat from left.
        ump[0] = n;
        int sumBlack = 0, sumRed = 0, tmp = 0, tar = 0, ans = 2*n;
        for (int i = 0; i < 2*n; i++)
        {
            cin >> row[i];
            if (row[i] == BLACK) sumBlack++;
            else sumRed++;
        }
        for (int i = n-1; i >= 0; i--)
        {
            if (row[i] == BLACK)
            {
                tmp++;
            }
            else if (row[i] == RED)
            {
                tmp--;
            }
            if (ump.find(tmp) == ump.end())
            {
                ump[tmp] = i;
            }
         //   cout << tmp << " ";
        }
        //cout << ";";
        tmp = 0;
        tar = sumBlack - sumRed;

        //the same when you don't have to eat to the right
        int d = tar - tmp;
        if (ump.find(d) != ump.end())
        {
            int p = ump[d];
            ans = min(ans, n-p);
        }
        for (int i = n; i < 2*n; i++)
        {
            if (row[i] == BLACK) tmp++;
            else tmp--;
         //   cout << tmp << " ";
            int d = tar - tmp, pos;
            if (ump.find(d) == ump.end()) continue;
            else pos = ump[d];
            ans = min(ans, i-pos+1);
        }
        //cout << endl;
        //cout << tar << endl;
        cout << ans << endl;
    };
    return 0;
}


#include <bits/stdc++.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#define pb push_back
#define fi first
#define se second
#define lson(r) (r<<1)
#define rson(r) ((r<<1)|1)
#define RED 1
#define BLACK 2
using namespace std;

typedef long long ll;

const int MAXN = 2e5+7;
const int MAXV = 507;
const int MAXE = 507;
const int INF = 0x3f3f3f3f;
int n;

int row[MAXN];
unordered_map<int, int> ump;

int main()
{
   // freopen("c.in", "r", stdin);
    int T;
    cin >> T;
    for (int cas = 1; cas <= T; cas++)
    {
        cin >> n;
        ump.clear();
        //this initialization when you don't have to eat from left.
        ump[0] = n;
        int sumBlack = 0, sumRed = 0, tmp = 0, tar = 0, ans = 2*n;
        for (int i = 0; i < 2*n; i++)
        {
            cin >> row[i];
            if (row[i] == BLACK) sumBlack++;
            else sumRed++;
        }
        for (int i = n-1; i >= 0; i--)
        {
            if (row[i] == BLACK)
            {
                tmp++;
            }
            else if (row[i] == RED)
            {
                tmp--;
            }
            if (ump.find(tmp) == ump.end())
            {
                ump[tmp] = i;
            }
         //   cout << tmp << " ";
        }
        //cout << ";";
        tmp = 0;
        tar = sumBlack - sumRed;
        if (tar == 0)
        {
            cout << 0 << endl;
            continue;
        }
        for (int i = n; i < 2*n; i++)
        {
            if (row[i] == BLACK) tmp++;
            else tmp--;
         //   cout << tmp << " ";
            int d = tar - tmp, pos;
            if (ump.find(d) == ump.end()) continue;
            else pos = ump[d];
            ans = min(ans, i-pos+1);
        }
        //cout << endl;
        //cout << tar << endl;
        cout << ans << endl;
    };
    return 0;
}


#include <bits/stdc++.h>
#include <string.h>
#include <iostream>
#include <stdio.h>
#define pb push_back
#define fi first
#define se second
#define lson(r) (r<<1)
#define rson(r) ((r<<1)|1)
#define RED 1
#define BLUE 2
using namespace std;

typedef long long ll;

const int MAXN = 1e5+7;
const int MAXV = 507;
const int MAXE = 507;
const int INF = 0x3f3f3f3f;

int row[MAXN];
int sumRed[MAXN], sumBlue[MAXN];
int n, blue = 0, red = 0;
bool check(int len, int mid)
{
    int leftBegin = max(0, n-len);
    int toEatRed = red - mid, toEatBlue = blue - mid;
    for (int l = leftBegin; l <= n && l+len-1 < 2*n; l++)
    {
        int eatBlue = sumBlue[l+len-1] - (l == 0 ? 0 : sumBlue[l-1]);
        int eatRed = sumRed[l+len-1] - (l == 0 ? 0 : sumRed[l-1]);
        // cout << l << " " << eatRed << " " << eatBlue << endl;
        if(eatRed == toEatRed && eatBlue == toEatBlue) return true;
    }
    return false;
}
int main()
{
   // freopen("c.in", "r", stdin);
    int T;
    cin >> T;
    for (int cas = 1; cas <= T; cas++)
    {
        int ans = 0;
        cin >> n;
        memset(sumRed, 0, sizeof(sumRed));
        memset(sumBlue, 0, sizeof(sumBlue));
        red = 0;
        blue = 0;
        for (int i = 0; i < 2*n; i++)
        {
            scanf("%d", &row[i]);
            if (row[i] == RED)
            {
                sumRed[i] = 1;
                red++;
            }
            else
            {
                sumBlue[i] = 1;
                blue++;
            }
            if (i == 0) continue;
            sumBlue[i] += sumBlue[i-1];
            sumRed[i] += sumRed[i-1];
        }
        //both of them should left
        int right = min(blue, red), left = 0;
        while(left < right)
        {
            int mid = (left+right) >> 1;
            int toEat = 2*n - 2*mid;
            bool flag = check(toEat, mid);
            //cout << left << " " << right << " " << mid << " " << flag << " " << toEat << endl;
            if (flag) left = mid+1;
            else right = mid;
        }
        if (!check(2*n-2*left, left)) left--;
        cout << 2*n-2*left << endl;
    }
    return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vint vector<ll>
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios cin.sync_with_stdio(false),cin.tie(NULL)
#define f_(i,m,n) for(ll i=m;i<n;i++)
#define ff first
#define ss second
const int INF=1e9 +7;
const int MOD=998244353;
const int maxn=5002;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;
ll part=0;

ll jam(vint v, ll left , ll right , ll s, ll b, ll r, ll n){
    if(left<0){
        if(right== 2*n){
        	//cout<<"here1 "<<left<<" "<<right<<endl;
            return 0;
        }
        else{
        	//cout<<"here2 "<<left<<" "<<right<<endl;
            return r+1;
        }
    }
    if(right==2*n){
    	//cout<<"here3 "<<left<<" "<<right<<endl;
        return r+1;
    }

    if(s==b){
    	//cout<<"here "<<left<<" "<<right<<endl;
        return r;
    }

    if(v[left]==v[right]){
    	//cout<<"h "<<left <<" "<<right<<endl;
    	if(v[left]==1){
           return min(jam(v, left-1, right , s-1 , b, r+1, n) , jam(v, left , right +1 , s-1 , b, r+1, n));
    	}
    	else{
    		return min(jam(v, left-1, right , s , b-1, r+1, n) , jam(v, left , right +1 , s , b-1, r+1, n));
    	}
    }

    if(s>b){
    	if(v[left]==1){
        	//cout<<"h1 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s-1 , b, r+1, n);
        }
        else if(v[right]==1){
        	//cout<<"h2 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s-1 , b, r+1, n);
        }
    }
    else{
    	if(v[left]==2){
        	//cout<<"h3 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s-1 , b, r+1, n);
        }
        else if(v[right]==2){
        	//cout<<"h4 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s-1 , b, r+1 , n);
        }
    }
}

void solve(){
   ll n;
   cin>>n;

   vint v;
   ll s=0;
   ll b=0;
   f_(i,0,2*n){
     ll x;
     cin>>x;
     v.pb(x);
     if(x==1){
        s++;
     }
     else{
        b++;
     }
   }

   if(min(s, b)==0){
    cout<<max(s,b)<<endl;
    return;
   }

   ll r=0;
   ll start=n-1;
   ll end=n;

   ll ans= jam(v, start , end ,s, b, r, n );

   cout<<ans<<endl;
   return;
}

int main(){
    ll t;
    //t=1;
    cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vint vector<ll>
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios cin.sync_with_stdio(false),cin.tie(NULL)
#define f_(i,m,n) for(ll i=m;i<n;i++)
#define ff first
#define ss second
const int INF=1e9 +7;
const int MOD=998244353;
const int maxn=5002;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;
ll part=0;

ll jam(vint v, ll left , ll right , ll s, ll b, ll r, ll n){
    if(s==b){
    	//cout<<"here "<<left<<" "<<right<<endl;
        return r;
    }

    if(left<0){
        if(right== 2*n){
        	//cout<<"here1 "<<left<<" "<<right<<endl;
            return 0;
        }
        else{
        	//cout<<"here2 "<<left<<" "<<right<<endl;
            return INF;
        }
    }
    if(right==2*n){
    	//cout<<"here3 "<<left<<" "<<right<<endl;
        return INF;
    }

    if(v[left]==v[right]){
    	//cout<<"h "<<left <<" "<<right<<endl;
    	if(v[left]==1){
           return min(jam(v, left-1, right , s-1 , b, r+1, n) , jam(v, left , right +1 , s-1 , b, r+1, n));
    	}
    	else{
    		return min(jam(v, left-1, right , s , b-1, r+1, n) , jam(v, left , right +1 , s , b-1, r+1, n));
    	}
    }

    if(s>b){
    	if(v[left]==1){
        	//cout<<"h1 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s-1 , b, r+1, n);
        }
        else if(v[right]==1){
        	//cout<<"h2 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s-1 , b, r+1, n);
        }
    }
    else{
    	if(v[left]==2){
        	//cout<<"h3 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s , b-1, r+1, n);
        }
        else if(v[right]==2){
        	//cout<<"h4 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s , b-1, r+1 , n);
        }
    }
}

void solve(){
   ll n;
   cin>>n;

   vint v;
   ll s=0;
   ll b=0;
   f_(i,0,2*n){
     ll x;
     cin>>x;
     v.pb(x);
     if(x==1){
        s++;
     }
     else{
        b++;
     }
   }

   if(min(s, b)==0){
    cout<<max(s,b)<<endl;
    return;
   }

   ll r=0;
   ll start=n-1;
   ll end=n;

   ll ans= jam(v, start , end ,s, b, r, n );

   cout<<ans<<endl;
   return;
}

int main(){
    ll t;
    //t=1;
    cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vint vector<ll>
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios cin.sync_with_stdio(false),cin.tie(NULL)
#define f_(i,m,n) for(ll i=m;i<n;i++)
#define ff first
#define ss second
const int INF=1e9 +7;
const int MOD=998244353;
const int maxn=5002;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;
ll part=0;

ll jam(vint v, ll left , ll right , ll s, ll b, ll r, ll n){
    if(s==b){
    	//cout<<"here "<<left<<" "<<right<<endl;
        return r;
    }

    if(left<0){
        if(right== 2*n){
        	//cout<<"here1 "<<left<<" "<<right<<endl;
            return r;
        }
        else{
        	//cout<<"here2 "<<left<<" "<<right<<endl;
        	if(v[right]==1){
              return jam(v, left , right+1 , s-1 , b, r+1 , n);
        	}
        	else{
        	      return jam( v, left , right +1 , s, b-1 , r+1 ,n)
        	}
        }
    }
    if(right==2*n){
    	//cout<<"here3 "<<left<<" "<<right<<endl;
        if(v[left]==1){
              return jam(v, left-1 , right , s-1 , b , r+1 , n);
        }
        else{
              return jam( v, left-1 , right , s, b-1 , r+1 , n);
        }
    }

    if(v[left]==v[right]){
    	//cout<<"h "<<left <<" "<<right<<endl;
    	if(v[left]==1){
           return min(jam(v, left-1, right , s-1 , b, r+1, n) , jam(v, left , right +1 , s-1 , b, r+1, n));
    	}
    	else{
    		return min(jam(v, left-1, right , s , b-1, r+1, n) , jam(v, left , right +1 , s , b-1, r+1, n));
    	}
    }

    if(s>b){
    	if(v[left]==1){
        	//cout<<"h1 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s-1 , b, r+1, n);
        }
        else if(v[right]==1){
        	//cout<<"h2 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s-1 , b, r+1, n);
        }
    }
    else{
    	if(v[left]==2){
        	//cout<<"h3 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s-1 , b, r+1, n);
        }
        else if(v[right]==2){
        	//cout<<"h4 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s-1 , b, r+1 , n);
        }
    }
}

void solve(){
   ll n;
   cin>>n;

   vint v;
   ll s=0;
   ll b=0;
   f_(i,0,2*n){
     ll x;
     cin>>x;
     v.pb(x);
     if(x==1){
        s++;
     }
     else{
        b++;
     }
   }

   if(min(s, b)==0){
    cout<<max(s,b)<<endl;
    return;
   }

   ll r=0;
   ll start=n-1;
   ll end=n;

   ll ans= jam(v, start , end ,s, b, r, n );

   cout<<ans<<endl;
   return;
}

int main(){
    ll t;
    //t=1;
    cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vint vector<ll>
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios cin.sync_with_stdio(false),cin.tie(NULL)
#define f_(i,m,n) for(ll i=m;i<n;i++)
#define ff first
#define ss second
const int INF=1e9 +7;
const int MOD=998244353;
const int maxn=5002;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;
ll part=0;

ll jam(vint v, ll left , ll right , ll s, ll b, ll r, ll n){
    if(s==b){
    	//cout<<"here "<<left<<" "<<right<<endl;
        return r;
    }

    if(left<0){
        if(right== 2*n){
        	//cout<<"here1 "<<left<<" "<<right<<endl;
            return r;
        }
        else{
        	//cout<<"here2 "<<left<<" "<<right<<endl;
        	if(v[right]==1){
              return jam(v, left , right+1 , s-1 , b, r+1 , n);
        	}
        	else{
        	      return jam( v, left , right +1 , s, b-1 , r+1 ,n);
        	}
        }
    }
    if(right==2*n){
    	//cout<<"here3 "<<left<<" "<<right<<endl;
        if(v[left]==1){
              return jam(v, left-1 , right , s-1 , b , r+1 , n);
        }
        else{
              return jam( v, left-1 , right , s, b-1 , r+1 , n);
        }
    }

    if(v[left]==v[right]){
    	//cout<<"h "<<left <<" "<<right<<endl;
    	if(v[left]==1){
           return min(jam(v, left-1, right , s-1 , b, r+1, n) , jam(v, left , right +1 , s-1 , b, r+1, n));
    	}
    	else{
    		return min(jam(v, left-1, right , s , b-1, r+1, n) , jam(v, left , right +1 , s , b-1, r+1, n));
    	}
    }

    if(s>b){
    	if(v[left]==1){
        	//cout<<"h1 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s-1 , b, r+1, n);
        }
        else if(v[right]==1){
        	//cout<<"h2 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s-1 , b, r+1, n);
        }
    }
    else{
    	if(v[left]==2){
        	//cout<<"h3 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s-1 , b, r+1, n);
        }
        else if(v[right]==2){
        	//cout<<"h4 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s-1 , b, r+1 , n);
        }
    }
}

void solve(){
   ll n;
   cin>>n;

   vint v;
   ll s=0;
   ll b=0;
   f_(i,0,2*n){
     ll x;
     cin>>x;
     v.pb(x);
     if(x==1){
        s++;
     }
     else{
        b++;
     }
   }

   if(min(s, b)==0){
    cout<<max(s,b)<<endl;
    return;
   }

   ll r=0;
   ll start=n-1;
   ll end=n;

   ll ans= jam(v, start , end ,s, b, r, n );

   cout<<ans<<endl;
   return;
}

int main(){
    ll t;
    //t=1;
    cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vint vector<ll>
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios cin.sync_with_stdio(false),cin.tie(NULL)
#define f_(i,m,n) for(ll i=m;i<n;i++)
#define ff first
#define ss second
const int INF=1e9 +7;
const int MOD=998244353;
const int maxn=5002;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;
ll part=0;

ll jam(vint v, ll left , ll right , ll s, ll b, ll r, ll n){
    if(s==b){
    	//cout<<"here "<<left<<" "<<right<<endl;
        return r;
    }

    if(left<0){
        if(right== 2*n){
        	//cout<<"here1 "<<left<<" "<<right<<endl;
            return 0;
        }
        else{
        	//cout<<"here2 "<<left<<" "<<right<<endl;
            return INF;
        }
    }
    if(right==2*n){
    	//cout<<"here3 "<<left<<" "<<right<<endl;
        return INF;
    }

    if(v[left]==v[right]){
    	//cout<<"h "<<left <<" "<<right<<endl;
    	if(v[left]==1){
           return min(jam(v, left-1, right , s-1 , b, r+1, n) , jam(v, left , right +1 , s-1 , b, r+1, n));
    	}
    	else{
    		return min(jam(v, left-1, right , s , b-1, r+1, n) , jam(v, left , right +1 , s , b-1, r+1, n));
    	}
    }

    if(s>b){
    	if(v[left]==1){
        	//cout<<"h1 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s-1 , b, r+1, n);
        }
        else if(v[right]==1){
        	//cout<<"h2 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s-1 , b, r+1, n);
        }
    }
    else{
    	if(v[left]==2){
        	//cout<<"h3 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s-1 , b, r+1, n);
        }
        else if(v[right]==2){
        	//cout<<"h4 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s-1 , b, r+1 , n);
        }
    }
}

void solve(){
   ll n;
   cin>>n;

   vint v;
   ll s=0;
   ll b=0;
   f_(i,0,2*n){
     ll x;
     cin>>x;
     v.pb(x);
     if(x==1){
        s++;
     }
     else{
        b++;
     }
   }

   if(min(s, b)==0){
    cout<<max(s,b)<<endl;
    return;
   }

   ll r=0;
   ll start=n-1;
   ll end=n;

   ll ans= jam(v, start , end ,s, b, r, n );

   cout<<ans<<endl;
   return;
}

int main(){
    ll t;
    //t=1;
    cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vint vector<ll>
#define pb push_back
#define all(v) v.begin(),v.end()
#define ios cin.sync_with_stdio(false),cin.tie(NULL)
#define f_(i,m,n) for(ll i=m;i<n;i++)
#define ff first
#define ss second
const int INF=1e9 +7;
const int MOD=998244353;
const int maxn=5002;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;
ll part=0;

ll jam(vint v, ll left , ll right , ll s, ll b, ll r, ll n){
    if(s==b){
    	//cout<<"here "<<left<<" "<<right<<endl;
        return r;
    }

    if(left<0){
        if(right== 2*n){
        	//cout<<"here1 "<<left<<" "<<right<<endl;
            return r;
        }
        else{
        	//cout<<"here2 "<<left<<" "<<right<<endl;
        	if(v[right]==1){
              return jam(v, left , right+1 , s-1 , b, r+1 , n);
        	}
        	else{
        	      return jam( v, left , right +1 , s, b-1 , r+1 ,n);
        	}
        }
    }
    if(right==2*n){
    	//cout<<"here3 "<<left<<" "<<right<<endl;
        if(v[left]==1){
              return jam(v, left-1 , right , s-1 , b , r+1 , n);
        }
        else{
              return jam( v, left-1 , right , s, b-1 , r+1 , n);
        }
    }

    if(v[left]==v[right]){
    	//cout<<"h "<<left <<" "<<right<<endl;
    	if(v[left]==1){
           return min(jam(v, left-1, right , s-1 , b, r+1, n) , jam(v, left , right +1 , s-1 , b, r+1, n));
    	}
    	else{
    		return min(jam(v, left-1, right , s , b-1, r+1, n) , jam(v, left , right +1 , s , b-1, r+1, n));
    	}
    }

    if(s>b){
    	if(v[left]==1){
        	//cout<<"h1 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s-1 , b, r+1, n);
        }
        else if(v[right]==1){
        	//cout<<"h2 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s-1 , b, r+1, n);
        }
    }
    else{
    	if(v[left]==2){
        	//cout<<"h3 "<<left <<" "<<right<<endl;
            return jam(v, left-1 , right , s , b-1, r+1, n);
        }
        else if(v[right]==2){
        	//cout<<"h4 "<<left <<" "<<right<<endl;
            return jam(v, left , right +1 , s , b-1, r+1 , n);
        }
    }
}

void solve(){
   ll n;
   cin>>n;

   vint v;
   ll s=0;
   ll b=0;
   f_(i,0,2*n){
     ll x;
     cin>>x;
     v.pb(x);
     if(x==1){
        s++;
     }
     else{
        b++;
     }
   }

   if(min(s, b)==0){
    cout<<max(s,b)<<endl;
    return;
   }

   ll r=0;
   ll start=n-1;
   ll end=n;

   ll ans= jam(v, start , end ,s, b, r, n );

   cout<<ans<<endl;
   return;
}

int main(){
    ll t;
    //t=1;
    cin>>t;
    while(t--){

        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

int n;
vector<int> a;

bool read(){
	if (scanf("%d", &n) != 1)
		return false;
	a.resize(2 * n);
	forn(i, 2 * n)
		scanf("%d", &a[i]);
	return true;
}

void solve(){
	int cur = 0;
	map<int, int> difr;

	difr[0] = 0;
	cur = 0;
	for (int i = n; i < 2 * n; ++i){
		if (a[i] == 1)
			++cur;
		else
			--cur;
		if (!difr.count(cur))
			difr[cur] = i - (n - 1);
	}

	int ans = 2 * n;
	int dif = count(a.begin(), a.end(), 1) - count(a.begin(), a.end(), 2);

	cur = 0;
	for (int i = n - 1; i >= 0; --i){
		if (a[i] == 1)
			++cur;
		else
			--cur;
		if (difr.count(dif - cur))
			ans = min(ans, n - i + difr[dif - cur]);
	}
	if (difr.count(dif)){
		ans = min(ans, difr[dif]);
	}

	printf("%d\n", ans);
}

int main() {
	int tc;
	scanf("%d", &tc);
	forn(_, tc){
		read();
		solve();
	}
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 200000 + 5;
int n, left[maxn], right[maxn], pre_left[maxn], pre_right[maxn];

struct Node {
	int id, vj;
	bool operator < (const Node& rhs) const {
		return vj < rhs.vj;
	}
} vRight[maxn];

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		scanf("%d", &n);
		pre_left[0] = pre_right[0] = 0;
		for (int i = 1; i <= n; i++) scanf("%d", &left[i]);
		for (int i = n; i >= 1; i--) scanf("%d", &right[i]);
		for (int i = 1; i <= n; i++) {
			pre_left[i] = pre_left[i-1] + (left[i] == 1);
			pre_right[i] = pre_right[i-1] + (right[i] == 1);
		}
		for (int i = 0; i <= n; i++) {
			vRight[i].id = i;
			vRight[i].vj = 2*pre_right[i] - i;
		}
		sort(vRight, vRight+n+1);

		int ans = 2*n;
		for (int i = 0; i <= n; i++) {
			Node vLeft = {i, i-2*pre_left[i]};
			int k = upper_bound(vRight, vRight+n+1, vLeft) - vRight;
			if (vRight[k-1].vj == vLeft.vj) ans = min(ans, n*2 - vRight[k-1].id - i);
		}
		printf("%d\n", ans);
	}
	return 0;
}