#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void solve(){
int n;
cin>>n;
int cnt0=0,cnt1 =0, cntn1=0;
for(int i=0; i<n; i++){
int x;
cin>>x;
if(x==0) cnt0++;
else if(x==1) cnt1++;
else cntn1++;
}
int result = 0;
int n1cnt = cntn1/2;
result += min(n1cnt,cnt1);
cnt1 -= result;
cntn1 -= (2*result);
int cnt11 = cnt1/3;
result += cnt11;
cnt1 %= 3;
n1cnt = cntn1/2;
int zac = min(n1cnt,cnt0);
cntn1 -= 2*zac;
cnt0 -= zac;
if(cntn1){
result -= (cntn1+cnt1)/3;
}
cout<<result<<endl;
}
signed main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
optimize();
ll t;
cin>>t;
for(ll i=1; i<=t; i++){
solve();
}
return 0;
}