/**
* author: Binoy Barman
* created: 2025-01-02 20:41:13
**/
#include<bits/stdc++.h>
#ifdef LOCAL
#include "debug/trace.hpp"
#else
#define dbg(...) 42
#define print(...) 42
#endif
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = 1e9;
#define int long long
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Testcase_Handler int tts, tc = 1; cin >> tts; hell: while(tts--)
#define uniq(v) sort(all(v)), v.resize(distance(v.begin(), unique(v.begin(), v.end())))
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {bool first = true;for(auto &x : a) {if(!first) out << ' ';first = false;out << x;}return out;};
namespace Dark_Lord_Binoy {
void preprocess() {}
void setup() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
preprocess();
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
}
int32_t main() {
Dark_Lord_Binoy::setup();
Testcase_Handler {
int n;
cin >> n;
int one = 0, zero = 0, neg = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if(x == 1) one++;
else if(x == 0) zero++;
else neg++;
}
int ans = 0;
while(n > 0) {
if(one >= 1 && neg >= 2) {
ans++;
one--;
neg -= 2;
} else if(zero >= 1 && neg >= 2) {
zero--;
neg -= 2;
} else if(zero >= 2 && neg >= 1) {
zero -= 2;
neg--;
} else if(one >= 2 && neg >= 1) {
ans--;
one -= 2;
neg--;
} else if(one >= 2 && zero >= 1) {
one -= 2;
zero--;
} else if(zero >= 2 && one >= 1) {
zero -= 2;
one--;
} else if(one >= 3) {
ans++;
one -= 3;
} else if(zero >= 3) {
zero -= 3;
} else if(neg >= 3) {
ans--;
neg -= 3;
}
n -= 3;
}
cout << ans << nl;
}
print(_Time_);
return 0;
}