#include <iostream>
#include <cstring>
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int ca[N * 2], cb[N * 2],a[N<<1];
/*
void get(int n, int *bucket) {
memset(bucket, 0, sizeof (int) * (n * 2 + 3));
int last = 0, cnt = 0;
for (int i = 1; i <= n; i++) {
int temp;
cin >> temp;
if (temp == last)
cnt++;
else {
bucket[last] = max(bucket[last], cnt);
last = temp;
cnt = 1;
}
}
bucket[last] = max(bucket[last], cnt);
}
*/
void get(int n,int *b)//time-time 传输
{
memset(b,0,sizeof(int)*(n*2+3));
for(int i=1;i<=n;i++) cin>>a[i];
int last=a[1],cnt=1;
for(int i=2;i<=n;i++)
{
if(a[i]==last) cnt++;
else
{
b[last]=max(b[last],cnt);
last=a[i];
cnt=1;
}
}
b[a[n]]= max(b[a[n]], cnt);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
get(n, ca);
get(n, cb);
int ans = 0;
for (int i = 1; i <= (n << 1); i++)
ans = max(ans, ca[i] + cb[i]);
cout << ans << '\n';
}
return 0;
}