/*CODED BY mahmudulsakib2019
DATE:-27/3/2024;TIME:-17:00 PM
BANGALDESH , SYLHET*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--) {
ll a,b=INT_MAX,c,count;
cin >> a;
bool start=false;
vector<ll>p(a);
vector<ll>q,s;
for(ll i=0;i<a;i++){
cin >> p[i];
}
for(ll i=0;i<a;i++){
if(p[i]==1){
start = true;
b=min(b,i);
}
else if(p[i]==2){
b=INT_MAX;
start = false;
}
else if(p[i]==3){
if(start){
c=i;
count = (c-b)+1;
q.push_back(count);
}
}
}
if (!q.empty()) {
auto it = max_element(q.begin(), q.end());
cout << *it << endl;
}
else{
cout << 0 << endl;
}
}
return 0;
}