#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;
if(cntn1 >= 2*cnt1){
result += cnt1;
cntn1 -= (2*cnt1);
cnt1 = 0;
if(cntn1 >= 2*cnt0){
cntn1 -= (2*cnt0);
cnt0 = 0;
}
else{
cntn1 =0;
cnt0 =0;
}
result -= (cntn1/3);
}
else{
result += cntn1/2;
cnt1 -= cntn1/2;
cntn1 %= 2;
result += cnt1/3;
cnt1 %= 3;
if(!cnt0 and cntn1) result--;
}
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;
}