#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define trace(x) cerr << #x << ": " << x << '\n'
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int c0 = 0, c1 = 0, cm1 = 0, ans = 0;
f(i, n)
{
int x;
cin >> x;
if (x == 0)
c0++;
else if (x == 1)
c1++;
else
cm1++;
}
ll t1 = min((ll)(cm1 / 2), (ll)c1);
ans += t1;
cm1 -= 2 * t1;
c1 -= t1;
ll t2 = c1 / 3;
ans += t2;
c1 -= 3 * t2;
ll t3 = min((ll)(cm1 / 2), (ll)c0);
cm1 -= 2 * t3;
c0 -= t3;
ll t4 = min((ll)(c1 / 2), (ll)c0);
c1 -= 2 * t4;
c0 -= t4;
ll t5 = min({(ll)cm1, (ll)c1, (ll)c0});
cm1 -= t5;
c1 -= t5;
c0 -= t5;
ll t6 = min((ll)cm1, (ll)(c0 / 2));
cm1 -= t6;
c0 -= 2 * t6;
ll t7 = min((ll)c1, (ll)(c0 / 2));
c1 -= t7;
c0 -= 2 * t7;
ll t8 = c0 / 3;
c0 -= 3 * t8;
ll t9 = cm1 / 3;
ans -= t9;
cm1 -= 3 * t9;
ll t10 = min((ll)cm1, (ll)(c1 / 2));
ans -= t10;
cm1 -= t10;
c1 -= 2 * t10;
cout << ans << '\n';
}
}