#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end(); 
#define F first
#define S second
#define ll long long
#define int long long
using namespace std;
const int maxn = 2e5 + 5;
int n,a[maxn];
signed main(){
	int tt = 1;
	
	cin >> tt;
	
	for(int ii = 1; ii <= tt; ii++){
		cin >> n;
	
		int cnt[3];
		cnt[0] = cnt[1] = cnt[2] = 0;
		
		for(int i = 1; i <= n; i++){
			cin >> a[i];
			cnt[a[i] + 1]++;
		}
		
		int ans = 0;
		
		while(cnt[0] > 1 && cnt[2]){
			ans++;
			cnt[0] -= 2;
			cnt[2]--;
		}
		
		while(cnt[2] > 2){
			ans++;
			cnt[2] -= 3;
		}
		
		while(cnt[0] + cnt[1] > 2){
			if(cnt[0] > 1){
				cnt[0] -= 2;
				cnt[1]--;
			}
			else {
				cnt[1] -= 2;
				cnt[0]--;
			}
		}
		
		while(cnt[0] && cnt[2]){
			if(cnt[2] > 1){
				ans--;
				cnt[2] -= 2;
				cnt[0]--;
			}
			else break;
		}
		
		cout << ans << '\n';
		
	}
	
	return 0;
}