#include <bits/stdc++.h>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define ll long long int
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mx_ele(v) *max_element(v.begin(),v.end())
#define mnm_ele(v) *min_element(v.begin(),v.end())
#define endl "\n"
using namespace std;
void smile()
{
int N;
cin >> N;
vector<int> arr(N);
int sum = 0;
for (int i = 0; i < N; i++) {
cin >> arr[i];
sum += arr[i];
}
int remainder = sum % 3;
int result = 0;
if (remainder == 1) {
for (int i = 0; i < N; i++) {
if (arr[i] % 3 == 1) {
result = N - 1;
break;
}
}
if (result == 0) {
int count = 0;
for (int i = 0; i < N; i++) {
if (arr[i] % 3 == 2) {
count++;
}
if (count == 2) {
result = N - 2;
break;
}
}
}
} else if (remainder == 2) {
for (int i = 0; i < N; i++) {
if (arr[i] % 3 == 2) {
result = N - 1;
break;
}
}
if (result == 0) {
int count = 0;
for (int i = 0; i < N; i++) {
if (arr[i] % 3 == 1) {
count++;
}
if (count == 2) {
result = N - 2;
break;
}
}
}
} else
{
result = N;
}
cout << result << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--)
{
smile();
}
}