// Author: Gourav Preet Gupta
// Language: C++
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define float long double
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define PI 3.141592653589793
#define Mod 1000000007
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef priority_queue<ll> pq;
typedef priority_queue<pair<ll,ll> > pqp;
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
/*
****************************************LOVE YOU MAA***************************************************
**********************************FAMILY ABOVE ALL*****************************************************
**************************************GIVE ME SOME SUNSHINE , GIVE ME SOME RAIN************************
******************************GIVE ME ANOTHER CHANCE , I WANNA GROW UP ONCE AGAIN**********************
**************************************YE DIL MAANGE MORE***********************************************
**************************SHAURYAM DAKSHAM YUDDHE,BALIDAAN PARAM DHARMA********************************
*/
// Never Stop Trying.
// Trying to be Better than Myself.
// while(true)
// {
// if(AC)
// {
// break;
// }
// else if(Contest Over)
// {
// Try.
// Check out Editorial.
// Understand.
// Find out your Mistake.
// Learn the topic (if new).
// Solve Problems on that topic (if new).
// Upsolve that problem.
// break;
// }
// else
// {
// Try.
// Use Pen-Paper.
// Find errors, edge cases, etc.
// continue;
// }
// }
//Remember,mazaa journey mein jyaada hai,manzil main utna nahi....
const int N=1e5+5;
void solve()
{
ll n;
cin>>n;
vll v(n);
for(ll i=0; i<n; i++)
{
cin>>v[i];
}
ll zero=0ll, one=0ll, none=0ll;
for(ll i=0; i<n; i++)
{
if(v[i]==0ll)
zero++;
else if(v[i]==1ll)
one++;
else
none++;
}
ll ans = 0ll;
if(one && none)
{
ll mini = min(none/2,one);
ans+=mini;
none-=2*mini;
one-=mini;
}
if(one)
{
ll mini = one/3;
ans+=mini;
one-=3*mini;
}
if(none && zero)
{
ll mini = min(none/2,zero);
none-=2*mini;
zero-=mini;
}
if(none)
{
ll mini = none/3;
ans-=mini;
none-=3*mini;
}
if(one && none && !zero)
{
ll mini = min(one/2,none);
ans-=mini;
one-=2*mini;
none-=mini;
}
cout<<ans<<endl;
}
int main()
{
IOS;
ll t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}