#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl '\n'
void edm()
{
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
}
void solve()
{
int n;cin>>n;
int one=0,zero=0,mn=0;
for(int i=0;i<n;i++)
{
int x;cin>>x;
if(x==1)one++;
else if(x==0)zero++;
else mn++;
}
int ans=0;
ans = ans + min(one,mn/2);
one = one - ans;
mn = mn - 2*ans;
if(one && zero && mn)
{
one--;
zero--;
mn--;
}
ans = ans + one/3;
one = one%3;
int xt = min(2*zero,mn);
mn = mn - xt + one;
zero = zero - xt;
ans = ans - mn/3;
cout<<ans<<endl;
}
int32_t main()
{
//edm();
int t = 1;
cin>>t;
for(int i=1;i<=t;i++)
{
solve();
}
}