You are given an array $a$ consisting of $n$ integers $a_1, a_2, \dots , a_n$.

In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For example, from the array $[2, 1, 4]$ you can obtain the following arrays: $[3, 4]$, $[1, 6]$ and $[2, 5]$.

Your task is to find the maximum possible number of elements divisible by $3$ that are in the array after performing this operation an arbitrary (possibly, zero) number of times.

You have to answer $t$ independent queries.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of queries.

The first line of each query contains one integer $n$ ($1 \le n \le 100$).

The second line of each query contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$). 


-----Output-----

For each query print one integer in a single line — the maximum possible number of elements divisible by $3$ that are in the array after performing described operation an arbitrary (possibly, zero) number of times.


-----Example-----
Input
2
5
3 1 2 3 1
7
1 1 1 1 1 2 2

Output
3
3



-----Note-----

In the first query of the example you can apply the following sequence of operations to obtain $3$ elements divisible by $3$: $[3, 1, 2, 3, 1] \rightarrow [3, 3, 3, 1]$.

In the second query you can obtain $3$ elements divisible by $3$ with the following sequence of operations: $[1, 1, 1, 1, 1, 2, 2] \rightarrow [1, 1, 1, 1, 2, 3] \rightarrow [1, 1, 1, 3, 3] \rightarrow [2, 1, 3, 3] \rightarrow [3, 3, 3]$.

Difficulty: EASY
Tags: Mathematics

Starter code:

Solutions:
t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	zero = []
	one = []
	two = []
	count = 0
	for item in a:
		if item % 3 == 0:
			zero.append(item)
		elif item % 3 == 1:
			one.append(item)
		elif item % 3 == 2:
			two.append(item)
	if len(one) > len(two):
		count = count + len(two) + len(zero) + (len(one) - len(two)) // 3
	elif len(two) > len(one):
		count = count + len(one) + len(zero) + (len(two) - len(one)) // 3
	else:
		count = count + len(zero) + len(one)
	print(count)


import bisect
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	k = 0
	for j in range(len(a)):
		if a[j] % 3 == 0:
			a[j] = 0
			k = k + 1
	while 0 in a:
		a.remove(0)
	a.sort()
	p = 0
	q = len(a) - 1
	while p < q:
		if (a[p] + a[q]) % 3 == 0:
			k = k + 1
			a.remove(a[q])
			a.remove(a[p])
			p = 0
			q = len(a) - 1
			continue
		else:
			q = q - 1
	while len(a) > 2:
		j = 3
		m = sum(a[:j])
		if m % 3 == 0:
			k = k + 1
			for q in range(j):
				a.pop(0)
			bisect.bisect(a, m)
	print(k)


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		total = 0
		ones = 0
		twos = 0
		for j in range(n):
			arr[j] = arr[j] % 3
			if arr[j] == 0:
				total += 1
			elif arr[j] == 1:
				ones += 1
			else:
				twos += 1
		curr = min(ones, twos)
		total += curr
		ones -= curr
		twos -= curr
		if ones > 0:
			total += ones // 3
		else:
			total += twos // 3
		print(total)
main()


n = int(input())
while n != 0:
	s = int(input())
	l = list(map(int, input().split()))
	two = 0
	one = 0
	count = 0
	for k in l:
		if k % 3 == 0:
			i = 3
		else:
			i = k % 3
		if i == 3:
			count = count + 1
		elif i == 2:
			two += 1
		elif i == 1:
			one += 1
	if two > one and two != 0 and (one != 0):
		count = count + one
		two = two - one
		count = count + two // 3
	elif two < one and two != 0 and (one != 0):
		count = count + two
		one = one - two
		count = count + one // 3
	elif two == one and two != 0 and (one != 0):
		count = count + two
	if two == 0 and one >= 3:
		one = one - two
		count = count + one // 3
	if one == 0 and two >= 3:
		two = two - one
		count = count + two // 3
	print(count)
	n -= 1


def MyInput(Flag):
	return_list = []
	if Flag:
		while True:
			try:
				a = input()
				if a:
					return_list.append(a)
				else:
					return return_list
					break
			except EOFError:
				return return_list
	else:
		with open('input.txt') as f:
			return_list = f.read().split('\n')
			return return_list

def MyOutput(Flag, mystr):
	if Flag:
		print(mystr)
	else:
		with open('output.txt', 'a') as f:
			f.write(mystr + '\n')
flag = 1
param = MyInput(flag)
count3 = 0
count2 = 0
count1 = 0
result = ''
for i in range(int(param[0])):
	n = int(param.pop(1))
	an = [int(x1) for x1 in param.pop(1).split()]
	for x in an:
		if not x % 3:
			count3 += 1
			continue
		elif x % 3 == 2:
			count2 += 1
		else:
			count1 += 1
	c1 = abs(count2 - count1) // 3
	c2 = min(count2, count1)
	count3 = count3 + c1 + c2
	print(count3)
	count3 = 0
	count2 = 0
	count1 = 0


t = int(input())
while t > 0:
	n = int(input())
	c0 = 0
	c1 = 0
	c2 = 0
	a = [int(x) for x in input().split()]
	for i in range(n):
		x = a[i]
		if x % 3 == 0:
			c0 = c0 + 1
		elif x % 3 == 1:
			c1 = c1 + 1
		elif x % 3 == 2:
			c2 = c2 + 1
	if c2 >= c1:
		c0 = c0 + c1 + (c2 - c1) // 3
	elif c2 < c1:
		c0 = c0 + c2 + (c1 - c2) // 3
	print(c0)
	t = t - 1


t = int(input())
for _ in range(t):
	n = int(input())
	arr = map(int, input().split())
	(mod_0, mod_1, mod_2) = (0, 0, 0)
	for el in arr:
		if el % 3 == 0:
			mod_0 += 1
		elif el % 3 == 1:
			mod_1 += 1
		elif el % 3 == 2:
			mod_2 += 1
	res = mod_0
	min_1_2 = min(mod_1, mod_2)
	res += min_1_2
	mod_1 -= min_1_2
	mod_2 -= min_1_2
	res += mod_1 // 3
	res += mod_2 // 3
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	j = []
	count = 0
	one = 0
	two = 0
	for j in range(n):
		if l[j] % 3 == 0:
			count = count + 1
		elif l[j] % 3 == 1:
			l[j] = 1
			one = one + 1
		else:
			l[j] = 2
			two = two + 1
	if one >= two:
		count = count + two
		count = count + (one - two) // 3
	elif two > one:
		count = count + one
		count = count + (two - one) // 3
	print(count)


for _ in range(int(input())):
	n = int(input())
	(ans, o, t) = (0, 0, 0)
	for el in map(int, input().split()):
		if el % 3 == 0:
			ans += 1
		elif el % 3 == 1:
			o += 1
		else:
			t += 1
	ans += min(o, t)
	(o, t) = (o - min(o, t), t - min(o, t))
	ans += o // 3 + t // 3
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(lambda x: int(x) % 3, input().split()))
	su = l.count(0)
	a = l.count(1)
	b = l.count(2)
	t = min(a, b)
	su += t
	a = a - t
	b = b - t
	su += a // 3 + b // 3
	print(su)


import sys
sys.setrecursionlimit(1000000)

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = self.next_line()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_line(self):
		return sys.stdin.readline().split()

	def next_ints(self):
		return [int(x) for x in sys.stdin.readline().split()]

	def next_int(self):
		return int(self.next())

	def solve(self):
		ca = self.next_int()
		for _ in range(ca):
			n = self.next_int()
			x = [a % 3 for a in self.next_ints()]
			r = x.count(0)
			c1 = x.count(1)
			c2 = x.count(2)
			cc = min(c1, c2)
			print(r + cc + (c1 - cc) // 3 + (c2 - cc) // 3)
Main().solve()


import sys, math, bisect
inf = float('inf')
mod = inf + 7

def lcm(a, b):
	return int(a / math.gcd(a, b) * b)

def gcd(a, b):
	return int(math.gcd(a, b))

def binarySearch(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def lowerBound(a, x):
	i = bisect.bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def upperBound(a, x):
	i = bisect.bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i - 1
	else:
		return -1

def freq(a, x):
	z = upperBound(a, x) - lowerBound(a, x)
	if z <= 0:
		return 0
	return z
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt_0 = 0
	cnt_1 = 0
	cnt_2 = 0
	for i in range(n):
		x = arr[i] % 3
		if x == 0:
			cnt_0 += 1
		elif x == 1:
			cnt_1 += 1
		else:
			cnt_2 += 1
	ans = cnt_0
	while cnt_1 and cnt_2:
		ans += 1
		cnt_1 -= 1
		cnt_2 -= 1
	ans += math.floor(cnt_1 / 3)
	ans += math.floor(cnt_2 / 3)
	print(ans)


n1 = int(input())
lists = [[] for _ in range(n1)]
for lis in lists:
	x = int(input())
	y = input().split()
	lis.extend([int(k) for k in y])
for lis in lists:
	x = []
	y = []
	count = 0
	for i in range(0, len(lis)):
		if lis[i] % 3 == 1:
			x.append(lis[i])
		elif lis[i] % 3 == 2:
			y.append(lis[i])
		else:
			count += 1
	a = len(x)
	b = len(y)
	if a > b:
		a = a - b
		count = count + b + a // 3
	elif b > a:
		b = b - a
		count = count + a + b // 3
	else:
		count = count + a
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = [0] * 3
	for j in range(n):
		d[a[j] % 3] += 1
	num = 0
	num += d[0]
	k = min(d[1], d[2])
	num += k
	(d[1], d[2]) = (d[1] - k, d[2] - k)
	num += d[1] // 3
	num += d[2] // 3
	print(num)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	(a, b, c) = (0, 0, 0)
	ans = 0
	for i in l:
		if i % 3 == 0:
			a += 1
		elif i % 3 == 1:
			b += 1
		else:
			c += 1
	ans = a + min(b, c)
	fact = min(b, c)
	b -= fact
	c -= fact
	ans += b // 3 + c // 3
	print(ans)


t = int(input())
for j in range(t):
	n = int(input())
	c = [0] * 3
	ans = 0
	x = list(map(int, input().split()))
	for i in x:
		c[i % 3] += 1
	ans += c[0]
	ans += min(c[2], c[1])
	temp = min(c[2], c[1])
	c[1] -= temp
	c[2] -= temp
	ans += int(c[2] / 3)
	ans += int(c[1] / 3)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	ll = list(map(int, input().split()))
	for i in range(len(ll)):
		ll[i] = ll[i] % 3
	z = one = tw = 0
	for i in range(len(ll)):
		if ll[i] == 0:
			z += 1
		elif ll[i] == 1:
			one += 1
		elif ll[i] == 2:
			tw += 1
	f = min(one, tw)
	print(z + f + (one - f) // 3 + (tw - f) // 3)


def fun(l, n):
	c = 0
	a = [0, 0, 0]
	for x in l:
		if x % 3 == 0:
			c += 1
		elif x % 3 == 1:
			if a[2] > 0:
				a[2] -= 1
				c += 1
			else:
				a[1] += 1
		elif a[1] > 0:
			a[1] -= 1
			c += 1
		else:
			a[2] += 1
	c += a[1] // 3
	c += a[2] // 3
	return c
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	print(fun(l, n))


for z in ' ' * int(input()):
	input()
	k = [int(i) % 3 for i in input().split()]
	(a, b, c) = [k.count(i) for i in (0, 1, 2)]
	d = min(b, c)
	e = (b - d) // 3 + (c - d) // 3
	print(a + d + e)


n = int(input())
for i in range(0, n):
	x = int(input())
	a = input().split()
	s = [int(num) for num in a]
	q = 0
	w = 0
	e = 0
	for i in s:
		if i % 3 == 0:
			q += 1
		elif i % 3 == 1:
			w += 1
		elif i % 3 == 2:
			e += 1
	if w > e:
		q += e
		q += (w - e) // 3
	else:
		q += w
		q += (e - w) // 3
	print(q)


a = int(input())
for rainbow in range(a):
	n = int(input())
	arr = [i % 3 for i in map(int, input().split())]
	print(arr.count(0) + min(arr.count(1), arr.count(2)) + (max(arr.count(1), arr.count(2)) - min(arr.count(1), arr.count(2))) // 3)


def test(file='in.txt'):
	import sys
	sys.stdin = open(file, 'r')
	main()

def main():
	for t in range(int(input())):
		n = int(input())
		md = [0, 0, 0]
		for x in input().split():
			md[int(x) % 3] += 1
		cnt = md[0]
		mn = min(md[1], md[2])
		cnt += mn
		if md[1] > md[2]:
			cnt += (md[1] - mn) // 3
		elif md[2] > md[1]:
			cnt += (md[2] - mn) // 3
		print(cnt)
main()


q = int(input())
for _ in range(0, q):
	ans = 0
	a = [0, 0, 0]
	n = int(input())
	b = input().split()
	for i in b:
		x = int(i)
		a[x % 3] += 1
	print((max(a[1], a[2]) - min(a[1], a[2])) // 3 + min(a[1], a[2]) + a[0])


t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	count = 0
	a = [i % 3 for i in b]
	count = a.count(0)
	count1 = a.count(1)
	count2 = a.count(2)
	count += count2 if count1 >= count2 else count1
	if count1 > count2:
		count += (count1 - count2) // 3
	elif count2 > count1:
		count += (count2 - count1) // 3
	print(count)


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	lst = [ele % 3 for ele in lst]
	d = {}
	for ele in lst:
		if ele in d:
			d[ele] += 1
		else:
			d[ele] = 1
	if 0 in d:
		count = d[0]
	else:
		count = 0
	if 2 in d and 1 in d:
		t = min(d[2], d[1])
		d[2] -= t
		d[1] -= t
		count += t
	if 2 in d and d[2] >= 3:
		count += d[2] // 3
	if 1 in d and d[1] >= 3:
		count += d[1] // 3
	print(count)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	m1 = 0
	m2 = 0
	m0 = 0
	for i in arr:
		if i % 3 == 0:
			m0 += 1
		elif i % 3 == 1:
			m1 += 1
		else:
			m2 += 1
	ans = m0
	ans += min(m1, m2)
	temp = min(m1, m2)
	m1 -= temp
	m2 -= temp
	ans += m1 // 3
	ans += m2 // 3
	print(ans)


from collections import Counter
q = int(input())
while q:
	n = int(input())
	nums = list(map(lambda x: int(x) % 3, input().split(' ')))
	c = Counter(nums)
	if c[2] >= c[1]:
		c[0] += c[1]
		c[2] -= c[1]
		c[1] = 0
		c[0] += c[2] // 3
	if c[1] > c[2]:
		c[0] += c[2]
		c[1] -= c[2]
		c[2] = 0
		c[0] += c[1] // 3
	print(c[0])
	q -= 1


t = eval(input())
for y in range(t):
	w = eval(input())
	str = input()
	l = str.split()
	d = {0: 0, 1: 0, 2: 0}
	for x in range(len(l)):
		a = int(l[x])
		rem = a % 3
		d[rem] += 1
	sum = d[0]
	sum += abs(d[1] - d[2]) // 3
	sum += min(d[1], d[2])
	print(sum)


t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	a = list(map(int, input().split(' ')))
	p1 = 0
	p2 = 0
	for c in a:
		k = c % 3
		if k == 0:
			ans += 1
		elif k == 1:
			p1 += 1
		else:
			p2 += 1
	m = min(p1, p2)
	ans += m
	p1 -= m
	p2 -= m
	if p1 != 0:
		ans += p1 // 3
	else:
		ans += p2 // 3
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	p = [0] * 3
	for x in a:
		p[x % 3] += 1
	pp = min(p[1], p[2])
	ans = p[0] + pp
	p[1] -= pp
	p[2] -= pp
	ans += p[1] // 3 + p[2] // 3
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * 3
	for i in range(n):
		c[a[i] % 3] += 1
	print(c[0] + abs(c[1] - c[2]) // 3 + min(c[1], c[2]))


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	(p0, p1, p2) = (0, 0, 0)
	for el in a:
		if el % 3 == 0:
			p0 += 1
		elif el % 3 == 1:
			p1 += 1
		else:
			p2 += 1
	return p0 + min(p1, p2) + (max(p1, p2) - min(p1, p2)) // 3
q = int(input())
for i in range(q):
	print(solve())


from collections import Counter
t = int(input())
for query in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = [i % 3 for i in A]
	C = Counter(B)
	ANS = C[0]
	x = min(C[1], C[2])
	ANS += x
	C[1] -= x
	C[2] -= x
	ANS += C[1] // 3 + C[2] // 3
	print(ANS)


def solve():
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	ones = 0
	twos = 0
	for m in l:
		if m % 3 == 0:
			ans += 1
		elif m % 3 == 1:
			ones += 1
		else:
			twos += 1
	z = min(ones, twos)
	ones = ones - z
	twos = twos - z
	ans += ones // 3 + z + twos // 3
	return ans
for _ in range(int(input())):
	print(solve())


t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	B = [a % 3 for a in A]
	C = [0] * 3
	for b in B:
		C[b] += 1
	ans = 0
	ans += C[0]
	ans += min(C[1], C[2])
	ans += (max(C[1], C[2]) - min(C[1], C[2])) // 3
	print(ans)


for i in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	c3 = 0
	for i in range(n):
		if l1[i] % 3 == 0:
			c3 += 1
		elif l1[i] % 3 == 1:
			if c2 > 0:
				c2 -= 1
				c3 += 1
			else:
				c1 += 1
		elif l1[i] % 3 == 2:
			if c1 > 0:
				c1 -= 1
				c3 += 1
			else:
				c2 += 1
	c3 += c1 // 3 + c2 // 3
	print(c3)


for _ in [0] * int(input()):
	input()
	c = [0] * 3
	for x in map(int, input().split()):
		c[x % 3] += 1
	(x, y, z) = c
	if y > z:
		(y, z) = (z, y)
	print(x + y + (z - y) // 3)


x = int(input())
for i in range(x):
	a = input()
	b = input()
	c = b.split()
	d = [int(d) for d in c]
	t = []
	for num in d:
		t.append(num % 3)
	p = t.count(0)
	q = min(t.count(1), t.count(2))
	remcount_1or2 = max(t.count(1), t.count(2)) - q
	h = 0
	if remcount_1or2 >= 3:
		h = h + remcount_1or2 // 3
	print(p + q + h)


for t in range(int(input())):
	(n, d) = (input(), [0, 0, 0])
	for num in map(int, input().split()):
		d[num % 3] += 1
		m = min((d[1], d[2]))
	print(d[0] + m + (d[1] - m) // 3 + (d[2] - m) // 3)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	count_0 = 0
	count_1 = 0
	count_2 = 0
	for a in arr:
		value = a % 3
		if value == 1:
			count_1 += 1
		elif value == 2:
			count_2 += 1
		elif value == 0:
			count_0 += 1
	ans = 0
	ans += min(count_1, count_2)
	count_1 -= ans
	count_2 -= ans
	ans += count_1 // 3
	ans += count_2 // 3
	ans += count_0
	print(ans)


from collections import Counter
q = int(input())

def solve(t):
	p = map(lambda x: x % 3, t)
	c = Counter(p)
	r = c[0]
	t = min(c[1], c[2])
	r += t
	c[1] -= t
	c[2] -= t
	r += c[1] // 3
	r += c[2] // 3
	return r
for _ in range(q):
	_ = input()
	a = [int(x) for x in input().split()]
	print(solve(a))


import sys
inf = float('inf')
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
(mod, MOD) = (1000000007, 998244353)
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
t = int(input())
while t > 0:
	n = int(input())
	Arr = get_array()
	count_0 = 0
	count_1 = 0
	count_2 = 0
	for i in Arr:
		if i % 3 == 0:
			count_0 += 1
		elif i % 3 == 1:
			count_1 += 1
		else:
			count_2 += 1
	z = min(count_1, count_2)
	ans = count_0 + z
	count_1 -= z
	count_2 -= z
	ans += count_1 // 3 + count_2 // 3
	print(ans)
	t -= 1


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	c1 = 0
	c2 = 0
	for ele in a:
		if ele % 3 == 0:
			ans += 1
		elif ele % 3 == 1:
			c1 += 1
		else:
			c2 += 1
	if c2 >= c1:
		ans += c1
		c2 -= c1
		ans += c2 // 3
	else:
		ans += c2
		c1 -= c2
		ans += c1 // 3
	print(ans)


for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = [0] * 3
	for i in l:
		d[i % 3] += 1
	c = d[0]
	m = min(d[1], d[2])
	c = c + m
	(d[1], d[2]) = (d[1] - m, d[2] - m)
	c = c + d[1] // 3 + d[2] // 3
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(a) for a in input().split()]
	p = [0] * 3
	for j in a:
		p[j % 3] += 1
	c = p[0] + min(p[1], p[2]) + (max(p[1], p[2]) - min(p[1], p[2])) // 3
	print(c)


import math

def counter(a, k):
	x = list(filter(lambda x: x == k, a))
	return len(x)
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(0, n):
		a[i] = a[i] % 3
	a.sort()
	z = []
	for i in range(0, 3):
		count = counter(a, i)
		z.append(count)
	ans = z[0] + min(z[1], z[2]) + math.fabs(z[1] - z[2]) // 3
	print(int(ans))
	t -= 1


try:
	t = int(input())
	for __ in range(t):
		n = int(input())
		l = list(map(int, input().split()))
		nl = []
		n1 = 0
		n2 = 0
		n3 = 0
		for _ in l:
			if _ % 3 == 1:
				n1 += 1
			elif _ % 3 == 2:
				n2 += 1
			else:
				n3 += 1
		if n1 > n2:
			n3 += n2 + (n1 - n2) // 3
		elif n1 < n2:
			n3 += n1 + (n2 - n1) // 3
		else:
			n3 += n2
		print(n3)
except:
	pass


t = int(input())
for i in range(t):
	n = int(input())
	for j in range(1):
		arr = []
		ans = 0
		two = 0
		one = 0
		arr = list(map(int, input().split()))
		for elem in arr:
			if elem % 3 == 0:
				ans += 1
			if elem % 3 == 1:
				one += 1
			if elem % 3 == 2:
				two += 1
		min_val = min(one, two)
		ans += min_val
		if one == min_val:
			ans += (two - min_val) // 3
		else:
			ans += (one - min_val) // 3
	print(ans)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	n = I()
	l = L()
	d = {0: 0, 1: 0, 2: 0}
	for i in l:
		d[i % 3] += 1
	a = d[0] + min(d[1], d[2]) + (d[1] - min(d[1], d[2])) // 3 + (d[2] - min(d[1], d[2])) // 3
	print(a)


from collections import Counter as C
for TT in range(1, int(input()) + 1):
	n = int(input())
	c = C(map(lambda x: int(x) % 3, input().split()))
	(x, y, z) = (c.get(0, 0), c.get(1, 0), c.get(2, 0))
	d = min(y, z)
	y -= d
	z -= d
	x += d
	y //= 3
	z //= 3
	print(x + y + z)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = [0] * n
	ans = 0
	ans1 = 0
	for j in range(n):
		if l[j] % 3 == 1:
			l1[j] = 1
			ans += 1
		if l[j] % 3 == 2:
			l1[j] = -1
			ans1 += 1
	c = min(ans, ans1)
	print(n - ans - ans1 + c + (ans - c) // 3 + (ans1 - c) // 3)


t = int(input())
for _ in range(t):
	input()
	k = [int(i) % 3 for i in input().split()]
	(a, b, c) = [k.count(i) for i in (0, 1, 2)]
	print(a + min(b, c) + abs(b - c) // 3)


for _ in range(int(input())):
	n = int(input())
	k = [*map(int, input().split())]
	p = [0] * 3
	for z in k:
		p[z % 3] += 1
	print(p[0] + abs(p[1] - p[2]) // 3 + min(p[1], p[2]))


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c0 = 0
	c1 = 0
	c2 = 0
	for i in l:
		if i % 3 == 0:
			c0 = c0 + 1
		elif i % 3 == 1:
			c1 = c1 + 1
		else:
			c2 = c2 + 1
	r = c0
	m = min(c1, c2)
	r = r + m
	c1 = c1 - m
	c2 = c2 - m
	r = r + (c1 + c2) // 3
	print(r)


t = int(input(''))
for i in range(t):
	n = int(input(''))
	X = list(map(int, input('').split()))
	L = []
	T = []
	count = 0
	for j in X:
		if j % 3 == 0:
			count += 1
		else:
			T.append(j)
	L = list(map(lambda x: x % 3, T))
	(a, b) = (0, 0)
	for j in L:
		if j == 1:
			a += 1
		if j == 2:
			b += 1
	if a >= b:
		count = count + b + int((a - b) / 3)
	else:
		count = count + a + int((b - a) / 3)
	print(count)


for _ in range(int(input())):
	n = int(input())
	arr = [x % 3 for x in map(int, input().split())]
	z = o = t = 0
	for x in arr:
		if x == 0:
			z += 1
		elif x == 1:
			o += 1
		else:
			t += 1
	(a, b) = (o, t) if o > t else (t, o)
	print(z + b + (a - b) // 3)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if l[i] % 3 == 0:
			ans += 1
			l[i] = 0
		else:
			l[i] = l[i] % 3
	x = l.count(1)
	y = l.count(2)
	ans += min(x, y)
	if x > y:
		ans += (x - min(x, y)) // 3
	else:
		ans += (y - min(x, y)) // 3
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * 3
	for j in range(n):
		c[a[j] % 3] += 1
	c0 = c[0]
	c1 = c[1]
	c2 = c[2]
	ans = c0 + min(c1, c2) + (max(c1, c2) - min(c1, c2)) // 3
	print(ans)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	one = 0
	two = 0
	count = 0
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	for i in range(len(arr)):
		if arr[i] % 3 == 0:
			count += 1
		elif arr[i] % 3 == 1:
			one += 1
		elif arr[i] % 3 == 2:
			two += 1
	if one > two:
		count += two
		one -= two
		two = 0
	else:
		count += one
		two -= one
		one = 0
	count += one // 3
	count += two // 3
	print(count)


n = int(input())

def min1(a, b):
	if a > b:
		return b
	else:
		return a
for i in range(n):
	q = int(input())
	arr = input()
	arr = arr.split(' ')
	ones = 0
	twos = 0
	threes = 0
	for item in arr:
		if int(item) % 3 == 0:
			threes += 1
		elif int(item) % 3 == 1:
			ones += 1
		elif int(item) % 3 == 2:
			twos += 1
	print(threes + min1(ones, twos) + abs(ones - twos) // 3)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	dic = {1: 0, 2: 0}
	for item in a:
		if item % 3 == 0:
			cnt += 1
		elif item % 3 == 1 and dic[2]:
			cnt += 1
			dic[2] -= 1
		elif item % 3 == 1:
			dic[1] += 1
		elif item % 3 == 2 and dic[1]:
			cnt += 1
			dic[1] -= 1
		else:
			dic[2] += 1
	cnt += dic[2] // 3
	cnt += dic[1] // 3
	print(cnt)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(q,) = I()
while q:
	q -= 1
	(n,) = I()
	l = I()
	l = [i % 3 for i in l]
	(z, o, t) = (l.count(0), l.count(1), l.count(2))
	k = min(o, t)
	ans = z + k
	o -= k
	t -= k
	print(ans + o // 3 + t // 3)


t = int(input())
for q in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	(a_0, a_1, a_2) = (0, 0, 0)
	for i in l:
		if i % 3 == 0:
			a_0 += 1
		elif i % 3 == 1:
			a_1 += 1
		else:
			a_2 += 1
	ct = a_0 + min(a_1, a_2) + abs(a_1 - a_2) // 3
	print(ct)


for i in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	d = {0: 0, 1: 0, 2: 0}
	for i in A:
		d[i % 3] += 1
	Z = min(d[1], d[2])
	d[1] -= Z
	d[2] -= Z
	print(d[0] + Z + d[1] // 3 + d[2] // 3)


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	one = 0
	two = 0
	zero = 0
	for i in range(n):
		if A[i] % 3 == 0:
			zero += 1
		elif A[i] % 3 == 1:
			one += 1
		else:
			two += 1
	ans = zero
	x = min(one, two)
	ans += min(one, two)
	one -= x
	two -= x
	ans += one // 3 + two // 3
	print(ans)


a = input()
c = []
array = []
for i in range(int(a)):
	c.append(input())
	array.append(list(map(int, input().split())))
for x in range(int(a)):
	k = 0
	l = 0
	j = []
	m = []
	o = []
	for i in array[x]:
		if i % 3 != 0:
			j.append(i)
			l += 1
	for i in j:
		if i % 3 == 1:
			m.append(i)
		else:
			o.append(i)
	if len(m) < len(o):
		print(int(c[x]) - l + len(m) + (len(o) - len(m)) // 3)
	else:
		print(int(c[x]) - l + len(o) + (len(m) - len(o)) // 3)


def one():
	n = int(input())
	a = list(map(int, input().split()))
	op = [0, 0, 0]
	for i in range(n):
		op[a[i] % 3] += 1
	ans = min(op[1], op[2])
	(op[1], op[2]) = (op[1] - ans, op[2] - ans)
	ans += op[0]
	ans += op[2] // 3
	ans += op[1] // 3
	return ans

def main():
	count = int(input())
	for i in range(count):
		print(one())
main()


import sys
from bisect import *
from math import floor, sqrt, ceil, factorial as F, gcd, pi
from itertools import chain, combinations, permutations, accumulate
from collections import Counter, defaultdict, OrderedDict, deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -sys.maxsize - 1
mod = 1000000007
ch = 'abcdefghijklmnopqrstuvwxyz'
lcm = lambda a, b: a * b // gcd(a, b)
setbit = lambda x: bin(x)[2:].count('1')
input = lambda : sys.stdin.readline()

def solve():
	T = int(input())
	for _ in range(T):
		n = int(input())
		a = list(map(int, input().split()))
		a = [i % 3 for i in a]
		d = Counter(a)
		print(d[0] + min(d[1], d[2]) + (d[1] + d[2] - 2 * min(d[1], d[2])) // 3)
try:
	sys.stdin = open('input.txt', 'r')
except:
	pass
solve()


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = 0
	rem1 = 0
	rem2 = 0
	for j in range(n):
		if l[j] % 3 == 0:
			ans += 1
		elif l[j] % 3 == 1:
			rem1 += 1
		else:
			rem2 += 1
	ans += min(rem1, rem2)
	k = min(rem1, rem2)
	rem1 -= k
	rem2 -= k
	ans += rem1 // 3
	ans += rem2 // 3
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	d = {0: 0, 1: 0, 2: 0}
	for i in a:
		d[i % 3] += 1
	print(d[0] + min(d[1], d[2]) + max(0, d[1] - d[2]) // 3 + max(0, d[2] - d[1]) // 3)


for t in range(int(input())):
	n = int(input())
	list1 = list(map(int, input().split()))
	count = 0
	s1 = s2 = 0
	for i in range(len(list1)):
		if list1[i] % 3 == 0:
			count += 1
		elif list1[i] % 3 == 1:
			s1 += 1
		else:
			s2 += 1
	count += min(s1, s2)
	if s1 > s2:
		count += (s1 - s2) // 3
	elif s2 > s1:
		count += (s2 - s1) // 3
	print(count)


for _ in range(int(input())):
	n = int(input())
	x1 = x2 = x3 = 0
	for i in map(int, input().split()):
		if i % 3 == 0:
			x3 += 1
		elif i % 3 == 1:
			x1 += 1
		else:
			x2 += 1
	print(x3 + min(x1, x2) + (max(x1, x2) - min(x1, x2)) // 3)


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	res = 0
	count0 = 0
	count1 = 0
	count2 = 0
	for e in lst:
		rem = e % 3
		if rem == 0:
			count0 += 1
		elif rem == 1:
			count1 += 1
		else:
			count2 += 1
	res = count0
	min12 = min(count1, count2)
	res += min12
	count1 -= min12
	count2 -= min12
	res += count1 // 3
	res += count2 // 3
	print(res)


sol = []
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	nr = len([i for i in a if i % 3 == 0])
	nr1 = len([i for i in a if i % 3 == 1])
	nr2 = len([i for i in a if i % 3 == 2])
	m = min(nr1, nr2)
	nr += m
	nr1 -= m
	nr2 -= m
	nr += nr1 // 3
	nr += nr2 // 3
	sol.append(nr)
print(*sol, sep='\n')


from sys import stdin, stdout, exit
q = int(input())
for it in range(q):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	cts = [0] * 3
	for i in range(n):
		cts[a[i] % 3] += 1
	ans = cts[0]
	t = min(cts[1], cts[2])
	ans += t
	cts[1] -= t
	cts[2] -= t
	ans += cts[1] // 3
	ans += cts[2] // 3
	stdout.write(str(ans) + '\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0, 0, 0]
	for i in a:
		c[i % 3] += 1
	if c[1] >= c[2]:
		print(c[0] + c[2] + (c[1] - c[2]) // 3)
	else:
		print(c[0] + c[1] + (c[2] - c[1]) // 3)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		l[i] = l[i] % 3
	d = Counter(l)
	ans = min(d[2], d[1]) + abs(d[2] - d[1]) // 3
	print(ans + d[0])


t = int(input())
while t:
	n = int(input())
	a = input()
	b = a.split()
	zer = 0
	on = 0
	tw = 0
	for i in range(n):
		b[i] = int(b[i]) % 3
		if b[i] == 0:
			zer = zer + 1
		elif b[i] == 1:
			on = on + 1
		else:
			tw = tw + 1
	out = zer + min(on, tw) + (max(on, tw) - min(on, tw)) // 3
	print(out)
	t = t - 1


def getMergeCount(array_size, array):
	freq = [0, 0, 0]
	for i in range(array_size):
		array[i] %= 3
		freq[array[i]] += 1
	perfect_pairs = min(freq[1], freq[2])
	freq[1] -= perfect_pairs
	freq[2] -= perfect_pairs
	freq[0] += perfect_pairs
	if freq[1] == 0:
		two_groups = freq[2] // 3
		freq[0] += two_groups
		freq[2] -= two_groups
	elif freq[2] == 0:
		one_groups = freq[1] // 3
		freq[0] += one_groups
		freq[1] -= one_groups
	return freq[0]
num_queries = int(input())
for i in range(num_queries):
	array_size = int(input())
	array = list(map(int, input().split(' ')))
	print(getMergeCount(array_size, array))


t = int(input())
for i in range(t):
	n = int(input())
	numbers = list(map(int, input().split(' ')))
	rem = {0: 0, 1: 0, 2: 0}
	for number in numbers:
		rem[number % 3] += 1
	ans = rem[0]
	x = min(rem[1], rem[2])
	if x:
		ans += x
		rem[1] -= x
		rem[2] -= x
	ans += rem[1] // 3 + rem[2] // 3
	print(ans)


def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		a = list(map(int, input().split()))
		d0 = d1 = d2 = 0
		for val in a:
			if val % 3 == 0:
				d0 += 1
			elif val % 3 == 1:
				d1 += 1
			else:
				d2 += 1
		print(d0 + min(d1, d2) + (max(d1, d2) - min(d1, d2)) // 3)
main()


t = int(input())
for i in range(t):
	n = int(input())
	k0 = 0
	k1 = 0
	k2 = 0
	for j in list(map(int, input().split())):
		if j % 3 == 0:
			k0 += 1
		elif j % 3 == 1:
			k1 += 1
		else:
			k2 += 1
	print(k0 + min(k1, k2) + (k1 - min(k1, k2)) // 3 + (k2 - min(k1, k2)) // 3)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	c3 = 0
	for i in range(n):
		if ar[i] % 3 == 0:
			c3 += 1
		elif ar[i] % 3 == 1:
			c1 += 1
		else:
			c2 += 1
	ans = 0
	ans += c3
	ans += min(c2, c1)
	c_2 = c2 - min(c2, c1)
	c_1 = c1 - min(c1, c2)
	ans += c_1 // 3
	ans += c_2 // 3
	print(ans)


import sys
inf = float('inf')
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def int1():
	return int(input())
import string
import math
from itertools import combinations

def main():
	t = int(input())
	while t > 0:
		x = int1()
		a = get_array()
		z1 = 0
		z2 = 0
		z3 = 0
		for i in a:
			if i % 3 == 0:
				z1 = z1 + 1
			if i % 3 == 1:
				z2 = z2 + 1
			if i % 3 == 2:
				z3 = z3 + 1
		y = min(z2, z3)
		z4 = y + z1 + (z2 - y) // 3 + (z3 - y) // 3
		print(z4)
		t = t - 1
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	c = []
	d = []
	i = 0
	while i < len(a):
		if a[i] % 3 == 0:
			b.append(a[i])
			a.remove(a[i])
		else:
			i += 1
	i = 0
	while i < len(a):
		condition = False
		for x in a[i + 1:]:
			if (a[i] + x) % 3 == 0:
				c.append(a[i])
				c.append(x)
				a.remove(a[i])
				a.remove(x)
				condition = True
				break
		if condition is False and len(a) >= 3:
			for y in range(3):
				d.append(a[0])
				a.pop(0)
		if condition is False and len(a) < 3:
			while len(a) > 0:
				d.append(a[0])
				a.pop(0)
	print(len(b) + len(c) // 2 + len(d) // 3)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	r = [0, 0, 0]
	for j in a:
		if j % 3 == 0:
			r[0] += 1
		elif j % 3 == 1:
			r[1] += 1
		else:
			r[2] += 1
	if r[1] < r[2]:
		r[2] -= r[1]
		m = r[0] + r[1] + r[2] // 3
	else:
		r[1] -= r[2]
		m = r[0] + r[2] + r[1] // 3
	print(m)


for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	m1 = m2 = 0
	total = 0
	for i in a:
		if i % 3 == 1:
			m1 += 1
		elif i % 3 == 2:
			m2 += 1
		else:
			total += 1
	m = min(m1, m2)
	total += m
	m1 -= m
	m2 -= m
	total += (m1 // 3 if m1 >= 3 else 0) + (m2 // 3 if m2 >= 3 else 0)
	print(total)


from math import floor
t = int(input())
for c in range(t):
	n = int(input())
	l = [int(j) for j in input().split()]
	cont = [0] * 3
	for i in l:
		cont[i % 3] += 1
	res = cont[0]
	while cont[1] != 0 and cont[2] != 0:
		res += 1
		cont[1] -= 1
		cont[2] -= 1
	res += floor(cont[2] / 3)
	res += floor(cont[1] / 3)
	print(res)


def func(n, a):
	count1 = 0
	count2 = 0
	count3 = 0
	for i in range(n):
		if a[i] % 3 == 1:
			count1 += 1
		elif a[i] % 3 == 2:
			count2 += 1
		else:
			count3 += 1
	if count1 < count2:
		return count3 + count1 + (count2 - count1) // 3
	else:
		return count3 + count2 + (count1 - count2) // 3
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	print(func(n, a))


def get(list):
	(count, count1, count2) = (0, 0, 0)
	for i in range(len(list)):
		list[i] = list[i] % 3
		if list[i] == 0:
			count += 1
		elif list[i] == 1:
			count1 += 1
		else:
			count2 += 1
	if count2 < count1:
		count += count2
		count1 -= count2
		count += count1 // 3
		return count
	elif count1 < count2:
		count += count1
		count2 -= count1
		count += count2 // 3
		return count
	else:
		count += count1
		return count
n = int(input())
for i in range(n):
	m = int(input())
	l = list(map(int, input().strip().split()))
	print(get(l))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) % 3 for i in input().split()]
	count = 0
	(c1, c2) = (0, 0)
	for i in a:
		if i == 0:
			count += 1
		elif i == 1:
			c1 += 1
		else:
			c2 += 1
	if c1 >= c2:
		ans = count + c2
		c1 = c1 - c2
		print(ans + c1 // 3)
	else:
		ans = count + c1
		c2 = c2 - c1
		print(ans + c2 // 3)


for _ in range(int(input())):
	cnt = [0, 0, 0]
	n = int(input())
	l = list(map(int, input().split()))
	for i in l:
		cnt[i % 3] += 1
	ans = cnt[0]
	mn = min(cnt[1], cnt[2])
	cnt[1] -= mn
	cnt[2] -= mn
	ans += mn
	ans += (cnt[1] + cnt[2]) // 3
	print(ans)


queries = int(input())
for _ in range(queries):
	n = int(input())
	arr = list(map(int, input().split()))
	mod0 = len(list(filter(lambda x: x % 3 == 0, arr)))
	mod1 = len(list(filter(lambda x: x % 3 == 1, arr)))
	mod2 = len(list(filter(lambda x: x % 3 == 2, arr)))
	pairs = min(mod1, mod2)
	mod1 -= pairs
	mod2 -= pairs
	print(mod0 + pairs + mod1 // 3 + mod2 // 3)


n = int(input())
for i in range(n):
	l = int(input())
	g = list(map(int, input().split()))
	o = dict()
	o[1] = 0
	o[2] = 0
	k = 0
	for i in range(l):
		if g[i] % 3 == 0:
			k += 1
		else:
			o[g[i] % 3] += 1
	(h, j) = (max(o[1], o[2]), min(o[1], o[2]))
	print(k + j + (h - j) // 3)


def ain():
	return map(int, input().split())

def lin():
	return list(ain())

def plist(l):
	for x in l:
		print(x, end=' ')
	print()

def indexof(l, v, l3):
	return l3[v]
for _ in range(int(input())):
	n = int(input())
	l = lin()
	a = 0
	b = 0
	c = 0
	for x in l:
		if x % 3 == 0:
			a += 1
		elif x % 3 == 1:
			b += 1
		else:
			c += 1
	s = a + min(b, c)
	if b > c:
		s += (b - c) // 3
	else:
		s += (c - b) // 3
	print(s)


q = int(input())
while q > 0:
	n = int(input())
	l = list(map(int, input().split()))
	r = [0, 0, 0]
	for i in l:
		r[i % 3] += 1
	ans = 0
	ans += r[0]
	r.pop(0)
	mn = min(r)
	ans += mn
	r[0] -= mn
	r[1] -= mn
	ans += (r[1] + r[0]) // 3
	print(ans)
	q -= 1


INT_MAX = 10 ** 18 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]

def calc(n, A):
	a = 0
	b = 0
	c = 0
	for ele in A:
		if ele % 3 == 0:
			a += 1
		elif ele % 3 == 1:
			b += 1
		else:
			c += 1
	ans = a
	mini = min(b, c)
	ans += mini
	if b - mini > 0:
		ans += (b - mini) // 3
	if c - mini > 0:
		ans += (c - mini) // 3
	return ans
for _ in range(int(input())):
	n = int(input())
	A = INPUT()
	print(calc(n, A))


T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(int, input().strip().split()))[:N]
	a = 0
	b = 0
	c = 0
	for n in range(N):
		if A[n] % 3 == 0:
			a = a + 1
		elif A[n] % 3 == 1:
			b = b + 1
		else:
			c = c + 1
	print(a + min(b, c) + (max(b, c) - min(b, c)) // 3)


for _ in range(int(input())):
	(n, a) = (int(input()), list(map(lambda x: int(x) % 3, input().split())))
	rem = [a.count(i) for i in [0, 1, 2]]
	print(rem[0] + min(rem[1], rem[2]) + abs(rem[1] - rem[2]) // 3)


for _ in range(int(input())):
	n = int(input())
	s = input().split()
	l = [0] * 3
	for n in s:
		l[int(n) % 3] += 1
	cnt = l[0] + min(l[1], l[2])
	if l[1] > l[2]:
		l[1] -= l[2]
		cnt += l[1] // 3
	elif l[2] > l[1]:
		l[2] -= l[1]
		cnt += l[2] // 3
	print(cnt)


n = int(input())
for i in range(n):
	k = int(input())
	a = [int(x) for x in input().split()]
	b = [0, 0, 0]
	ans = 0
	for j in a:
		b[j % 3] += 1
	m1 = max(b[1], b[2])
	m2 = min(b[1], b[2])
	ans = ans + b[0] + m2 + (m1 - m2) // 3
	print(ans)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
from collections import defaultdict
nb_test = RI()
for _ in range(nb_test):
	_ = RI()
	maps = defaultdict(int)
	arrs = RMI()
	for i in arrs:
		maps[i % 3] += 1
	ans = 0
	for i in range(maps[1] + 1):
		rem1 = maps[1] - i
		rem2 = maps[2] - i
		if rem2 < 0:
			break
		cur = maps[0] + i + rem1 // 3 + rem2 // 3
		ans = max(ans, cur)
	print(ans)


for _ in range(int(input())):
	x = int(input())
	li = list(map(int, input().split()))
	li1 = [0] * 3
	for i in li:
		li1[i % 3] += 1
	cnt = li1[0]
	m = min(li1[1], li1[2])
	li1[1] -= m
	li1[2] -= m
	cnt += m
	print(cnt + (li1[1] + li1[2]) // 3)


t = int(input())
kq = []
for i in range(0, t):
	s = 0
	kt = 0
	n = int(input())
	na = [int(c) for c in input().split()]
	na = [c % 3 for c in na]
	kt = kt + na.count(0)
	if na.count(1) >= na.count(2):
		kt = kt + na.count(2) + int((na.count(1) - na.count(2)) / 3)
	else:
		kt = kt + na.count(1) + int((na.count(2) - na.count(1)) / 3)
	kq.append(kt)
for i in range(0, t):
	print(kq[i])


t = int(input())
while t:
	n = int(input())
	A = list(map(int, input().split(' ')))
	rem0 = 0
	rem1 = 0
	rem2 = 0
	res = 0
	for i in range(n):
		if A[i] % 3 == 0:
			rem0 += 1
		elif A[i] % 3 == 1:
			rem1 += 1
		else:
			rem2 += 1
	res += rem0
	if rem2 == rem1:
		res += rem1
	elif rem2 < rem1:
		res += rem2
		res = res + (rem1 - rem2) // 3
	else:
		res = res + rem1
		res = res + (rem2 - rem1) // 3
	print(res)
	t = t - 1


def scand():
	return int(input())

def scana():
	return [int(x) for x in input().split()]
n = scand()

def solve():
	scand()
	arr = [it % 3 for it in scana()]
	cnt = [0, 0, 0]
	for it in arr:
		cnt[it] += 1
	return cnt[0] + min(cnt[1], cnt[2]) + abs(cnt[1] - cnt[2]) // 3
for i in range(n):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	a = [int(o) for o in input().split()]
	s = 0
	cnt = 0
	(o, t) = (0, 0)
	for i in range(n):
		if a[i] % 3 == 0:
			cnt += 1
		elif a[i] % 3 == 1:
			o += 1
		elif a[i] % 3 == 2:
			t += 1
	u = min(o, t)
	cnt += u
	o -= u
	t -= u
	cnt = cnt + o // 3 + t // 3
	print(cnt)


n = int(input())
for f in range(n):
	c = 0
	arr = []
	d1 = dict.fromkeys(range(100), 0)
	a = int(input())
	b = input()
	arr2 = b.split(' ')
	s = 0
	for x in range(a):
		if int(arr2[x]) % 3 == 0:
			c += 1
		else:
			arr.insert(s, int(arr2[x]))
			s += 1
	arr.sort()
	kk = len(arr)
	for i in range(kk):
		for j in range(i, kk):
			if d1[i] == 0 and d1[j] == 0:
				if (arr[i] + arr[j]) % 3 == 0:
					d1[i] = 1
					d1[j] = 1
					c += 1
	sum = 0
	for i in range(kk):
		if d1[i] == 0:
			sum += arr[i]
			if sum % 3 == 0:
				c += 1
				sum = 0
	print(c)


import math
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	c = [0 for i in range(3)]
	for i in range(n):
		c[a[i] % 3] += 1
	total = 0
	total += c[0]
	x = 0
	if c[1] >= c[2]:
		total += c[2]
		c[1] = c[1] - c[2]
		x = c[1] // 3
	else:
		total += c[1]
		c[2] = c[2] - c[1]
		x = c[2] // 3
	total += x
	print(total)


q = int(input())
for i in range(q):
	input()
	li = map(int, input().split())
	a = [0, 0, 0]
	for j in li:
		a[j % 3] += 1
	print(a[0] + min(a[1], a[2]) + (max(a[1], a[2]) - min(a[1], a[2])) // 3)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) % 3 for j in input().split(' ')]
	zs = 0
	os = 0
	ts = 0
	for val in a:
		if val == 0:
			zs += 1
		elif val == 1:
			os += 1
		else:
			ts += 1
	total = zs
	if os >= ts:
		total += ts
		left = os - ts
	else:
		total += os
		left = ts - os
	total += int(left / 3)
	print(total)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * 3
	for d in a:
		c[d % 3] += 1
	ans = c[0] + min(c[1], c[2]) + abs(c[1] - c[2]) // 3
	print(ans)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, sys.stdin.readline().split(' ')))
	z = 0
	o = 0
	two = 0
	for nu in a:
		if nu % 3 == 0:
			z += 1
		elif nu % 3 == 1:
			o += 1
		else:
			two += 1
	ans = min(o, two)
	o -= ans
	two -= ans
	if o:
		ans += o // 3
	if two:
		ans += two // 3
	print(ans + z)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


from collections import Counter

def merge(arr):
	arr = list(map(lambda x: x % 3, arr))
	rems = Counter(arr)
	tmp = min(rems[1], rems[2])
	total = rems[0] + tmp + (max(rems[1], rems[2]) - tmp) // 3
	return total
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(merge(arr))


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	cnt = cnt1 = cnt2 = 0
	for j in range(n):
		modulo = arr[j] % 3
		if modulo == 0:
			cnt += 1
		elif modulo == 1:
			cnt1 += 1
		else:
			cnt2 += 1
	mi = min(cnt1, cnt2)
	print(cnt + mi + (cnt1 + cnt2 - 2 * mi) // 3)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	bd = {}
	ans = 0
	s = r = 0
	for i in range(n):
		if a[i] != 0:
			b.append(a[i] % 3)
	for i in b:
		if i in bd:
			bd[i] += 1
		else:
			bd[i] = 1
	if 0 in bd:
		ans += bd[0]
	if 1 in bd:
		s = bd[1]
	if 2 in bd:
		r = bd[2]
	m = min(s, r)
	ans += m
	s = s - m
	r = r - m
	ans += s // 3
	ans += r // 3
	print(ans)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {0: 0, 1: 0, 2: 0}
	for x in a:
		d[x % 3] += 1
	ans = d[0]
	x = min(d[1], d[2])
	ans += x
	d[1] -= x
	d[2] -= x
	ans += d[1] // 3 + d[2] // 3
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	l = []
	l = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	c0 = 0
	for i in range(n):
		if l[i] % 3 == 0:
			c0 += 1
		elif l[i] % 3 == 1:
			c1 += 1
		elif l[i] % 3 == 2:
			c2 += 1
	mi = min(c1, c2)
	ma = max(c1, c2) - mi
	print(c0 + mi + ma // 3)
	t -= 1


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	r = [0, 0, 0]
	for ai in a:
		r[ai % 3] += 1
	ans = r[0]
	comb = min(r[1], r[2])
	r[1] -= comb
	r[2] -= comb
	ans += comb
	ans += r[1] // 3 + r[2] // 3
	print(ans)


import sys

def merge(a):
	r = [0, 0, 0]
	extra = 0
	for i in a:
		r[i % 3] += 1
	if r[1] > r[2]:
		extra = r[2] + (r[1] - r[2]) // 3
	else:
		extra = r[1] + (r[2] - r[1]) // 3
	return r[0] + extra
sys.stdin.readline()
skip = True
for line in sys.stdin:
	if skip:
		skip = False
		continue
	skip = True
	print(merge([int(k.strip()) for k in line.strip().split()]))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = [0, 0, 0]
	for ai in a:
		f[ai % 3] += 1
	m = min(f[1], f[2])
	f[1] -= m
	f[2] -= m
	print(f[0] + m + (f[1] + f[2]) // 3)


for w in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	for i in range(n):
		if a[i] % 3 != 0:
			l.append(a[i] % 3)
	ans = n - len(l)
	if l.count(1) == 0:
		ans += len(l) // 3
	elif l.count(2) == 0:
		ans += len(l) // 3
	elif l.count(1) == l.count(2):
		ans += l.count(1)
	elif l.count(2) > l.count(1):
		ans += l.count(1)
		ans += (l.count(2) - l.count(1)) // 3
	else:
		ans += l.count(2)
		ans += (l.count(1) - l.count(2)) // 3
	print(ans)


from collections import defaultdict

def fix():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	keep = defaultdict(int)
	for i in range(n):
		keep[a[i] % 3] += 1
	c = keep[0]
	x = min(keep[1], keep[2])
	c += x
	keep[1] -= x
	keep[2] -= x
	if keep[1] > 0:
		c += keep[1] // 3
	if keep[2] > 0:
		c += keep[2] // 3
	return c

def go():
	t = int(input())
	for i in range(t):
		print(fix())
go()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	for i in range(n):
		ans.append(a[i] % 3)
	if ans.count(1) > ans.count(2):
		print(ans.count(0) + ans.count(2) + (ans.count(1) - ans.count(2)) // 3)
	else:
		print(ans.count(0) + ans.count(1) + (ans.count(2) - ans.count(1)) // 3)


def main():
	for x in range(int(input())):
		solve()

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	times = [0] * 3
	for x in a:
		times[x % 3] += 1
	x = times[0]
	take = min(times[1], times[2])
	x += take
	times[1] -= take
	times[2] -= take
	x += times[1] // 3
	x += times[2] // 3
	print(x)
main()


import sys
import math
from collections import defaultdict

def rl():
	return sys.stdin.readline().strip()

def rn():
	return list(map(int, sys.stdin.readline().strip().split()))

def rln(n):
	l = [None] * n
	for i in range(n):
		l[i] = int(rl())
	return l

def solve():
	input()
	tab = rn()
	count1 = 0
	count2 = 0
	res = 0
	for e in tab:
		if e % 3 == 0:
			res += 1
		elif e % 3 == 1:
			count1 += 1
		elif e % 3 == 2:
			count2 += 1
	if count2 >= count1:
		print(res + count1 + (count2 - count1) // 3)
	else:
		print(res + count2 + (count1 - count2) // 3)
test = int(input())
for _ in range(test):
	solve()


t = int(input())

def d(x):
	r = 0
	for i in x:
		r += int(i)
	return r % 3

def s(x):
	return bool(x)
l = []
for i in range(t):
	f = int(input())
	g = [*filter(s, map(d, input().split()))]
	l.append([f, g])
for i in l:
	y = i[0] - len(i[1])
	z = i[1].count(1)
	x = i[1].count(2)
	k = z - x
	if k > 0:
		print(y + x + k // 3)
	else:
		print(y + z + -k // 3)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	p = q = r = 0
	for i in a:
		if i % 3 == 0:
			p += 1
		elif i % 3 == 1:
			q += 1
		else:
			r += 1
	m = min(q, r)
	p += m
	q -= m
	r -= m
	p += (q + r) // 3
	print(p)


def Processing():
	t = 0
	n = 0
	Arr = []
	t = int(input())
	for i in range(t):
		result = 0
		number_1 = 0
		number_2 = 0
		number_3 = 0
		n = int(input())
		Arr = list(map(int, input().split()))
		for j in range(n):
			Arr[j] = Arr[j] % 3
			if Arr[j] == 0:
				number_3 += 1
			elif Arr[j] == 1:
				number_1 += 1
			elif Arr[j] == 2:
				number_2 += 1
		result += number_3
		result += min(number_2, number_1)
		result += abs(number_1 - number_2) // 3
		print(result, end='\n')
Processing()


for _ in ' ' * int(input()):
	input()
	a = [i % 3 for i in map(int, input().split())]
	print(a.count(0) + min(a.count(1), a.count(2)) + abs(a.count(1) - a.count(2)) // 3)


n = int(input())
for i in range(n):
	value = 0
	v = int(input())
	a = list(map(int, input().split()))
	for i in range(v):
		a[i] = a[i] % 3
	l1 = a.count(1)
	l2 = a.count(2)
	if l2 > l1:
		print(a.count(0) + l1 + (l2 - l1) // 3)
	else:
		print(a.count(0) + l2 + (l1 - l2) // 3)


def f(l):
	ml = [0, 0, 0]
	for i in l:
		ml[i % 3] += 1
	return ml[0] + min(ml[1:]) + (max(ml[1:]) - min(ml[1:])) // 3
q = int(input())
for _ in range(q):
	_ = input()
	l = list(map(int, input().split()))
	print(f(l))


q = int(input())
for _ in range(q):
	n = int(input())
	u = list(map(int, input().split()))
	(a0, a1, a2) = [0, 0, 0]
	for i in range(n):
		if u[i] % 3 == 0:
			a0 += 1
		elif u[i] % 3 == 1:
			a1 += 1
		else:
			a2 += 1
	w1 = a0 + min(a1, a2)
	w2 = min(a1, a2)
	a1 -= w2
	a2 -= w2
	w1 += a1 // 3 + a2 // 3
	print(w1)


q = int(input())
for _ in range(q):
	n = int(input())
	count = [0, 0, 0]
	for i in [int(x) % 3 for x in input().split()]:
		count[i] += 1
	m = min(count[1], count[2])
	print(m + count[0] + (count[1] - m) // 3 + (count[2] - m) // 3)


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	count3 = 0
	for j in range(n):
		if A[j] % 3 == 1:
			count1 += 1
		if A[j] % 3 == 2:
			count2 += 1
		if A[j] % 3 == 0:
			count3 += 1
	if count1 < count2:
		print(count1 + count3 + (count2 - count1) // 3)
	else:
		print(count2 + count3 + (count1 - count2) // 3)


t = int(input())
for ii in range(t):
	n = int(input())
	mods = [0] * 3
	ans = 0
	a = list(map(int, input().split()))
	for i in range(n):
		mods[a[i] % 3] += 1
	ans += mods[0]
	if mods[1] > mods[2]:
		ans += mods[2] + (mods[1] - mods[2]) // 3
	else:
		ans += mods[1] + (mods[2] - mods[1]) // 3
	print(ans)


for caso in range(int(input())):
	n = int(input())
	cont = 0
	li = [int(i) for i in input().split()]
	aux = []
	for i in range(len(li)):
		li[i] %= 3
		if li[i] == 0:
			cont += 1
		else:
			aux.append(li[i])
	li = aux
	while len(li) > 1:
		li.sort()
		li[0] = li[0] + li[-1]
		li.pop(-1)
		if li[0] % 3 == 0:
			cont += 1
			li.pop(0)
	print(cont)


def count_steps(x):
	x = [i % 3 for i in x]
	steps = x.count(0)
	n1 = x.count(1)
	n2 = x.count(2)
	m = min(n1, n2)
	steps = steps + m
	steps = steps + (n2 - m) // 3 + (n1 - m) // 3
	return steps
T = int(input())
for i in range(T):
	n = input()
	a = list(map(int, input().split()))
	print(count_steps(a))


q = int(input())
for tc in range(0, q):
	n = int(input())
	xs = [int(x) for x in input().split()]
	ones = 0
	twos = 0
	threes = 0
	for x in xs:
		group = x % 3
		if group == 0:
			threes += 1
		elif group == 1:
			ones += 1
		else:
			twos += 1
	result = threes + min(ones, twos) + abs(ones - twos) // 3
	print(result)


def unite(lst):
	(count1, count2, count3) = (0, 0, 0)
	for elem in lst:
		if elem % 3 == 0:
			count1 += 1
		elif elem % 3 == 1:
			count2 += 1
		else:
			count3 += 1
	count1 += min(count2, count3)
	x = count3
	count3 -= min(x, count2)
	count2 -= min(x, count2)
	return count1 + count2 // 3 + count3 // 3
n = int(input())
b = list()
for i in range(n):
	m = int(input())
	a = [int(j) for j in input().split()]
	b.append(unite(a))
for elem in b:
	print(elem)


t = int(input())
for i in range(t):
	n = int(input())
	line = [int(x) % 3 for x in input().split()]
	three = line.count(0)
	one = line.count(1)
	two = line.count(2)
	m = min(one, two)
	three += m
	one -= m
	two -= m
	three += two // 3
	three += one // 3
	print(three)


def find(ele, a):
	l = 0
	r = n - 1
	while l <= r:
		mid = (l + r) // 2
		if a[mid] == ele and check[mid]:
			return mid
		k = mid - 1
		while k >= 0 and a[k] == ele:
			if check[k]:
				return k
			k -= 1
		k = mid + 1
		while k < n and a[k] == ele:
			if check[k]:
				return k
			k += 1
		if a[mid] < ele:
			l = mid + 1
		else:
			r = mid - 1
	return -1
t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % 3
	a.sort()
	count = 0
	check = [True] * n
	for i in range(n):
		if a[i] % 3 == 0:
			count += 1
			check[i] = False
	ind = 0
	while ind < n and a[ind] == 0:
		ind += 1
	if count == len(a):
		print(count)
	else:
		xxx = False
		current = -1
		i = ind
		while i < n:
			if check[i]:
				if current == -1:
					current = a[i]
					check[i] = False
				x = find(abs(3 - current), a)
				if x == -1:
					try:
						ind = check.index(True)
					except:
						xxx = True
						print(count)
						break
					current = (current + a[ind]) % 3
					check[ind] = False
					check[i] = False
				else:
					check[x] = False
					count += 1
					current = -1
			i += 1
		if xxx == False:
			print(count)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	A = [int(i) % 3 for i in input().split()]
	count = A.count(0)
	x = A.count(1)
	y = A.count(2)
	count += min(x, y)
	rest = max(x, y) - min(x, y)
	count += rest // 3
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	(a, b, c) = (0, 0, 0)
	for j in map(int, input().split()):
		if j % 3 == 0:
			a += 1
		if j % 3 == 1:
			b += 1
		if j % 3 == 2:
			c += 1
	tmp = min(b, c)
	a += tmp
	b -= tmp
	c -= tmp
	print(a + b // 3 + c // 3)


n = int(input())
for i in range(n):
	m = int(input())
	a = 0
	b = 0
	c = 0
	j = input().split()
	for k in j:
		x = int(k)
		if x % 3 == 0:
			a = a + 1
		if x % 3 == 1:
			b = b + 1
		if x % 3 == 2:
			c = c + 1
	ans = a + min(b, c) + (max(b, c) - min(b, c)) / 3
	print(int(ans))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	ans = 0
	l1 = 0
	l2 = 0
	x = list(map(int, input().split()))
	for i in range(n):
		if x[i] % 3 == 0:
			ans += 1
		elif x[i] % 3 == 1:
			l1 += 1
		elif x[i] % 3 == 2:
			l2 += 1
	ans += min(l1, l2)
	l = max(l1, l2) - min(l1, l2)
	ans += l // 3
	print(ans)


n = int(input())
for k in range(n):
	a = int(input())
	b = [int(q) for q in input().strip().split()]
	(c, d, e, f, g) = (0, 0, 0, 0, 0)
	for p in range(a):
		if int(b[p]) % 3 == 0:
			c += 1
		elif int(b[p]) % 3 == 1:
			d += 1
		else:
			e += 1
		(f, g) = (max(d, e), min(d, e))
	print(c + g + int((f - g) / 3))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = [i % 3 for i in a]
	count = a.count(0)
	mod1 = a.count(1)
	mod2 = a.count(2)
	if mod1 == mod2:
		count += mod1
	elif mod1 > mod2:
		count += mod2
		mod1 -= mod2
		count += mod1 // 3
	else:
		count += mod1
		mod2 -= mod1
		count += mod2 // 3
	print(count)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	k = 0
	d = 0
	for i in l:
		if i % 3 == 1:
			c = c + 1
		if i % 3 == 2:
			d = d + 1
		if i % 3 == 0:
			k = k + 1
	print(int(k + min(c, d) + abs(c - d) // 3))


n = int(input())
for i in range(n):
	x = int(input())
	a = [int(i) for i in input().split()]
	zero = 0
	one = 0
	two = 0
	for i in range(x):
		if a[i] % 3 == 0:
			zero += 1
		elif a[i] % 3 == 1:
			one += 1
		else:
			two += 1
	print(zero + min(two, one) + (max(two, one) - min(two, one)) // 3)


t = int(input())
for case in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	rest = [0, 0, 0]
	for item in a:
		rest[item % 3] += 1
	pairs = min(rest[1], rest[2])
	ans = rest[0] + pairs + (rest[1] - pairs) // 3 + (rest[2] - pairs) // 3
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0, 0, 0]
	for i in a:
		if i % 3 == 0:
			c[0] += 1
		elif i % 3 == 1:
			c[1] += 1
		elif i % 3 == 2:
			c[2] += 1
	print(c[0] + min(c[1], c[2]) + (max(c[1], c[2]) - min(c[1], c[2])) // 3)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def solve():
	t = nu()
	for _ in range(t):
		n = nu()
		a = li()
		for i in range(n):
			a[i] = a[i] % 3
		pp = 0
		qq = 0
		cc = 0
		for i in range(n):
			if a[i] == 0:
				cc += 1
			if a[i] == 1:
				pp += 1
			if a[i] == 2:
				qq += 1
		if qq > 0 and pp > 0:
			cc += min(qq, pp)
			zz = min(pp, qq)
			qq -= zz
			pp -= zz
		if pp > 0:
			cc += pp // 3
			pp -= pp // 3
		if qq > 0:
			cc += qq // 3
			qq -= qq // 3
		print(cc)
solve()


(z, zz) = (input, lambda : list(map(int, z().split())))
num = int(z())
for _ in range(num):
	n = int(z())
	cnt = [0] * 3
	for i in zz():
		cnt[i % 3] += 1
	ans = cnt[0]
	t = min(cnt[1], cnt[2])
	ans += t
	cnt[1] -= t
	cnt[2] -= t
	t1 = cnt[1] // 3
	t2 = cnt[2] // 3
	print(ans + t1 + t2)


from fractions import gcd
from itertools import combinations, permutations, accumulate, product
from collections import deque, defaultdict, Counter
import decimal
import re
import math
import bisect
import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
for _ in range(I()):
	n = I()
	A = list(map(lambda x: int(x) % 3, input().split()))
	C = Counter(A)
	ans = 0
	ans += C[0]
	least = min(C[1], C[2])
	C[1] -= least
	C[2] -= least
	ans += least
	ans += C[1] // 3
	ans += C[2] // 3
	print(ans)


tcase = int(input())
while tcase > 0:
	tcase -= 1
	n = int(input())
	arr = input().split()
	l = []
	for i in range(n):
		l.append(int(arr[i]) % 3)
	cnt1 = l.count(1)
	cnt2 = l.count(2)
	cnt0 = l.count(0)
	result = cnt0
	if cnt1 > cnt2:
		result += cnt2
		cnt1 -= cnt2
		if cnt1 >= 3:
			result += cnt1 // 3
	elif cnt2 > cnt1:
		result += cnt1
		cnt2 -= cnt1
		if cnt2 >= 3:
			result += cnt2 // 3
	elif cnt1 == cnt2:
		result += cnt1
	print(result)


x = int(input())
for i in range(x):
	t = int(input())
	a = list(map(int, input().split()))
	r1 = 0
	r2 = 0
	r0 = 0
	for i in range(t):
		if a[i] % 3 == 2:
			r2 = r2 + 1
		elif a[i] % 3 == 1:
			r1 = r1 + 1
		else:
			r0 = r0 + 1
		k = min(r1, r2)
		if r1 == max(r1, r2):
			t = (r1 - r2) // 3
		elif r2 == max(r1, r2):
			t = (r2 - r1) // 3
	print(r0 + k + t)


for q in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	mod = []
	for w in arr:
		mod.append(w % 3)
	mod.sort()
	count = 0
	count1 = 0
	count2 = 0
	for w in range(n):
		if mod[w] == 0:
			count += 1
		elif mod[w] == 1:
			count1 += 1
		else:
			count2 += 1
	count += min(count1, count2)
	if count1 > count2:
		count += (count1 - count2) // 3
	else:
		count += (count2 - count1) // 3
	print(count)


from sys import stdin, setrecursionlimit
import heapq
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	a = [0, 0, 0]
	arr = list(map(int, stdin.readline().split()))
	for i in range(len(arr)):
		a[arr[i] % 3] += 1
	ans = a[0]
	if a[1] > a[2]:
		ans += a[2]
		a[1] -= a[2]
		ans += a[1] // 3
	elif a[2] > a[1]:
		ans += a[1]
		a[2] -= a[1]
		ans += a[2] // 3
	else:
		ans += a[1]
	print(ans)


n = int(input())
for _ in range(n):
	t = int(input())
	array = list(map(int, input().split()))
	(a, b, c) = (0, 0, 0)
	for i in range(t):
		if array[i] % 3 == 0:
			a += 1
		if array[i] % 3 == 1:
			b += 1
		if array[i] % 3 == 2:
			c += 1
	print(a + min(b, c) + (b + c - min(b, c) * 2) // 3)


t = int(input())

def solve(arr, n):
	ones = 0
	twos = 0
	for item in arr:
		if item % 3 == 1:
			ones += 1
		elif item % 3 == 2:
			twos += 1
	zeros = n - ones - twos
	threes = abs(ones - twos) // 3
	return zeros + min(ones, twos) + threes
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	print(solve(arr, n))


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	m = {}
	m[1] = 0
	m[2] = 0
	result = 0
	for i in ar:
		if i % 3 == 1:
			m[1] += 1
		elif i % 3 == 2:
			m[2] += 1
		elif i % 3 == 0:
			result += 1
	minValue = min(m[1], m[2])
	result += minValue
	result += (m[1] - minValue) // 3
	result += (m[2] - minValue) // 3
	print(result)


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	a = list(map(int, input().split()))
	for j in range(n):
		l.append(a[j] % 3)
	oh = l.count(0)
	tt = min(l.count(2), l.count(1))
	print(oh + tt + (l.count(1) - tt) // 3 + (l.count(2) - tt) // 3)


import math
mod = 1000000007

def power(a, b):
	res = 1
	b = b % (mod - 1)
	while b > 0:
		if b % 2 != 0:
			res = res % mod * (a % mod) % mod
		b = b // 2
		a = a % mod
		a = a * a % mod
	res = res % mod
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	b = [0] * 3
	for i in range(n):
		b[a[i] % 3] += 1
	s = b[0] + min(b[1], b[2])
	if b[1] < b[2]:
		s = s + (b[2] - b[1]) // 3
	else:
		s = s + (b[1] - b[2]) // 3
	print(s)


q = int(input())
for iqwwq in range(q):
	n = int(input())
	sp = input().split()
	(k0, k1, k2) = (0, 0, 0)
	for i in sp:
		if int(i) % 3 == 0:
			k0 += 1
		elif int(i) % 3 == 1:
			k1 += 1
		else:
			k2 += 1
	if k2 > k1:
		k2 -= k1
		print(k0 + k1 + k2 // 3)
	else:
		k1 -= k2
		print(k0 + k1 // 3 + k2)


import sys
import os
from io import IOBase, BytesIO

def main():
	for tc in range(int(input())):
		n = int(input())
		tmp = get_array()
		arr = [0, 0, 0]
		ans = 0
		for i in tmp:
			arr[i % 3] += 1
		ans = arr[0]
		x = min(arr[1], arr[2])
		ans += x
		arr[1] -= x
		arr[2] -= x
		ans += arr[1] // 3
		ans += arr[2] // 3
		print(ans)
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline().strip()
main()


def sum_digits(n):
	s = 0
	while n:
		s += n % 10
		n //= 10
	return s
t = int(input())
for i in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	sm = 0
	s = []
	for i in ar:
		if i % 3 == 0:
			sm += 1
		else:
			t = str(i)
			s.append(sum_digits(i) % 3)
	r1 = s.count(1)
	r2 = s.count(2)
	b = min(r1, r2)
	sm += b
	r1 = r1 - b
	r2 = r2 - b
	sm = sm + r1 // 3 + r2 // 3
	print(sm)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] = a[i] % 3
	ans = a.count(0)
	a1 = a.count(1)
	a2 = a.count(2)
	k = min(a1, a2)
	ans += k
	a1 -= k
	a2 -= k
	ans += a1 // 3
	ans += a2 // 3
	print(ans)


def cal(a):
	ans = [0, 0, 0]
	for i in a:
		ans[i % 3] += 1
	if ans[1] > ans[2]:
		y = ans[2]
		ans[1] -= ans[2]
		y += ans[1] // 3
	elif ans[1] < ans[2]:
		y = ans[1]
		ans[2] -= ans[1]
		y += ans[2] // 3
	else:
		y = ans[1]
	return ans[0] + y
for i in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	print(cal(a))


tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	arr = list(map(lambda x: x % 3, arr))
	zero = arr.count(0)
	ones = arr.count(1)
	twos = arr.count(2)
	ans = zero
	mini = min(ones, twos)
	ans += mini
	ones -= mini
	twos -= mini
	ans += ones // 3 + twos // 3
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	a = 0
	b = 0
	for num in arr:
		tmp = num % 3
		if tmp == 0:
			ans += 1
		elif tmp == 1:
			a += 1
		else:
			b += 1
	ans += min(a, b)
	ans += abs(a - b) // 3
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sum1 = sum2 = sum3 = 0
	for q in a:
		if q % 3 == 0:
			sum1 += 1
		elif q % 3 == 1:
			sum2 += 1
		else:
			sum3 += 1
	ans = sum1
	ans += min(sum2, sum3)
	ans += (max(sum2, sum3) - min(sum2, sum3)) // 3
	print(ans)


t = int(input())
for i in range(t):
	a = int(input())
	s = [int(x) % 3 for x in input().split() if int(x) != 0]
	ans = s.count(0) + min(s.count(1), s.count(2)) + (s.count(1) - min(s.count(1), s.count(2))) // 3 + (s.count(2) - min(s.count(1), s.count(2))) // 3
	print(ans)


import sys
from collections import defaultdict

class BMergeIt:

	def solve(self):
		for _ in range(int(input())):
			n = int(input())
			a = [int(item) for item in input().split()]
			for i in range(n):
				a[i] = a[i] % 3
			cnt = defaultdict(int)
			for x in a:
				cnt[x] += 1
			u = min(cnt[1], cnt[2])
			print(cnt[0] + u + (cnt[1] - u) // 3 + (cnt[2] - u) // 3)
solver = BMergeIt()
input = sys.stdin.readline
solver.solve()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	y1 = 0
	y2 = 0
	for x in l:
		if x % 3 == 0:
			c += 1
		elif x % 3 == 1:
			y1 += 1
		else:
			y2 += 1
	m = min(y1, y2)
	y1 -= m
	y2 -= m
	x = y1 // 3 + y2 // 3
	print(x + c + m)


for i in range(int(input())):
	k = int(input())
	l = list(map(int, input().split()))
	l1 = [0] * 3
	for i in l:
		l1[i % 3] += 1
	(a, b) = (l1[1], l1[2])
	if a == b:
		print(l1[0] + a)
	else:
		k1 = max(a, b) - min(a, b)
		if max(a, b) == a:
			print(l1[0] + b + k1 // 3)
		else:
			print(l1[0] + a + k1 // 3)


from collections import deque, defaultdict, Counter, OrderedDict
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	mod = []
	ans = 0
	for i in arr:
		if i % 3 == 0:
			ans += 1
		else:
			mod.append(i % 3)
	c = Counter(mod)
	c = dict(c)
	now = min(c.get(1, 0), c.get(2, 0))
	ans += now
	c[2] = max(0, c.get(2, 0) - now)
	c[1] = max(0, c.get(1, 0) - now)
	ans += c.get(1, 0) // 3
	c[1] = c.get(1, 0) - c.get(1, 0) // 3 * 3
	ans += c.get(2, 0) // 3
	c[2] = c.get(2, 0) - c.get(2, 0) // 3 * 3
	print(ans)


q = int(input().strip())
while q:
	q -= 1
	n = int(input().strip())
	a = list(map(int, input().strip().split(' ')))
	ans = 0
	cnt1 = 0
	cnt2 = 0
	for i in a:
		if i % 3 == 0:
			ans += 1
		elif i % 3 == 1:
			cnt1 += 1
		else:
			cnt2 += 1
	ans += abs(cnt1 - cnt2) // 3 + min(cnt1, cnt2)
	print(ans)


from collections import defaultdict

def solve():
	for _ in range(int(input())):
		N = int(input())
		A = [int(k) for k in input().split()]
		rem = defaultdict(int)
		for x in A:
			rem[x % 3] += 1
		ans = min(rem[1], rem[2])
		if rem[1] > ans:
			ans += (rem[1] - ans) // 3
		if rem[2] > ans:
			ans += (rem[2] - ans) // 3
		ans += rem[0]
		print(ans)
solve()


querries = int(input())
for itr in range(querries):
	n = int(input())
	t = input()
	t = t.split()
	t = [int(x) for x in t]
	ile = [0, 0, 0]
	for i in t:
		ile[i % 3] += 1
	x = min(ile[1], ile[2])
	y = max(ile[1], ile[2])
	print(ile[0] + x + (y - x) // 3)


import os
import sys
import string
import math

def solution(nums):
	(c1, c2, c3) = (0, 0, 0)
	for num in nums:
		if num % 3 == 0:
			c3 += 1
		elif num % 3 == 1:
			c1 += 1
		else:
			c2 += 1
	count = c3
	count += min(c1, c2)
	tmp = abs(c1 - c2)
	count += tmp // 3
	return count

def main(cases):
	for case in cases:
		print(solution(case))

def parse():
	n = int(input())
	cases = []
	for _ in range(n):
		input()
		case = [int(s) for s in input().split(' ')]
		cases.append(case)
	return cases
main(parse())


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	for i in range(n):
		a[i] %= 3
	c0 = 0
	c1 = 0
	c2 = 0
	for i in a:
		if i == 0:
			c0 += 1
		elif i == 1:
			c1 += 1
		else:
			c2 += 1
	ans = 0
	ans += c0
	now = min(c2, c1)
	ans += now
	c1 -= now
	c2 -= now
	ans += c1 // 3
	ans += c2 // 3
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	div1 = 0
	div2 = 0
	score = 0
	for e in l:
		if e % 3 == 0:
			score += 1
		elif e % 3 == 1:
			div1 += 1
		elif e % 3 == 2:
			div2 += 1
	w = min(div2, div1)
	score += w
	score += (div1 - w) // 3 + (div2 - w) // 3
	print(score)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * 3
	for i in a:
		c[i % 3] += 1
	(x, y) = (min(c[1], c[2]), max(c[1], c[2]))
	print(c[0] + x + (y - x) // 3)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	le = l
	les = []
	ans = 0
	item = 0
	for i in range(len(l)):
		if l[i] % 3 == 1:
			les.append(1)
		elif l[i] % 3 == 2:
			les.append(2)
		else:
			ans += 1
	if 2 in les:
		if 1 in les:
			while 2 in les and 1 in les:
				ans = ans + 1
				les.remove(2)
				les.remove(1)
			if 2 in les:
				while 2 in les:
					item = item + 1
					les.remove(2)
					if item == 3:
						item = 0
						ans = ans + 1
			if 1 in les:
				while 1 in les:
					item = item + 1
					les.remove(1)
					if item == 3:
						item = 0
						ans = ans + 1
		else:
			while 2 in les:
				item = item + 1
				les.remove(2)
				if item == 3:
					item = 0
					ans = ans + 1
	elif 1 in les:
		while 1 in les:
			item = item + 1
			les.remove(1)
			if item == 3:
				item = 0
				ans = ans + 1
	print(ans)


for i in range(int(input())):
	(c0, c1, c2) = (0, 0, 0)
	input()
	for i in [int(s) for s in input().split()]:
		if i % 3 == 0:
			c0 += 1
		elif i % 3 == 1:
			c1 += 1
		else:
			c2 += 1
	print(c0 + min(c1, c2) + (max(c1, c2) - min(c1, c2)) // 3)


from itertools import combinations

def solve(arr):
	total = 0
	for i in range(len(arr) - 1, -1, -1):
		if arr[i] % 3 == 0:
			total += 1
			arr.pop(i)
	i = 0
	while i < len(arr):
		found = False
		for j in range(i + 1, len(arr)):
			if (arr[i] + arr[j]) % 3 == 0:
				found = True
				total += 1
				arr.pop(j)
				arr.pop(i)
				break
		if not found:
			i += 1
	i = 0
	while i < len(arr):
		found1 = False
		j = i + 1
		while j < len(arr):
			found = False
			for k in range(j + 1, len(arr)):
				if (arr[i] + arr[j] + arr[k]) % 3 == 0:
					arr.pop(k)
					arr.pop(j)
					arr.pop(i)
					found = True
					total += 1
					break
			if not found:
				j += 1
			else:
				found1 = True
				break
		if not found1:
			i += 1
	return total
for _ in range(int(input().strip())):
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	print(solve(arr))


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [0, 0, 0]
	arr = list(map(int, input().split()))
	for i in arr:
		a[i % 3] += 1
	ans = a[0]
	z = min(a[1], a[2])
	ans += z
	a[1] -= z
	a[2] -= z
	ans += a[1] // 3
	ans += a[2] // 3
	print(ans)


q = int(input())
for i in range(q):
	n = int(input())
	l = [*map(int, input().split())]
	l1 = []
	l2 = []
	l3 = []
	for i in l:
		if i % 3 == 0:
			l3.append(i)
		if i % 3 == 1:
			l1.append(i)
		if i % 3 == 2:
			l2.append(i)
	cnt = len(l3)
	cnt += min(len(l2), len(l1))
	cnt += abs(len(l1) - len(l2)) // 3
	print(cnt)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

def LI():
	return list(map(int, input().split()))

def I():
	return int(input())

def LS():
	return input().split()

def S():
	return input()

def main():
	_n = I()
	ans = []
	for i in range(_n):
		n = I()
		l = LI()
		l2 = [0, 0, 0]
		for x in l:
			if x % 3 == 0:
				l2[0] += 1
			elif x % 3 == 1:
				l2[1] += 1
			else:
				l2[2] += 1
		p = l2[1]
		q = l2[2]
		a = l2[0]
		if p >= q:
			a += q
			p -= q
			a += p // 3
		else:
			a += p
			q -= p
			a += q // 3
		ans.append(a)
	for x in ans:
		print(x)
main()


t = int(input())
l1 = []
for _ in range(t):
	l2 = [0, 0, 0]
	n = input()
	l = list(map(int, input().split()))
	for i in l:
		l2[i % 3] += 1
	mi = min(l2[1], l2[2])
	l1.append(str(l2[0] + mi + (l2[1] + l2[2] - 2 * mi) // 3))
print('\n'.join(l1))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	c = 0
	for j in range(n):
		p = a[j] % 3
		if p == 0:
			c += 1
		else:
			b.append(p)
	l = 0
	r = len(b) - 1
	b.sort()
	while l < r and b[l] == 1 and (b[r] == 2):
		c += 1
		l += 1
		r -= 1
	if l == r:
		print(c)
	else:
		if l < r and b[r] == 1 and (b[l] == 1):
			s = sum(b[l:r + 1])
			c += s // 3
		elif l < r and b[r] == 2 and (b[l] == 2):
			s = sum(b[l:r + 1]) // 2
			c += s // 3
		print(c)


q = int(input())
for x in range(q):
	n = int(input())
	arr = [int(x) % 3 for x in input().split(' ')]
	(ones, zeros, twos) = (0, 0, 0)
	for item in arr:
		if item == 0:
			zeros += 1
		elif item == 1:
			ones += 1
		else:
			twos += 1
	ans = zeros + min(ones, twos) + abs(ones - twos) // 3
	print(ans)


t = int(input())
for x in range(t):
	n = int(input())
	tab = list(map(int, input().split()))
	tab_pod = []
	wyn = 0
	for x in tab:
		if x % 3 == 0:
			wyn += 1
			continue
		elif x % 3 == 1:
			tab_pod.append([x, 2])
		else:
			tab_pod.append([x, 1])
	if len(tab_pod) <= 1:
		print(wyn)
		continue
	tab_pod.sort(key=lambda z: z[1])
	while True:
		if tab_pod[0][1] + tab_pod[-1][1] == 3:
			wyn += 1
			del tab_pod[0]
			del tab_pod[-1]
		else:
			break
		if len(tab_pod) < 2:
			break
	wyn += len(tab_pod) // 3
	print(wyn)


def fn(s, n):
	cnt = 0
	sum1 = 0
	cnt2 = 0
	cnt3 = 0
	for i in range(n):
		if s[i] % 3 == 0:
			cnt += 1
		elif s[i] % 3 == 2:
			cnt2 += 1
		elif s[i] % 3 == 1:
			cnt3 += 1
	if cnt2 >= 0 and cnt3 >= 0:
		if cnt2 >= cnt3:
			cnt += cnt3
			cnt += (cnt2 - cnt3) // 3
		elif cnt3 > cnt2:
			cnt += cnt2
			cnt += (cnt3 - cnt2) // 3
	return cnt
n = int(input())
for _ in range(n):
	a = int(input())
	s = list(map(int, input().strip().split()))
	res = fn(s, a)
	print(res)


n = int(input())
for i in range(n):
	num = int(input())
	lst = list(map(int, input().split()))
	lst.sort(key=lambda x: -(x % 3))
	one = 0
	two = 0
	for j in range(num):
		if lst[j] % 3 == 1:
			one += 1
		elif lst[j] % 3 == 2:
			two += 1
		else:
			break
	else:
		j += 1
	(imin, imax) = sorted([one, two])
	print(num - j + imin + (imax - imin) // 3)


for _ in range(int(input())):
	n = int(input())
	lst = [i % 3 for i in map(int, input().split())]
	(a, b, c) = (lst.count(1), lst.count(2), lst.count(0))
	b1 = min(a, b)
	a1 = abs(a - b)
	r = b1 + a1 // 3 + c
	print(r)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	l = [0] * 4
	for i in a:
		l[i % 3] += 1
	sum = min(l[1], l[2])
	l[1] -= sum
	l[2] -= sum
	sum += l[0]
	sum += l[1] // 3
	sum += l[2] // 3
	print(sum)
	t -= 1


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	n = int(z())
	cnt = [0] * 3
	for i in zzz():
		cnt[i % 3] += 1
	ans = cnt[0]
	t = min(cnt[1], cnt[2])
	ans += t
	cnt[1] -= t
	cnt[2] -= t
	t1 = cnt[1] // 3
	t2 = cnt[2] // 3
	print(ans + t1 + t2)


for _ in range(int(input())):
	n = int(input())
	noList = list(map(int, input().split()))
	reducedList = list(map(lambda x: x % 3, noList))
	result = reducedList.count(0)
	ones = reducedList.count(1)
	twos = reducedList.count(2)
	if ones > twos:
		result += twos
		ones -= twos
		result += ones // 3
	else:
		result += ones
		twos -= ones
		result += twos // 3
	print(result)


import sys
q = int(sys.stdin.readline())
for _ in range(q):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	cnt0 = 0
	cnt1 = 0
	cnt2 = 0
	for i in range(n):
		if a[i] % 3 == 0:
			cnt0 += 1
		elif a[i] % 3 == 1:
			cnt1 += 1
		elif a[i] % 3 == 2:
			cnt2 += 1
	res = cnt0
	if cnt1 >= cnt2:
		res += cnt2
		cnt1 -= cnt2
		cnt2 = 0
		res += cnt1 // 3
	else:
		res += cnt1
		cnt2 -= cnt1
		cnt1 = 0
		res += cnt2 // 3
	print(res)


for _ in range(int(input())):
	k = int(input())
	l = list(map(int, input().rstrip().split()))
	l = list(map(lambda x: x % 3, l))
	one = l.count(1)
	two = l.count(2)
	three = l.count(0)
	c = three
	if one > two:
		c += two
		one -= two
		c += one // 3
	elif two > one:
		c += one
		two -= one
		c += two // 3
	elif one == two:
		c += one
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	one = 0
	two = 0
	ans = 0
	for i in a:
		if i % 3 == 0:
			ans += 1
		elif i % 3 == 1:
			one += 1
		else:
			two += 1
	m = min(one, two)
	one -= m
	two -= m
	ans += m
	ans += one // 3
	ans += two // 3
	print(ans)


q = int(input())
for i in range(q):
	n = int(input())
	arr = list(map(int, input().split()))
	ost = [0] * 3
	for el in arr:
		ost[el % 3] += 1
	summ = ost[0] + min(ost[1], ost[2])
	a = min(ost[1], ost[2])
	ost[1] -= a
	ost[2] -= a
	summ += ost[1] // 3
	summ += ost[2] // 3
	print(summ)


q = int(input())
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	a0 = a1 = a2 = 0
	for i in range(n):
		if a[i] % 3 == 0:
			a0 += 1
		elif a[i] % 3 == 1:
			a1 += 1
		else:
			a2 += 1
	a0 += min(a1, a2)
	a1 = abs(a1 - a2)
	a0 += a1 // 3
	print(a0)


def div(n):
	ans = 0
	a = [int(i) % 3 for i in input().split()]
	ans += a.count(0)
	one = a.count(1)
	two = a.count(2)
	ans += min(one, two)
	ans += abs(two - one) // 3
	return ans
t = int(input())
for i in range(t):
	print(div(int(input())))


t = int(input())
for ii in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x0 = 0
	x1 = 0
	x2 = 0
	for i in range(n):
		if a[i] % 3 == 0:
			x0 += 1
		elif a[i] % 3 == 1:
			x1 += 1
		elif a[i] % 3 == 2:
			x2 += 1
	mi = min(x1, x2)
	ma = max(x1, x2)
	print(x0 + mi + (ma - mi) // 3)


t = int(input())
while t > 0:
	n = int(input())
	ar = map(int, input().split())
	cnt0 = 0
	cnt1 = 0
	cnt2 = 0
	for i in ar:
		if i % 3 == 0:
			cnt0 += 1
		elif i % 3 == 1:
			cnt1 += 1
		elif i % 3 == 2:
			cnt2 += 1
	ans = cnt0 + min(cnt1, cnt2)
	ans += (cnt1 + cnt2 - 2 * min(cnt1, cnt2)) // 3
	print(ans)
	t -= 1


import sys, math

def read_int():
	return int(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def read_string():
	return sys.stdin.readline().strip()

def read_string_list(delim=' '):
	return sys.stdin.readline().strip().split(delim)

def print_int_list(l):
	print(' '.join(map(str, l)))

def err_print(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)
q = read_int()
for _ in range(q):
	n = read_int()
	arr = read_int_list()
	mod_arr = [e % 3 for e in arr]
	counters = [0, 0, 0]
	for i in mod_arr:
		counters[i] += 1
	ans = counters[0]
	temp = min(counters[1], counters[2])
	ans += temp
	counters[1] -= temp
	counters[2] -= temp
	ans += counters[1] // 3
	ans += counters[2] // 3
	print(ans)


t = int(input())
for x in range(t):
	n = int(input())
	arr = [int(x) % 3 for x in input().split()]
	ans = 0
	one = 0
	two = 0
	for y in arr:
		if y == 0:
			ans += 1
		elif y == 1:
			one += 1
		elif y == 2:
			two += 1
	if one and two:
		m = min(one, two)
		ans += m
		one -= m
		two -= m
	if one:
		ans += one // 3
	if two:
		ans += two // 3
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ost1 = 0
	ost2 = 0
	ans = 0
	for i in range(n):
		if a[i] % 3 == 0:
			ans += 1
		elif a[i] % 3 == 1:
			ost1 += 1
		elif a[i] % 3 == 2:
			ost2 += 1
	q = min(ost1, ost2)
	ans += q
	ost1 -= q
	ost2 -= q
	if ost1 != 0:
		ans += ost1 // 3
	if ost2 != 0:
		ans += ost2 // 3
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	li1 = list(map(int, input().split()))
	(cn1, cn2, cn3) = (0, 0, 0)
	for j in li1:
		if j % 3 == 0:
			cn1 += 1
		elif j % 3 == 1:
			cn2 += 1
		elif j % 3 == 2:
			cn3 += 1
	cn = cn1 + min(cn2, cn3)
	(cn2, cn3) = (cn2 - min(cn2, cn3), cn3 - min(cn2, cn3))
	cn += cn2 // 3 + cn3 // 3
	cn = int(cn)
	print(cn)


q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	p = [0, 0, 0]
	for j in a:
		p[j % 3] += 1
	c = p[0] + min(p[1], p[2]) + (max(p[1], p[2]) - min(p[1], p[2])) // 3
	print(c)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	one = two = 0
	ans = 0
	for i in a:
		if i % 3 == 2:
			two += 1
		elif i % 3 == 1:
			one += 1
		else:
			ans += 1
	print(ans + min(one, two) + abs(one - two) // 3)


t = int(input())
for i in range(t):
	n = int(input())
	A = input().split()
	a = 0
	b = 0
	c = 0
	for j in range(n):
		if int(A[j]) % 3 == 0:
			a += 1
		if int(A[j]) % 3 == 1:
			b += 1
		if int(A[j]) % 3 == 2:
			c += 1
	print(a + min(b, c) + abs(b - c) // 3)


n = int(input())
a = []
for _ in range(n):
	input()
	a.append(input().split())
for t in a:
	t = [sum([int(i) for i in j]) % 3 for j in t]
	while True:
		if 1 in t and 2 in t:
			t.pop(t.index(1))
			t.pop(t.index(2))
			t.append(0)
		elif t.count(1) == 0 and t.count(2) > 2:
			t.pop(t.index(2))
			t.pop(t.index(2))
			t.pop(t.index(2))
			t.append(0)
		elif t.count(1) > 2 and t.count(2) == 0:
			t.pop(t.index(1))
			t.pop(t.index(1))
			t.pop(t.index(1))
			t.append(0)
		else:
			break
	print(t.count(0))


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		r = 0
		a2 = [i % 3 == 0 for i in a]
		r += sum(a2)
		a3 = [i for i in a if i % 3 != 0]
		if a3:
			num2 = 0
			num1 = 0
			for a3e in a3:
				if a3e % 3 == 1:
					num1 += 1
				elif a3e % 3 == 2:
					num2 += 1
			if num2 >= num1:
				r += num1
				num2 -= num1
				r += num2 // 3
			else:
				r += num2
				num1 -= num2
				r += num1 // 3
		print(r)
main()


for tt in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	cnt0 = 0
	cnt1 = 0
	cnt2 = 0
	for i in range(n):
		if l[i] % 3 == 0:
			cnt0 += 1
		if l[i] % 3 == 1:
			cnt1 += 1
		if l[i] % 3 == 2:
			cnt2 += 1
	r1 = cnt0
	r2 = min(cnt1, cnt2)
	r3 = (max(cnt1, cnt2) - min(cnt1, cnt2)) // 3
	print(r1 + r2 + r3)


t = int(input())
for o in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	q = [0 for x in range(3)]
	count = 0
	for i in range(n):
		q[l[i] % 3] += 1
	count += q[0]
	if q[1] > q[2]:
		count += q[2]
		q[1] = q[1] - q[2]
		count += q[1] // 3
	elif q[2] > q[1]:
		count += q[1]
		q[2] = q[2] - q[1]
		count += q[2] // 3
	else:
		count += q[2]
	print(count)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	r = [0, 0, 0]
	for x in a:
		r[x % 3] += 1
	a = r[0] + min(r[1], r[2])
	l = max(r[1], r[2]) - min(r[1], r[2])
	a += l // 3
	print(a)


n = int(input())
for j in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	cnt0 = 0
	cnt1 = 0
	cnt2 = 0
	for i in l:
		if i % 3 == 0:
			cnt0 += 1
		elif i % 3 == 1:
			cnt1 += 1
		else:
			cnt2 += 1
	print(cnt0 + min(cnt1, cnt2) + abs(cnt1 - cnt2) // 3)


n = int(input())
for i in range(n):
	m = int(input())
	nums = [int(j) % 3 for j in input().split()]
	num_of_1 = nums.count(1)
	num_of_2 = nums.count(2)
	num_of_3 = nums.count(0)
	num_of_pairs = min(num_of_1, num_of_2)
	k = num_of_pairs + (num_of_1 - num_of_pairs) // 3 + (num_of_2 - num_of_pairs) // 3 + num_of_3
	print(k)


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().split())
inl = lambda : list(map(int, input().split()))
out = lambda x: print('\n'.join(map(str, x)))
ans = []
t = ini()
for _ in range(t):
	n = ini()
	a = inl()
	count = [0, 0, 0]
	for i in a:
		count[i % 3] += 1
	count[0] += min(count[1], count[2])
	tmp = min(count[1], count[2])
	count[1] -= tmp
	count[2] -= tmp
	count[0] += count[1] // 3 + count[2] // 3
	ans.append(count[0])
out(ans)


t = int(input())
for _ in range(t):
	input()
	l = [i % 3 for i in list(map(int, input().split()))]
	l_2 = l.count(2)
	l_1 = l.count(1)
	print(l.count(0) + min(l_2, l_1) + abs(l_2 - l_1) // 3)


for j in range(int(input())):
	a = [0, 0, 0]
	n = int(input())
	s = list(map(int, input().split()))
	for i in range(n):
		a[s[i] % 3] += 1
	ma = max(a[1], a[2])
	mi = min(a[1], a[2])
	print(a[0] + mi + (ma - mi) // 3)


n = int(input())
b = []
for i in range(n):
	n = int(input())
	a = list(map(int, input().split()))
	b.append(a)
for i in b:
	c = 0
	m = 0
	p = 0
	for j in i:
		if j % 3 == 0:
			c += 1
		elif j % 3 == 1:
			p += 1
		elif j % 3 == 2:
			m += 1
	if p > m:
		c += m + (p - m) // 3
	else:
		c += p + (m - p) // 3
	print(c)


import sys
q = int(next(sys.stdin))
for _ in range(q):
	n = int(next(sys.stdin))
	a = map(int, next(sys.stdin).split(' '))
	result = 0
	mod_sum = []
	for ai in a:
		if ai % 3 == 0:
			result += 1
		else:
			mod_sum.append(ai % 3)
	mod_sum = sorted(mod_sum)
	l = len(mod_sum)
	for i in range(l // 2):
		if (mod_sum[i] + mod_sum[l - i - 1]) % 3 == 0:
			result += 1
		else:
			mod_sum = mod_sum[i:l - i]
			break
		if i == l // 2 - 1:
			mod_sum = []
	acc = 0
	for ai in mod_sum:
		acc += ai
		if acc % 3 == 0:
			result += 1
			acc = 0
	print(result)


for i in range(int(input())):
	input()
	x = 0
	ost1 = 0
	ost2 = 0
	for i in input().split():
		i = int(i)
		if i % 3 == 0:
			x += 1
		elif i % 3 == 1:
			ost1 += 1
		else:
			ost2 += 1
	if ost2 >= ost1:
		print(ost1 + x + (ost2 - ost1) // 3)
	else:
		print(ost2 + (ost1 - ost2) // 3 + x)


from sys import stdin

def main():
	t = int(stdin.readline())
	for query in range(t):
		n = int(stdin.readline())
		ln = [int(x) for x in stdin.readline().strip().split()]
		divise = [0] * 3
		for numbers in ln:
			divise[numbers % 3] += 1
		resultado = divise[0]
		minimo = min(divise[1], divise[2])
		resultado += minimo
		divise[1] -= minimo
		divise[2] -= minimo
		resultado += (divise[1] + divise[2]) // 3
		print(resultado)
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	c0 = 0
	c1 = 0
	c2 = 0
	ans = 0
	for i in range(len(arr)):
		arr[i] = arr[i] % 3
		if arr[i] == 0:
			c0 += 1
		elif arr[i] == 1:
			c1 += 1
		else:
			c2 += 1
	mn = min(c1, c2)
	c1 = c1 - mn
	c2 = c2 - mn
	ans = c0 + mn + (c1 + c2) // 3
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * 3
	for i in a:
		c[i % 3] += 1
	(x, y, z) = c
	print(x + min(y, z) + abs(z - y) // 3)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
t = intIn()
for _ in range(t):
	n = intIn()
	a = listIn()
	count = [0] * 3
	for i in range(n):
		if a[i] % 3 == 1:
			count[1] += 1
		elif a[i] % 3 == 2:
			count[2] += 1
		else:
			count[0] += 1
	ans = count[0]
	if count[1] == count[2]:
		ans += count[2]
	elif count[1] > count[2]:
		rem = count[1] - count[2]
		ans += count[2] + rem // 3
	else:
		rem = count[2] - count[1]
		ans += count[1] + rem * 2 // 6
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	nd3 = 0
	nd2 = 0
	nd1 = 0
	for x in a:
		if x % 3 == 0:
			nd3 += 1
		elif x % 3 == 1:
			nd1 += 1
		else:
			nd2 += 1
	res = 0
	res += nd3
	if nd1 > nd2:
		res += nd2
		res += (nd1 - nd2) // 3
	elif nd1 == nd2:
		res += nd2
	else:
		res += nd1
		res += (nd2 - nd1) // 3
	print(res)


t = int(input())
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	f = [0] * 3
	for i in arr:
		f[i % 3] += 1
	ans = f[0]
	tr = min(f[1], f[2])
	f[1] -= tr
	f[2] -= tr
	ans += tr
	ans += f[1] // 3
	ans += f[2] // 3
	print(ans)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	aa = map(lambda x: int(x) % 3, input().split())
	cnt = Counter(aa)
	res = cnt[0]
	if cnt[2] <= cnt[1]:
		res += cnt[2] + (cnt[1] - cnt[2]) // 3
	else:
		res += cnt[1] + (cnt[2] - cnt[1]) // 3
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [x % 3 for x in a]
	b1 = b.count(1)
	b2 = b.count(2)
	b0 = b.count(0)
	b12 = min(b1, b2)
	remain = max(b1, b2) - b12
	belse = remain // 3
	print(b0 + b12 + belse)


for _ in range(int(input())):
	n = int(input())
	a = [int(j) for j in input().split()]
	(c, d, e, f) = (0, 0, 0, 0)
	for i in range(n):
		if a[i] % 3 == 0:
			d += 1
		elif a[i] % 3 == 1:
			e += 1
		else:
			f += 1
	c = min(f, e) + d
	t = min(f, e)
	e = e - t
	f = f - t
	c += e // 3 + f // 3
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	a1 = [x % 3 for x in a]
	o = a1.count(0)
	on = a1.count(1)
	tw = a1.count(2)
	print(o + abs(on - tw) // 3 + min(on, tw))


t1 = int(input())
for _ in range(t1):
	c1 = c2 = c3 = t = 0
	n = int(input())
	a = list(map(int, input().split()))
	for i in a:
		i %= 3
		if i == 0:
			c3 += 1
		elif i == 1:
			c1 += 1
		else:
			c2 += 1
	t += c3
	t2 = min(c1, c2)
	c1 -= t2
	c2 -= t2
	t += t2
	t += c1 // 3 + c2 // 3
	print(t)


from sys import stdin
nQ = int(stdin.readline())
for q in range(nQ):
	nQ = int(stdin.readline())
	numbers = [int(t) % 3 for t in stdin.readline().split(' ')]
	counts = {0: 0, 1: 0, 2: 0}
	for x in numbers:
		counts[x] += 1
	combinations = min(counts[1], counts[2])
	left1 = counts[1] - combinations
	left2 = counts[2] - combinations
	total = counts[0] + combinations + left1 // 3 + left2 // 3
	print(total)


T = int(input())
for test in range(T):
	N = int(input())
	an = list(map(int, input().split()))
	mods = [0, 0, 0]
	for a in an:
		if a % 3 == 1:
			mods[1] += 1
		elif a % 3 == 2:
			mods[2] += 1
		else:
			mods[0] += 1
	modsnz = mods[1:3]
	rem = mods[0] + min(modsnz) + (max(modsnz) - min(modsnz)) // 3
	print(rem)


import sys
read = sys.stdin.readline
for _ in range(int(read())):
	n = int(read())
	arr = list(map(int, read().split()))
	ans = [0, 0, 0]
	for i in range(n):
		mod = arr[i] % 3
		ans[mod] += 1
	while ans[1] and ans[2]:
		ans[1] -= 1
		ans[2] -= 1
		ans[0] += 1
	if ans[1]:
		ans[0] += ans[1] // 3
	if ans[2]:
		ans[0] += ans[2] // 3
	print(ans[0])


t = int(input())
for l in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	co1 = 0
	co2 = 0
	co = 0
	for i in arr:
		if i % 3 == 0:
			co += 1
		if i % 3 == 1:
			co1 += 1
		if i % 3 == 2:
			co2 += 1
	ans = co
	ans += min(co1, co2)
	left = max(co2, co1) - min(co2, co1)
	ans += int(left / 3)
	print(ans)


def solve(arr):
	if len(arr) == 0:
		return 0
	cnt = [0] * 3
	for x in arr:
		cnt[x % 3] += 1
	ans = cnt[0]
	merge_cnt = min(cnt[1], cnt[2])
	cnt[1] -= merge_cnt
	cnt[2] -= merge_cnt
	ans += merge_cnt
	ans += cnt[1] // 3
	ans += cnt[2] // 3
	return ans
t = int(input().strip())
while t:
	t -= 1
	n = input()
	arr = map(int, input().strip().split(' '))
	arr = list(arr)
	print(solve(arr))


t = int(input())
for i in range(t):
	n = int(input())
	a = map(int, input().split())
	count = [0, 0, 0]
	for element in a:
		r = element % 3
		count[r] += 1
	if count[2] >= count[1]:
		print(count[0] + count[1] + (count[2] - count[1]) // 3)
	else:
		print(count[0] + count[2] + (count[1] - count[2]) // 3)


def read(t=int):
	return list(map(t, input().strip().split(' ')))
t = read()[0]
while t:
	t -= 1
	n = read()[0]
	a = [i % 3 for i in read()]
	c = [a.count(0), a.count(1), a.count(2)]
	k = min(c[1], c[2])
	c[0] += k
	c[1] -= k
	c[2] -= k
	print(c[0] + c[1] // 3 + c[2] // 3)


n = int(input())
for i in range(n):
	q = int(input())
	l = list(map(int, input().split()))
	a = 0
	b = 0
	c = 0
	for i in range(q):
		if l[i] % 3 == 0:
			a += 1
		elif l[i] % 3 == 1:
			b += 1
		else:
			c += 1
	print(a + min(c, b) + (max(c, b) - min(c, b)) // 3)


def compute(arr):
	cts = [0, 0, 0]
	for i in range(len(arr)):
		val = arr[i] % 3
		cts[val] = cts[val] + 1
	v1 = min(cts[1], cts[2])
	v2 = max(cts[1], cts[2])
	out = cts[0] + v1 + (v2 - v1) // 3
	return out

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		arr = input().split(' ')
		for i in range(n):
			arr[i] = int(arr[i])
		print(compute(arr))
main()


t = int(input())
for j in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	for i in range(n):
		li[i] = li[i] % 3
	z = li.count(0)
	a = li.count(1)
	b = li.count(2)
	if a > b:
		z = z + b
		a = a - b
		z = z + a // 3
	else:
		z = z + a
		b = b - a
		z = z + b // 3
	print(z)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	one = 0
	two = 0
	three = 0
	for i in range(n):
		if a[i] % 3 == 0:
			three += 1
		elif a[i] % 3 == 1:
			one += 1
		else:
			two += 1
	ans = three
	if one >= two:
		ans += two
		one -= two
		ans += one // 3
	else:
		ans += one
		two -= one
		ans += two // 3
	print(ans)


for i in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	type1 = 0
	type2 = 0
	ans = 0
	for item in l1:
		if item % 3 == 0:
			ans += 1
		elif item % 3 == 1:
			type1 += 1
		else:
			type2 += 1
	x = min(type1, type2)
	ans += x
	type1 -= x
	type2 -= x
	ans += type1 // 3 + type2 // 3
	print(ans)


def fun(n, a):
	a.sort()
	(count, t1, t2) = (0, [], [])
	for i in a:
		if i % 3 == 0:
			count += 1
		elif i % 3 == 1:
			t1.append(i)
		else:
			t2.append(i)
	(l1, l2) = (len(t1), len(t2))
	m = min(l1, l2)
	count += m
	(l1, l2) = (l1 - m, l2 - m)
	if l1 == 0:
		count += l2 // 3
	else:
		count += l1 // 3
	return count
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	print(fun(n, a))


t = int(input())
for x in range(t):
	n = int(input())
	cnt = [0, 0, 0, 0]
	ar = input().split()
	for i in range(len(ar)):
		cnt[int(ar[i]) % 3] += 1
	ans = cnt[0]
	ans += min(cnt[1], cnt[2])
	d = min(cnt[1], cnt[2])
	cnt[1] -= d
	cnt[2] -= d
	ans += cnt[1] // 3
	ans += cnt[2] // 3
	print(ans)


te = int(input(''))
for _ in range(te):
	n = int(input(''))
	a = list(map(int, input().split()))
	cnt = 0
	ans = 0
	b = []
	for i in a:
		if i % 3 == 0:
			cnt += 1
		else:
			b.append(i % 3)
	b.sort()
	o = 0
	t = 0
	for i in range(len(b)):
		if b[i] == 1:
			o += 1
		else:
			t += 1
	cnt += min(o, t)
	j = min(o, t)
	o -= j
	t -= j
	if o > t:
		o = o - t
		cnt += o // 3
	else:
		t = t - o
		cnt += t // 3
	print(cnt)


n = int(input())
for i in range(n):
	m = int(input())
	a = [int(i) for i in input().split()]
	e = 0
	one = 0
	two = 0
	for j in range(0, len(a)):
		rem = 3 - a[j] % 3
		if rem == 2:
			two = two + 1
		elif rem == 1:
			one = one + 1
		else:
			e = e + 1
	f = min(one, two)
	e = e + f
	one = one - f
	two = two - f
	print(e + (one + two) // 3)


t = int(input())
for _ in range(t):
	n = int(input())
	cnt = [0, 0, 0]
	for i in list(map(int, input().split())):
		cnt[i % 3] += 1
	res = cnt[0]
	y = min(cnt[1], cnt[2])
	cnt[1] -= y
	cnt[2] -= y
	res += y
	res += cnt[1] // 3
	res += cnt[2] // 3
	print(res)


for useless in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	lis = [0] * 3
	for i in range(n):
		lis[a[i] % 3] += 1
	print(lis[0] + abs(lis[1] - lis[2]) // 3 + min(lis[1], lis[2]))


for _ in range(int(input())):
	n = int(input())
	L = [0] * 3
	for k in map(int, input().split()):
		L[k % 3] += 1
	mn = min(L[1:])
	L[1] -= mn
	L[2] -= mn
	ans = L[0] + mn + L[1] // 3 + L[2] // 3
	print(ans)


from collections import deque
from math import log, sqrt, ceil

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
t = ii()
while t:
	t -= 1
	n = ii()
	a = li()
	b = []
	c = 0
	for i in range(n):
		if a[i] % 3 == 0:
			c += 1
		else:
			x = a[i] % 3
			b.append(3 - x)
	x = b.count(2)
	y = b.count(1)
	c += min(x, y)
	x = max(x, y) - min(x, y)
	c += x // 3
	print(c)


q = int(input())
for i in range(q):
	n = int(input())
	m = []
	l = list(map(int, input().split()))[:n]
	for j in range(n):
		m.append(l[j] % 3)
	c = m.count(0)
	d = m.count(1)
	e = m.count(2)
	if d > e:
		print(c + e + (d - e) // 3)
	else:
		print(c + d + (e - d) // 3)


t = int(input())
while t:
	n = int(input())
	List = list(map(int, input().split()))
	Counter_3 = 0
	Counter_1 = 0
	Counter_2 = 0
	for i in List:
		if i % 3 == 0:
			Counter_3 += 1
		elif i % 3 == 1:
			Counter_1 += 1
		elif i % 3 == 2:
			Counter_2 += 1
	print(Counter_3 + min(Counter_1, Counter_2) + abs(Counter_1 - Counter_2) // 3)
	t -= 1


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt = 0
	mod1 = 0
	mod2 = 0
	for a in arr:
		if a % 3 == 0:
			cnt += 1
		elif a % 3 == 1:
			mod1 += 1
		else:
			mod2 += 1
	cnt += min(mod1, mod2)
	if mod1 - mod2 > 2:
		cnt += int((mod1 - mod2) / 3)
	elif mod2 - mod1 > 2:
		cnt += int((mod2 - mod1) / 3)
	print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	res = 0
	modulus = [0] * 3
	for val in a:
		modulus[val % 3] += 1
	min_12 = min(modulus[1], modulus[2])
	print('{}'.format(modulus[0] + min_12 + (modulus[1] - min_12) // 3 + (modulus[2] - min_12) // 3))


def merge(arr, n):
	dict1 = {}
	for i in range(0, 3):
		dict1[i] = dict1.get(i, 0)
	for k in range(n):
		dict1[arr[k] % 3] = dict1.get(arr[k] % 3) + 1
	if dict1[2] >= dict1[1]:
		dict1[0] = dict1[0] + dict1[1]
		dict1[2] = dict1[2] - dict1[1]
		dict1[0] = dict1[0] + dict1[2] // 3
	else:
		dict1[0] = dict1[0] + dict1[2]
		dict1[1] = dict1[1] - dict1[2]
		dict1[0] = dict1[0] + dict1[1] // 3
	return dict1[0]
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().strip().split(' ')))
	print(merge(arr, n))


n = int(input())
j = 0
while j < n:
	t = int(input())
	a = list(map(int, input().split()))
	count0 = 0
	count1 = 0
	count2 = 0
	for i in range(t):
		if a[i] % 3 == 0:
			count0 += 1
		if a[i] % 3 == 1:
			count1 += 1
		elif a[i] % 3 == 2:
			count2 += 1
	ans = min(count1, count2)
	count1 -= ans
	count2 -= ans
	ans += count2 // 3
	ans += count1 // 3
	print(ans + count0)
	j += 1


for _ in range(int(input())):
	n = int(input())
	a = input().strip().split()
	d = {0: 0, 1: 0, 2: 0}
	for i in a:
		d[int(i) % 3] += 1
	k = min(d[1], d[2])
	d[1] -= k
	d[2] -= k
	d[0] += k
	d[0] += d[1] // 3
	d[0] += d[2] // 3
	print(d[0])


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = [0] * 3
	for x in l:
		d[x % 3] += 1
	c = d[0]
	r = min(d[1], d[2])
	c = c + r + (d[1] - r) // 3 + (d[2] - r) // 3
	print(c)


q = int(input())
result = [0] * q
for i in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	ones = 0
	twos = 0
	for j in a:
		if j % 3 == 0:
			result[i] += 1
			continue
		elif (j - 1) % 3 == 0:
			ones += 1
		elif (j + 1) % 3 == 0:
			twos += 1
	while ones != 0 and twos != 0:
		ones -= 1
		twos -= 1
		result[i] += 1
	if ones != 0:
		result[i] += ones // 3
	elif twos != 0:
		result[i] += twos // 3
for i in result:
	print(i)


for i in range(int(input())):
	input()
	j = c = o = t = 0
	a = list(map(int, input().split()))
	for i in range(len(a)):
		if a[i] % 3 == 2:
			t += 1
		elif a[i] % 3 == 1:
			o += 1
		else:
			c += 1
	c += min(o, t)
	c += (max(o, t) - min(o, t)) // 3
	print(c)


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = LIST()
	A = [a % 3 for a in A]
	C = Counter(A)
	ans = C[0]
	while C[2] and C[1]:
		C[2] -= 1
		C[1] -= 1
		ans += 1
	while C[2] >= 3:
		C[2] -= 3
		ans += 1
	while C[1] >= 3:
		C[1] -= 3
		ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = [int(x) % 3 for x in input().split()]
	d = d1 = d2 = 0
	for e in l:
		if e == 0:
			d += 1
		elif e == 1:
			d1 += 1
		else:
			d2 += 1
	x = min(d1, d2)
	d += x
	d1 -= x
	d2 -= x
	if d1 != 0:
		d += d1 // 3
	if d2 != 0:
		d += d2 // 3
	print(d)


n = int(input())
for i in range(0, n):
	o = int(input())
	p = input().rstrip().split(' ')
	l = [0] * 3
	for j in range(0, len(p)):
		l[int(p[j]) % 3] += 1
	s = 0
	s += l[0]
	s += min(l[1], l[2])
	if min(l[1], l[2]) == l[2]:
		l[1] -= l[2]
		s += l[1] // 3
	elif min(l[1], l[2]) == l[1]:
		l[2] -= l[1]
		s += l[2] // 3
	print(s)


from collections import Counter

def rearrange(array):
	dict_3 = Counter()
	count = 0
	for el in array:
		rest = el - int(el // 3) * 3
		if rest == 0:
			count += 1
		elif dict_3[rest] > 0:
			count += 1
			dict_3[rest] -= 1
		else:
			dict_3[3 - rest] += 1
	for (rest, value) in dict_3.items():
		num = int(value // 3)
		count += num
	return count
n = int(input())
input_a = []
for i in range(0, n):
	s = input()
	a = list(map(int, input().split(' ')))
	input_a.append(a)
for i in input_a:
	result = rearrange(i)
	print(result)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s1 = 0
	s2 = 0
	s = 0
	c = 0
	count = 0
	for el in a:
		if el % 3 != 0:
			if el % 3 == 1:
				s1 += 1
			else:
				s2 += 1
		else:
			c += 1
	print(c + min(s1, s2) + abs(s1 - s2) // 3)


t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	cnt = 0
	a = []
	for j in range(n):
		if x[j] % 3 == 0:
			cnt += 1
		else:
			a.append(x[j] % 3)
	if a.count(1) >= a.count(2):
		cnt += a.count(2)
		cnt += (a.count(1) - a.count(2)) // 3
	else:
		cnt += a.count(1)
		cnt += (a.count(2) - a.count(1)) // 3
	print(cnt)


import sys
n = int(sys.stdin.readline())
for i in range(n):
	k = int(sys.stdin.readline())
	array = [int(j) for j in sys.stdin.readline().split()]
	one = 0
	two = 0
	three = 0
	for val in array:
		if val % 3 == 0:
			three += 1
		elif val % 3 == 1:
			one += 1
		else:
			two += 1
	if two > one:
		add = one
		if two - one > 2:
			add += (two - one) // 3
	else:
		add = two
		if one - two > 2:
			add += (one - two) // 3
	print(three + add)


from collections import Counter
q = int(input())
for _ in range(q):
	n = int(input())
	a = [ai % 3 for ai in map(int, input().split())]
	c = Counter(a)
	res = c.get(0, 0)
	p1 = min(c.get(1, 0), c.get(2, 0))
	c[1] = max(c.get(1, 0) - p1, 0)
	c[2] = max(c.get(2, 0) - p1, 0)
	res += p1
	if c.get(1):
		res += c.get(1) // 3
	if c.get(2):
		res += c.get(2) // 3
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = [0] * 3
	for i in l:
		c[i % 3] += 1
	print(c[0] + min(c[1], c[2]) + (max(c[1], c[2]) - min(c[1], c[2])) // 3)


for _ in ' ' * int(input()):
	a = int(input())
	z = [i % 3 for i in map(int, input().split())]
	_1 = z.count(1)
	_2 = z.count(2)
	r = min(_1, _2)
	_1 -= r
	_2 -= r
	print(z.count(0) + r + _1 // 3 + _2 // 3)


n = int(input())
for _ in range(n):
	m = int(input())
	l = list(map(int, input().split()))
	d = [e % 3 for e in l]
	a = d.count(0)
	b = d.count(1)
	c = d.count(2)
	if b > c:
		print(a + c + (b - c) // 3)
	else:
		print(a + b + (c - b) // 3)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().strip().split(' ')]
	n2 = 0
	n1 = 0
	n3 = 0
	for i in arr:
		if i % 3 == 0:
			n3 += 1
		elif i % 3 == 2:
			n2 += 1
		else:
			n1 += 1
	if n1 > n2:
		ans = n3 + n2 + (n1 - n2) // 3
	else:
		ans = n3 + n1 + (n2 - n1) // 3
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	(num0, num1, num2) = (0, 0, 0)
	for j in range(n):
		if A[j] % 3 == 0:
			num0 += 1
		elif A[j] % 3 == 1:
			num1 += 1
		elif A[j] % 3 == 2:
			num2 += 1
	print(num0 + min(num1, num2) + abs(num1 - num2) // 3)


t = int(input())
for z in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	b = 0
	c = 0
	for i in range(0, n):
		if a[i] % 3 == 0:
			l += 1
		elif a[i] % 3 == 1:
			b += 1
		else:
			c += 1
	p = min(b, c)
	if p == b:
		c -= b
		p += c // 3
	else:
		b -= c
		p += b // 3
	print(l + p)


t = int(input())
for _ in range(t):
	c1 = 0
	c2 = 0
	ans = 0
	n = int(input())
	p = [int(x) for x in input().split()]
	for a in p:
		if a % 3 == 1:
			c1 += 1
		elif a % 3 == 2:
			c2 += 1
		else:
			ans += 1
	if c1 < c2:
		ans += c1
		c2 -= c1
		ans += c2 // 3
	else:
		ans += c2
		c1 -= c2
		ans += c1 // 3
	print(ans)


vstup1 = int(input())
for i in range(vstup1):
	n = int(input())
	vstup3 = list(map(int, input().split()))
	query = [i for i in vstup3 if i != 0]
	query = list(map(lambda x: x % 3, query))
	x = query.count(0)
	y = min([query.count(1), query.count(2)])
	z = (len(query) - x - 2 * y) // 3
	print(z + y + x)


def di(x):
	x = int(x)
	return x % 3
n = int(input())
for i in range(n):
	a = int(input())
	l = list(map(di, input().split()))
	ans = l.count(0)
	x = l.count(1)
	y = l.count(2)
	(x, y) = (min(x, y), max(x, y))
	print(ans + x + (y - x) // 3)


t = int(input())
ans = []
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k1 = 0
	k2 = 0
	k = 0
	for i in a:
		if i % 3 == 0:
			k += 1
		elif i % 3 == 2:
			k2 += 1
		elif i % 3 == 1:
			k1 += 1
	if k1 > k2:
		k += k2 + (k1 - k2) // 3
	else:
		k += k1 + (k2 - k1) // 3
	ans.append(k)
for i in ans:
	print(i)


import sys, math
input = sys.stdin.readline
t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	(n1, n2, n3) = (0, 0, 0)
	for i in range(n):
		if a[i] % 3 == 0:
			n3 += 1
		if a[i] % 3 == 1:
			n1 += 1
		if a[i] % 3 == 2:
			n2 += 1
	ans = n3 + min(n1, n2)
	ans += int(abs(n2 - n1) / 3)
	print(ans)
	t -= 1


t = int(input())
while t > 0:
	n = int(input())
	arr = [int(i) for i in input().split()]
	count = 0
	a = 0
	b = 0
	for x in range(len(arr)):
		if arr[x] % 3 == 0:
			count += 1
		elif arr[x] % 3 == 1:
			a += 1
		else:
			b += 1
	if a >= b:
		k = a - b
		count = count + b
	else:
		k = b - a
		count = count + a
	count = count + int(k / 3)
	print(count)
	t = t - 1


for _ in range(int(input())):
	input()
	M = [0] * 3
	for a in map(int, input().split()):
		M[a % 3] += 1
	print(M[0] + min(M[1], M[2]) + abs(M[1] - M[2]) // 3)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	p = dict()
	count1 = 0
	count2 = 0
	count0 = 0
	ans = 0
	for i in a:
		if i % 3 == 1:
			count1 += 1
		elif i % 3 == 2:
			count2 += 1
		elif i % 3 == 0:
			count0 += 1
	if count2 < count1:
		ans = count0 + count2 + (count1 - count2) // 3
	else:
		ans = count0 + count1 + (count2 - count1) // 3
	print(ans)


from math import *
from collections import *
t = int(input())
for y in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = [0, 0, 0]
	for i in range(n):
		ind = a[i] % 3
		d[ind] += 1
	x = min(d[1], d[2])
	d[0] += x
	d[1] -= x
	d[2] -= x
	d[0] += d[2] // 3 + d[1] // 3
	print(d[0])


for i in range(int(input())):
	input()
	cnt = [0, 0, 0]
	for a in map(int, input().split()):
		cnt[a % 3] += 1
	tmp = min(cnt[1], cnt[2])
	cnt[0] += tmp
	cnt[1] -= tmp
	cnt[2] -= tmp
	cnt[0] += cnt[1] // 3 + cnt[2] // 3
	print(cnt[0])


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l_1 = 0
	l1 = 0
	l0 = 0
	for i in l:
		if i % 3 == 0:
			l0 += 1
		elif i % 3 == 1:
			l1 += 1
		else:
			l_1 += 1
	print(l0 + min(l1, l_1) + abs(l1 - l_1) // 3)


n = int(input())
while n:
	q = int(input())
	x = list(map(int, input().split()))
	y = [i % 3 for i in x]
	k = y.count(0)
	p = y.count(1)
	m = y.count(2)
	if p == m:
		print(k + min(p, m))
	elif p > m:
		p = p - m
		p = p // 3
		print(k + p + m)
	elif p < m:
		m = m - p
		m = m // 3
		print(k + p + m)
	n = n - 1


rounds = int(input())
for i in range(rounds):
	len_arr = int(input())
	arr = input()
	num_arr = map(int, arr.split(' '))
	count = [0] * 3
	for elt in num_arr:
		count[elt % 3] += 1
	count = int(count[0] + min(count[1:])) + int(abs(count[2] - count[1]) // 3)
	print(count)


from math import *
a = int(input())
for i in range(a):
	z = int(input())
	k = list(map(int, input().split()))
	zz = [int(i) % 3 for i in k]
	print(zz.count(0) + min(zz.count(1), zz.count(2)) + floor(abs(zz.count(1) - zz.count(2)) / 3))


for _____ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {0: 0, 1: 0, 2: 0}
	for it in arr:
		d[it % 3] += 1
	(a, b, c) = (d[0], d[1], d[2])
	if b < c:
		ctx = a + b + (c - b) // 3
	elif c < b:
		ctx = a + c + (b - c) // 3
	else:
		ctx = a + b
	print(ctx)


t = int(input())
for _ in range(t):
	input()
	a = list(map(int, input().split()))
	count = [0] * 3
	for x in a:
		count[x % 3] += 1
	Min = min(count[1], count[2])
	count[1] -= Min
	count[2] -= Min
	print(count[0] + Min + count[1] // 3 + count[2] // 3)


ll = lambda : list(map(int, input().split()))
testcases = 1
testcases = int(input())
for testcase in range(testcases):
	[n] = ll()
	numbers = ll()
	(c1, c2) = (0, 0)
	c0 = 0
	for i in numbers:
		if i % 3 == 2:
			c2 += 1
		elif i % 3 == 1:
			c1 += 1
		else:
			c0 += 1
	ans = c0
	ans += min(c2, c1)
	x = min(c2, c1)
	c2 -= x
	c1 -= x
	if c1 <= 2 and c2 <= 2:
		print(ans)
	else:
		print(ans + (c1 + c2) // 3)


t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(lambda x: int(x) % 3, input().split()))
	res = a.count(0)
	a = list(filter(lambda x: x != 0, a))
	ones = a.count(1)
	twos = a.count(2)
	m = min(ones, twos)
	res += m
	res += (twos - m) // 3
	res += (ones - m) // 3
	print(res)


nTest = int(input())

def solution(l):
	dp = [0, 0, 0]
	for n in l:
		dp[n % 3] += 1
	return dp[0] + min(dp[1], dp[2]) + (dp[1] - min(dp[1], dp[2])) // 3 + (dp[2] - min(dp[1], dp[2])) // 3
for i in range(nTest):
	n = int(input())
	l = list(map(int, input().split()))
	print(solution(l))


n = int(input())
a = []
b = []
for i in range(n):
	m = int(input())
	a.append(m)
	c = list(map(int, input().split()))
	b.append(c)
for j in range(n):
	g = a[j]
	(r1, r2, r0) = (0, 0, 0)
	for k in range(g):
		if b[j][k] % 3 == 0:
			r0 = r0 + 1
		elif b[j][k] % 3 == 1:
			r1 = r1 + 1
		elif b[j][k] % 3 == 2:
			r2 = r2 + 1
	s = max(r1, r2)
	t = min(r1, r2)
	p = s - t
	p = int(p / 3)
	sumx = r0 + p + t
	print(sumx)


t = int(input())
for z in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(two, one) = (0, 0)
	for i in range(n):
		if a[i] % 3 == 0:
			one += 1
			two += 1
		elif a[i] % 3 == 2:
			two += 1
		else:
			one += 1
	if one >= two:
		print(two + (one - two) // 3)
	else:
		print(one + (two - one) // 3)


b = int(input())
for i in range(b):
	c = int(input())
	d = list(map(int, input().split()))
	x1 = [0, 0, 0]
	for j in d:
		x1[j % 3] = x1[j % 3] + 1
	s = x1[0] + min(x1[1], x1[2])
	if x1[1] > x1[2]:
		print(s + (x1[1] - x1[2]) // 3)
	else:
		print(s + (x1[2] - x1[1]) // 3)


q = int(input())
results = []
for i in range(q):
	n = int(input())
	arr = list(map(int, input().split()))
	mods = {}
	for element in arr:
		mods[element % 3] = mods.get(element % 3, 0) + 1
	result1 = mods.get(1, 0) // 3 + mods.get(2, 0) // 3 + min(mods.get(1, 0) % 3, mods.get(2, 0) % 3)
	mins = min(mods.get(1, 0), mods.get(2, 0))
	result2 = mins + (mods.get(1, 0) - mins) // 3 + (mods.get(2, 0) - mins) // 3
	result = mods.get(0, 0) + max(result1, result2)
	results.append(result)
print(*results, sep='\n')


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt0 = 0
	cnt1 = 0
	cnt2 = 0
	for i in a:
		if i % 3 == 0:
			cnt0 += 1
		elif i % 3 == 1:
			cnt1 += 1
		else:
			cnt2 += 1
	if cnt1 != 0 and cnt2 != 0:
		ans = cnt0 + min(cnt1, cnt2)
		if cnt1 >= cnt2:
			cnt1 = cnt1 - cnt2
			print(ans + cnt1 // 3)
		else:
			cnt2 = cnt2 - cnt1
			print(ans + cnt2 // 3)
	elif cnt1 != 0:
		print(cnt0 + cnt1 // 3)
	else:
		print(cnt0 + cnt2 // 3)


q = int(input())
for i in range(q):
	n = int(input())
	a = map(int, input().split())
	cnt = [0] * 3
	for x in a:
		cnt[x % 3] += 1
	ans = 0
	ans += cnt[0]
	d = min(cnt[1], cnt[2])
	ans += d
	ans += (cnt[1] - d) // 3
	ans += (cnt[2] - d) // 3
	print(ans)


m = int(input())
j = 0
while j < m:
	s = int(input())
	l = input()
	l = l.split(' ')
	mod1 = 0
	mod2 = 0
	mod3 = 0
	i = 0
	while i < s:
		r = int(l[i])
		if r % 3 == 0:
			mod3 += 1
		elif r % 3 == 1:
			mod1 += 1
		else:
			mod2 += 1
		i += 1
	min0 = min(mod1, mod2)
	mod3 += min0
	mod1 -= min0
	mod2 -= min0
	mod3 += mod1 // 3
	mod3 += mod2 // 3
	print(mod3)
	j += 1


t = int(input())
for i in range(t):
	n = int(input())
	v = [int(i) % 3 for i in input().split()]
	total = v.count(0)
	u = v.count(1)
	d = v.count(2)
	mais = min(u, d)
	d -= mais
	u -= mais
	total += mais
	if d % 3 == 0:
		total += d // 3
	elif d % 3 == 1 and d >= 1:
		total += (d - 1) // 3
	elif d % 3 == 2 and d >= 2:
		total += (d - 2) // 3
	if u % 3 == 0:
		total += u // 3
	elif u % 3 == 1 and u >= 1:
		total += (u - 1) // 3
	elif u % 3 == 2 and u >= 2:
		total += (u - 2) // 3
	print(total)


T = int(input())
for t in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	a = [i % 3 for i in a]
	ans = 0
	one = 0
	two = 0
	for i in a:
		if i == 0:
			ans += 1
		elif i == 1:
			one += 1
		else:
			two += 1
	if two < one:
		ans += two
		one -= two
		ans += one // 3
	else:
		ans += one
		two -= one
		ans += two // 3
	print(ans)


for _ in range(int(input())):
	a = input()
	div_3 = []
	div_2 = []
	div_1 = []
	lis = [x for x in map(int, input().split())]
	for j in lis:
		if j % 3 == 0:
			div_3.append(j)
		elif j % 3 == 2:
			div_1.append(j)
		else:
			div_2.append(j)
	total = len(div_3)
	temp1 = len(div_2)
	temp2 = len(div_1)
	b = min(temp1, temp2)
	temp1 = temp1 - b
	temp2 = temp2 - b
	total += b
	total = total + temp1 // 3 + temp2 // 3
	print(total)


t = int(input())
while t > 0:
	t -= 1
	c1 = 0
	c2 = 0
	c3 = 0
	ans = 0
	n = int(input())
	l = []
	s = input().split(' ')
	for i in range(n):
		l.append(int(s[i]))
	for i in range(n):
		if l[i] % 3 == 1:
			c1 += 1
		if l[i] % 3 == 2:
			c2 += 1
		if l[i] % 3 == 0:
			ans += 1
	if c1 == c2:
		ans += c2
	elif c1 > c2:
		c3 = c1 - c2
		ans += int(c3 / 3) + c2
	else:
		c3 = c2 - c1
		ans += int(c3 / 3) + c1
	print(ans)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	a = map(int, input().split())
	mods = map(lambda x: x % 3, a)
	c = Counter(mods)
	while c[1] > 0 and c[2] > 0:
		c[0] += 1
		c[1] -= 1
		c[2] -= 1
	while c[1] >= 3:
		c[0] += 1
		c[1] -= 3
	while c[2] >= 3:
		c[0] += 1
		c[2] -= 3
	print(c[0])


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(c, d, e) = (0, 0, 0)
	for i in a:
		if i % 3 == 0:
			c += 1
		elif i % 3 == 1:
			d += 1
		elif i % 3 == 2:
			e += 1
	while d > 0 and e > 0:
		d -= 1
		e -= 1
		c += 1
	while d >= 3:
		d -= 3
		c += 1
	while e >= 3:
		e -= 3
		c += 1
	print(c)


def solve(A, n):
	cnt = [0] * 3
	res = 0
	for i in range(n):
		cnt[A[i] % 3] += 1
	res += cnt[0]
	mn = min(cnt[1], cnt[2])
	res += mn
	cnt[1] -= mn
	cnt[2] -= mn
	res += (cnt[1] + cnt[2]) // 3
	return res
res = []
t = int(input())
while t:
	n = int(input())
	arr = input().split(' ')
	A = [int(n) for n in arr]
	res.append(solve(A, n))
	t -= 1
for r in res:
	print(r)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	a = [int(i) for i in a]
	b = [0, 0, 0]
	for i in a:
		b[i % 3] += 1
	ans = b[0]
	if b[1] > b[2]:
		ans += b[2]
		ans += (b[1] - b[2]) // 3
	else:
		ans += b[1]
		ans += (b[2] - b[1]) // 3
	print(ans)


n = int(input())
for i in range(0, n):
	o = int(input())
	l = []
	q = []
	w = []
	p = input().rstrip().split(' ')
	for j in range(0, len(p)):
		if int(p[j]) % 3 == 0:
			l.append(int(p[j]) % 3)
		elif int(p[j]) % 3 == 1:
			q.append(int(p[j]) % 3)
		elif int(p[j]) % 3 == 2:
			w.append(int(p[j]) % 3)
	c = min(len(q), len(w))
	for j in range(0, c):
		del q[0]
		del w[0]
	if len(q) != 0:
		print(len(l) + c + len(q) // 3)
	else:
		print(c + len(l) + len(w) // 3)


for _ in range(int(input())):
	input()
	s = list(map(int, input().split()))
	d = [0] * 3
	for n in s:
		d[n % 3] += 1
	l = d[0]
	k = min(d[1], d[2])
	l += k
	d[1] -= k
	d[2] -= k
	l += d[1] // 3
	l += d[2] // 3
	print(l)


from sys import stdin, stdout
read = lambda : map(int, stdin.readline().split())
I = lambda : stdin.readline()
alias = {2: 1, 3: 2, 5: 3}
for i in range(int(I())):
	(n, count) = (int(I()), [0, 0, 0])
	for i in read():
		count[i % 3] += 1
	(a, b, c) = count
	if b < c:
		c -= b
		a += b + c // 3
	else:
		b -= c
		a += c + b // 3
	print(a)


def merge(a):
	temp = [0, 0, 0]
	for i in a:
		temp[i % 3] += 1
	mn = min(temp[1], temp[2])
	mx = max(temp[1], temp[2])
	res = temp[0] + mn
	l = mx - mn
	res += l // 3
	print(res)
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	merge(a)


for _ in range(int(input())):
	n = int(input())
	br0 = br1 = br2 = 0
	a = [int(x) for x in input().split()]
	for el in a:
		if el % 3 == 0:
			br0 += 1
		elif el % 3 == 1:
			br1 += 1
		else:
			br2 += 1
	ans = br0 + min(br1, br2) + ((br2 - br1) // 3, (br1 - br2) // 3)[br1 > br2]
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().strip().split(' ')))
	x = [0 for _ in range(3)]
	for i in a:
		x[i % 3] += 1
	ans = 0
	ans += x[0]
	ans += min(x[1], x[2])
	if x[1] >= x[2]:
		x[1] -= x[2]
		ans += x[1] // 3
	elif x[2] > x[1]:
		x[2] -= x[1]
		ans += x[2] // 3
	print(ans)


import sys, collections
tc = int(sys.stdin.readline())
for _ in range(tc):
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	zero = 0
	one = 0
	two = 0
	for i in arr:
		if i % 3 == 0:
			zero += 1
		elif i % 3 == 1:
			one += 1
		else:
			two += 1
	temp = min(one, two)
	one -= temp
	two -= temp
	print(zero + temp + one // 3 + two // 3)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = [0, 0, 0]
	for i in a:
		if i % 3 == 0:
			l[0] = l[0] + 1
		elif i % 3 == 1:
			l[1] = l[1] + 1
		elif i % 3 == 2:
			l[2] = l[2] + 1
	ans = l[0] + min(l[1], l[2]) + (max(l[1], l[2]) - min(l[1], l[2])) // 3
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	see = map(int, input().split(' '))
	mods = [0, 0, 0]
	for i in see:
		mods[i % 3] += 1
	ans = min(mods[1], mods[2])
	mods[1] -= ans
	mods[2] -= ans
	print(ans + mods[0] + mods[2] // 3 + mods[1] // 3)
	t -= 1


for _ in range(int(input())):
	(n, a) = (int(input()), [0] * 3)
	l = list(map(int, input().split()))
	for i in range(n):
		a[l[i] % 3] += 1
	m = min(a[1], a[2])
	(a[1], a[2]) = ((a[1] - m) // 3, (a[2] - m) // 3)
	print(m + sum(a))


ii = lambda : int(input())
kk = lambda : map(int, input().split())
ll = lambda : list(kk())
for _ in range(ii()):
	(_, d) = (ii(), {0: 0, 1: 0, 2: 0})
	for i in kk():
		d[i % 3] += 1
	if d[1] > d[2]:
		(d[1], d[2]) = (d[2], d[1])
	print(d[0] + d[1] + (d[2] - d[1]) // 3)


from sys import stdin
from fractions import *
Input = []

def Out(x):
	stdout.write(str(x) + '\n')

def In():
	return stdin.readline().strip()

def inputGrab():
	for line in stdin:
		Input.extend(map(str, line.strip().split()))
inputIDX = 0

def hasNext():
	global inputIDX
	return inputIDX < len(Input)

def nextInt():
	global inputIDX
	inputIDX += 1
	return int(Input[inputIDX - 1])

def nextString():
	global inputIDX
	inputIDX += 1
	return Input[inputIDX - 1]

def main():
	t = nextInt()
	for __ in range(t):
		n = nextInt()
		a = 0
		b = 0
		c = 0
		for i in range(n):
			x = nextInt() % 3
			if x == 0:
				a += 1
			elif x == 1:
				b += 1
			else:
				c += 1
		tot = a + min(b, c)
		tot += max(0, (b - min(b, c)) // 3)
		tot += max(0, (c - min(b, c)) // 3)
		print(tot)
inputGrab()
main()


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections, re, itertools, statistics, math
from collections import *
from itertools import *
from statistics import *
from math import *
from re import *
mod = int(1000000000.0 + 7)
imin = -2147483648
imax = 2147483647
true = True
false = False
none = None
inp = lambda : input()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
L = lambda : list(M())
Yes = lambda : print('Yes')
No = lambda : print('No')
YES = lambda : print('YES')
NO = lambda : print('NO')

def IO(controll):
	if controll == false:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		pass

def true_yes(statement):
	return YES() if statement else NO()

def state(statement, one, two):
	print(one if statement else two)

def swap(a, b):
	(a, b) = (b, a)

def prec(a):
	return '{0:.7f}'.format(a)

def binary_search(arr, low, high, x):
	while low <= high:
		mid = low + (high - low) // 2
		if arr[mid] == x:
			return [mid, true]
		elif arr[mid] > x:
			high = mid - 1
		else:
			low = mid - 1
	return [-1, false]

def kabraji_ka_totka():
	IO(1)
	for i in range(I()):
		n = I()
		prefix = [0] * 3
		for i in L():
			prefix[i % 3] += 1
		print(prefix[0] + min(prefix[1], prefix[2]) + (max(prefix[1], prefix[2]) - min(prefix[1], prefix[2])) // 3)
kabraji_ka_totka()


t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	ones = 0
	twos = 0
	zeros = 0
	for i in range(n):
		if s[i] % 3 == 0:
			zeros += 1
		elif s[i] % 3 == 1:
			ones += 1
		else:
			twos += 1
	ans = zeros
	ou = min(twos, ones)
	ans += ou
	twos -= ou
	ones -= ou
	ans += twos // 3
	ans += ones // 3
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	ans = 0
	for i in l:
		if i % 3 == 1:
			count1 += 1
		if i % 3 == 2:
			count2 += 1
		if i % 3 == 0:
			ans += 1
	ans += min(count1, count2)
	val = min(count1, count2)
	count1 -= val
	count2 -= val
	ans += count1 // 3
	ans += count2 // 3
	print(ans)


from collections import defaultdict
t = int(input())
for i in range(t):
	d = defaultdict(int)
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		d[a[i] % 3] += 1
	ans = min(d[1], d[2])
	if d[1] > d[2]:
		ans += (d[1] - d[2]) // 3
	else:
		ans += (d[2] - d[1]) // 3
	print(ans + d[0])


import sys
import math
import bisect

def main():
	for _ in range(int(input())):
		n = int(input())
		A = list(map(int, input().split()))
		B = [0] * 3
		for a in A:
			B[a % 3] += 1
		max_val = 0
		tmp = min(B[1], B[2])
		for i in range(tmp + 1):
			val = B[0] + tmp + (B[1] - tmp) // 3 + (B[2] - tmp) // 3
			max_val = max(max_val, val)
		print(max_val)
main()


for i in range(int(input())):
	s = int(input())
	a = list(map(int, input().split()))
	t = [x % 3 for x in a]
	s0 = t.count(0)
	s1 = t.count(1)
	s2 = t.count(2)
	calc = min(s1, s2)
	s1 = s1 - calc
	s2 = s2 - calc
	tot = s0 + s1 // 3 + s2 // 3 + calc
	print(tot)


def fun(n, a):
	m = [0, 0, 0]
	for i in a:
		m[i % 3] += 1
	return m[0] + min(m[1], m[2]) + abs(m[1] - m[2]) // 3
n = int(input())
for i in range(n):
	print(fun(int(input()), list(map(int, input().split()))))


t = int(input())
for i in range(t):
	n = int(input())
	array = list(map(int, input().split()))
	r0 = 0
	r1 = 0
	r2 = 0
	for el in array:
		if el % 3 == 0:
			r0 += 1
		elif el % 3 == 1:
			r1 += 1
		else:
			r2 += 1
	count = r0 + min(r1, r2)
	if r1 > r2:
		count += (r1 - r2) // 3
	elif r2 > r1:
		count += (r2 - r1) // 3
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	(mod, mod1, mod2) = (0, 0, 0)
	ones = []
	twos = []
	for n in a:
		if n % 3 == 0:
			mod += 1
		elif n % 3 == 1:
			mod1 += 1
			ones.append(n)
		elif n % 3 == 2:
			mod2 += 1
			twos.append(n)
	ans1 = (len(ones) - min(mod1, mod2)) // 3
	ans2 = (len(twos) - min(mod1, mod2)) // 3
	mod += ans1
	mod += ans2
	print(mod + min(mod1, mod2))


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) % 3 for x in input().strip().split()]
	count = 0
	count1 = 0
	count2 = 0
	for i in range(n):
		if a[i] == 0:
			count += 1
		elif a[i] == 1:
			count1 += 1
		else:
			count2 += 1
	if count1 > count2:
		temp = (count1 - count2) // 3
	elif count2 > count1:
		temp = (count2 - count1) // 3
	else:
		temp = 0
	res = count + min(count1, count2) + temp
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	a = [int(x) % 3 for x in a]
	m = 0
	f = 0
	l = 0
	for x in a:
		if x == 0:
			m += 1
		elif x == 1:
			f += 1
		else:
			l += 1
	print(m + min(f, l) + int((max(f, l) - min(f, l)) / 3))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ar = [x % 3 for x in a]
	c0 = ar.count(0)
	c1 = ar.count(1)
	c2 = ar.count(2)
	print(c0 + abs(c1 - c2) // 3 + min(c1, c2))


for t in range(int(input())):
	n = int(input())
	arr = map(int, input().split())
	arr = list(map(lambda x: x % 3, arr))
	ans = 0
	(_0, _1, _2) = (arr.count(0), arr.count(1), arr.count(2))
	ans += _0
	a = min(_1, _2)
	_1 -= a
	_2 -= a
	ans += a
	ans += _1 // 3
	ans += _2 // 3
	print(ans)


a = int(input())
for __ in range(a):
	b = int(input())
	c = list(map(int, input().split()))
	m = []
	n = []
	k = 0
	for i in c:
		if i % 3 == 1:
			m.append(1)
		elif i % 3 == 2:
			n.append(2)
		else:
			k += 1
	k += min(len(m), len(n))
	k += abs(len(m) - len(n)) // 3
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	cnt = [0] * 3
	for i in range(3):
		cnt[i] = sum((1 for x in l if x % 3 == i))
	ans = cnt[0]
	if cnt[1] > cnt[2]:
		ans += cnt[2]
		cnt[1] -= cnt[2]
		cnt[2] = 0
	else:
		ans += cnt[1]
		cnt[2] -= cnt[1]
		cnt[1] = 0
	if cnt[2] != 0:
		ans += cnt[2] // 3
	elif cnt[1] != 0:
		ans += cnt[1] // 3
	print(ans)


for i in range(int(input())):
	n = int(input())
	d = [0, 0, 0]
	for i in map(int, input().split()):
		d[i % 3] += 1
		(mx, mn) = (max(d[1:]), min(d[1:]))
	print(d[0] + mn + (mx - mn) // 3)


def sol(arr, n):
	count = 0
	(a, b, c) = (0, 0, 0)
	for i in range(n):
		if arr[i] % 3 == 0:
			arr[i] = 3
			c = c + 1
		else:
			arr[i] = arr[i] % 3
			if arr[i] == 1:
				a = a + 1
			else:
				b = b + 1
	count = count + min(a, b) + c
	d = min(a, b)
	a = a - d
	b = b - d
	count = count + a // 3 + b // 3
	return count

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		a = list(map(int, input().split()))
		print(sol(a, n))
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	a = [0, 0, 0, 0]
	for v in arr:
		a[v % 3] += 1
	c = a[0]
	add = min(a[2], a[1])
	if a[2] > a[1]:
		a[2] -= add
		c += add + a[2] // 3
	elif a[1] > a[2]:
		a[1] -= add
		c += add + a[1] // 3
	else:
		c += a[1]
	print(c)


t = int(input())
for t1 in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m0 = 0
	m1 = 0
	m2 = 0
	for k in a:
		if k % 3 == 0:
			m0 += 1
		elif k % 3 == 1:
			m1 += 1
		else:
			m2 += 1
	if m1 >= m2:
		print(m0 + m2 + (m1 - m2) // 3)
	else:
		print(m0 + m1 + (m2 - m1) // 3)


from sys import stdin
import math
from collections import defaultdict, deque
import bisect
I = stdin.readline
t = int(I())
for _ in range(t):
	n = int(I())
	rem = [0 for i in range(3)]
	arr = [int(x) for x in I().split()]
	for i in arr:
		rem[i % 3] += 1
	ans = rem[0]
	x = min(rem[1], rem[2])
	ans += x
	rem[1] -= x
	rem[2] -= x
	ans += rem[1] // 3
	ans += rem[2] // 3
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	zero = 0
	one = 0
	two = 0
	for i in range(n):
		if a[i] % 3 == 0:
			zero += 1
		if a[i] % 3 == 1:
			one += 1
		if a[i] % 3 == 2:
			two += 1
	ans = zero
	ans += min(one, two)
	if one > two:
		one -= two
		ans += one // 3
	else:
		two -= one
		ans += two // 3
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt1 = 0
	cnt2 = 0
	cnt3 = 0
	for i in a:
		if i % 3 == 0:
			cnt3 += 1
		if i % 3 == 1:
			cnt1 += 1
		if i % 3 == 2:
			cnt2 += 1
	ans = cnt3 + min(cnt2, cnt1)
	if cnt2 >= cnt1:
		cnt2 = cnt2 - cnt1
		cnt1 = 0
	else:
		cnt1 = cnt1 - cnt2
		cnt2 = 0
	if cnt2 > 0:
		ans += cnt2 // 3
	if cnt1 > 0:
		ans += cnt1 // 3
	print(ans)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	n = int(input())
	a = int_array()
	ans = 0
	ones = twos = 0
	for i in range(n):
		if a[i] % 3 == 0:
			ans += 1
		elif a[i] % 3 == 1:
			ones += 1
		else:
			twos += 1
	pairs = min(ones, twos)
	ans += pairs
	ones -= pairs
	twos -= pairs
	ans += ones // 3 + twos // 3
	print(ans)


def sum_of(n):
	s = 0
	num = n
	while num > 0:
		s += num % 10
		num = num // 10
	return s
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x_0 = 0
	x_1 = 0
	x_2 = 0
	for i in range(n):
		temp = sum_of(l[i])
		if temp % 3 == 0:
			x_0 += 1
		elif (temp - 1) % 3 == 0:
			x_1 += 1
		else:
			x_2 += 1
	temp = min(x_1, x_2)
	count = x_0 + temp
	x_1 -= temp
	x_2 -= temp
	count += x_1 // 3
	count += x_2 // 3
	print(count)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	n = int(input())
	arr = list_input()
	num = 0
	occur = {1: 0, 2: 0}
	for i in arr:
		if i % 3 == 0:
			num += 1
		else:
			x = i % 3
			occur[x] += 1
	num += min(occur[1], occur[2])
	if occur[1] < occur[2]:
		occur[2] -= occur[1]
		num += occur[2] // 3
	else:
		occur[1] -= occur[2]
		num += occur[1] // 3
	print(num)
t = 1
t = int(input())
for _ in range(t):
	solve()


def get(a):
	b = [0] * 3
	for ai in a:
		b[ai % 3] += 1
	x = min(b[1], b[2])
	b[0] += x
	b[1] -= x
	b[2] -= x
	return b[0] + b[1] // 3 + b[2] // 3
aa = []
t = int(input())
for _ in range(t):
	n = int(input())
	a = map(int, input().split())
	aa.append(a)
for a in aa:
	print(get(a))


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	dict = {}
	for i in range(3):
		dict[i] = 0
	for i in range(n):
		dict[a[i] % 3] += 1
	ans = dict[0]
	x = min(dict[1], dict[2])
	ans += x
	dict[1] -= x
	dict[2] -= x
	ans += dict[1] // 3
	ans += dict[2] // 3
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = input().split()
	for j in range(n):
		l[j] = int(l[j]) % 3
	print(l.count(0) + (min(l.count(1), l.count(2)) + l.count(1) + l.count(2)) // 3)


for _ in range(int(input().strip())):
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	(c0, c1, c2) = (0, 0, 0)
	for i in range(n):
		arr[i] %= 3
		if arr[i] == 0:
			c0 += 1
		elif arr[i] == 1:
			c1 += 1
		else:
			c2 += 1
	total = c0 + min(c1, c2) + (max(c1, c2) - min(c1, c2)) // 3
	print(total)


class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L
c = cinn()
n = c.cin()
for i in range(n):
	q = c.cin()
	L = c.clist(q)
	dic = {}
	dic[0] = 0
	dic[1] = 0
	dic[2] = 0
	tot = 0
	for el in L:
		dic[el % 3] += 1
	tot += dic[0] + min(dic[1], dic[2]) + (max(dic[1], dic[2]) - min(dic[1], dic[2])) // 3
	print(tot)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	t = 0
	p = 0
	q = 0
	b = []
	for i in a:
		if i % 3 == 0:
			t += 1
		elif i % 3 == 1:
			p = p + 1
		elif i % 3 == 2:
			q = q + 1
	if p > q:
		t = t + q
		p = p - q
		t = t + p // 3
	else:
		t = t + p
		q = q - p
		t = t + q // 3
	print(t)


import sys
input = sys.stdin.readline
from collections import *
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = [0] * 3
	for ai in a:
		cnt[ai % 3] += 1
	m = min(cnt[1], cnt[2])
	print(cnt[0] + m + (cnt[1] - m) // 3 + (cnt[2] - m) // 3)


x = int(input())
for k in range(x):
	n = int(input())
	cont = 0
	s = []
	for j in map(int, input().split()):
		if j % 3 == 0:
			cont += 1
		else:
			s += [j % 3]
	a = s.count(1)
	b = s.count(2)
	cont += min(a, b)
	if a > b:
		a -= b
		cont += a // 3
	elif b > a:
		b -= a
		cont += b // 3
	print(cont)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	z = []
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
			z.append(x)
	return [d, z]

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = list(In())
		ans = 0
		temp = []
		for x in range(n):
			if l[x] % 3 == 0:
				ans += 1
			else:
				temp.append(l[x])
		while len(temp) > 1:
			q = 0
			for i in range(1, len(temp)):
				if (temp[0] + temp[i]) % 3 == 0:
					q = 1
					break
			if q == 1:
				temp.pop(i)
				temp.pop(0)
				ans += 1
			else:
				te = temp.pop(0)
				te += temp.pop(0)
				temp.insert(0, te)
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


t = int(input())
for a in range(t):
	n = int(input())
	arr = input().split(' ')
	arr = [int(b) for b in arr]
	mod = [0, 0, 0]
	for val in arr:
		mod[val % 3] += 1
	avail = min(mod[1], mod[2])
	mod[0] += avail
	mod[1] -= avail
	mod[2] -= avail
	if mod[1] == 0:
		amt = mod[2] // 3
		mod[0] += amt
	elif mod[2] == 0:
		amt = mod[1] // 3
		mod[0] += amt
	print(mod[0])


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import PriorityQueue as pq
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	x = dc(int)
	for i in l:
		x[i % 3] += 1
	t = min(x[2], x[1])
	x[1] -= t
	x[2] -= t
	print(x[0] + t + x[1] // 3 + x[2] // 3)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(lambda x: x % 3, map(int, input().split())))
	x = arr.count(0)
	x += min(arr.count(1), arr.count(2))
	x += (max(arr.count(1), arr.count(2)) - min(arr.count(1), arr.count(2))) // 3
	print(x)


n = int(input())
for i in range(n):
	k = int(input())
	a = input().split()
	t0 = 0
	t1 = 0
	t2 = 0
	for j in range(k):
		a[j] = int(a[j])
		if a[j] % 3 == 0:
			t0 += 1
		if a[j] % 3 == 1:
			t1 += 1
		if a[j] % 3 == 2:
			t2 += 1
	x = t1
	if t2 < x:
		x = t2
	t1 -= x
	t2 -= x
	print(t0 + x + t1 // 3 + t2 // 3)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	o = 0
	tw = 0
	for j in a:
		k = j % 3
		if k == 0:
			c += 1
		elif k == 1:
			o += 1
		else:
			tw += 1
	miotw = min(o, tw)
	print(c + min(o, tw) + (o - miotw) // 3 + (tw - miotw) // 3)


t = int(input())
for _ in range(t):
	n = int(input())
	l = [int(x) for x in input().split()]
	max_len = []
	count = 0
	for i in l:
		if i % 3 == 0:
			count += 1
	i = 0
	while i < len(l):
		if l[i] % 3 == 0:
			del l[i]
		else:
			i += 1
	max_len.append(count)
	count = 0
	while len(l) != 1:
		for i in range(len(l) - 1):
			for j in range(i + 1, len(l)):
				if (l[i] + l[j]) % 3 == 0 and l[i] != 0 and (l[j] != 0):
					count += 1
					l[i] = 0
					l[j] = 0
		i = 0
		while i < len(l):
			if l[i] == 0:
				del l[i]
			else:
				i += 1
		if len(l) < 2:
			break
		else:
			l.append(l[0] + l[1])
			del l[0]
			del l[1]
	max_len.append(count)
	print(sum(max_len))


import math
t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * 3
	for i in range(n):
		if a[i] % 3 == 0:
			b[0] += 1
		elif a[i] % 3 == 1:
			b[1] += 1
		elif a[i] % 3 == 2:
			b[2] += 1
	print(b[0] + min(b[1], b[2]) + abs(b[1] - b[2]) // 3)


for _ in range(int(input())):
	n = int(input())
	ndb3 = 0
	a = [int(i) for i in input().split()]
	r0 = 0
	r1 = 0
	r2 = 0
	for i in range(n):
		if a[i] % 3 == 0:
			r0 += 1
		elif a[i] % 3 == 1:
			r1 += 1
		else:
			r2 += 1
	ndb3 = r0
	if r1 > r2:
		ndb3 += r2
		r1 = r1 - r2
		r2 = 0
		ndb3 += r1 // 3
	else:
		ndb3 += r1
		r2 = r2 - r1
		r1 = 0
		ndb3 += r2 // 3
	print(ndb3)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	c0 = 0
	for i in l:
		if i % 3 == 0:
			c0 += 1
		if i % 3 == 1:
			c1 += 1
		if i % 3 == 2:
			c2 += 1
	mini = min(c1, c2)
	maxi = max(c1, c2)
	c0 += mini
	maxi = maxi - mini
	c0 += maxi // 3
	print(c0)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	r1 = 0
	r2 = 0
	r3 = 0
	for j in range(n):
		if a[j] % 3 == 0:
			r1 += 1
		elif a[j] % 3 == 1:
			r2 += 1
		else:
			r3 += 1
	x = min(r2, r3)
	r2 = (r2 - x) // 3
	r3 = (r3 - x) // 3
	print(r1 + x + r2 + r3)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	tot = 0
	tot = b = c = 0
	for i in a:
		if i % 3 == 0:
			tot += 1
		elif i % 3 == 1:
			b += 1
		else:
			c += 1
	k = min(b, c)
	tot += k
	b -= k
	c -= k
	tot += b // 3
	tot += c // 3
	print(tot)


from math import floor
q = int(input())
for i in range(q):
	n = int(input())
	list = map(int, input().split())
	m_0 = 0
	m_1 = 0
	m_2 = 0
	for a in list:
		if a % 3 == 0:
			m_0 += 1
		elif a % 3 == 1:
			m_1 += 1
		else:
			m_2 += 1
	if m_1 == m_2:
		print(m_1 + m_0)
	elif m_1 > m_2:
		print(m_0 + m_2 + floor((m_1 - m_2) / 3))
	else:
		print(m_0 + m_1 + floor((m_2 - m_1) / 3))


for _ in range(int(input())):
	n = int(input())
	L = [int(x) % 3 for x in input().split()]
	X = [0, 0, 0]
	for x in L:
		if x == 0:
			X[0] += 1
		elif x == 1:
			X[1] += 1
		else:
			X[2] += 1
	if X[1] == X[2]:
		print(X[0] + X[1])
	elif X[1] > X[2]:
		print(X[0] + X[2] + (X[1] - X[2]) // 3)
	else:
		print(X[0] + X[1] + (X[2] - X[1]) // 3)


m = int(input())
for i in range(m):
	n = int(input())
	a = sorted(list(map(int, input().split())))
	(j, k) = (0, 0)
	count = 0
	for i in a:
		if i % 3 == 0:
			count = count + 1
		elif i % 3 == 1:
			j = j + 1
		else:
			k = k + 1
	count = count + min(j, k)
	count = count + abs(j - k) // 3
	print(count)


for i in range(int(input())):
	a = int(input())
	t = list(map(int, input().split()))
	for k in range(a):
		t[k] = t[k] % 3
	p = t.count(0)
	f = [t.count(1), t.count(2)]
	if f[0] > f[1]:
		print(p + f[1] + (f[0] - f[1]) // 3)
	else:
		print(p + f[0] + (f[1] - f[0]) // 3)


def main():
	answer = ''
	for i in range(int(input())):
		n = int(input())
		nums = list(map(int, input().split(' ')))
		new_nums = []
		for i in nums:
			new_nums.append(i % 3)
		counts = [0, 0, 0]
		for i in new_nums:
			counts[i] += 1
		ans = counts[0] + min(counts[1], counts[2]) + (max(counts[1], counts[2]) - min(counts[1], counts[2])) // 3
		answer += str(ans) + '\n'
	print(answer)
main()


n = int(input())
for i in range(n):
	m = int(input())
	t = input()
	t = t.split(' ')
	for j in range(m):
		t[j] = int(t[j])
	l = t
	count1 = 0
	count2 = 0
	count0 = 0
	for j in range(m):
		l[j] = l[j] % 3
		if l[j] == 1:
			count1 += 1
		elif l[j] == 2:
			count2 += 1
		elif l[j] == 0:
			count0 += 1
	if count1 >= count2:
		n = count0 + count2 + int((count1 - count2) / 3)
	else:
		n = count0 + count1 + int((count2 - count1) / 3)
	print(n)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	mod0 = mod1 = mod2 = 0
	for i in a:
		if i % 3 == 0:
			mod0 += 1
		elif i % 3 == 1:
			mod1 += 1
		else:
			mod2 += 1
	if mod1 == mod2:
		mod0 += mod1
	elif mod1 > mod2:
		mod1 -= mod2
		mod0 += mod2
		mod0 += mod1 // 3
	else:
		mod2 -= mod1
		mod0 += mod1
		mod0 += mod2 // 3
	print(mod0)


test_cases = int(input())
while test_cases > 0:
	num = input()
	data = list(map(int, input().split()))
	divisible = [0, 0, 0]
	for element in data:
		divisible[element % 3] += 1
	toPrint = divisible[0]
	if divisible[1] >= divisible[2]:
		toPrint += divisible[2]
		divisible[1] -= divisible[2]
		toPrint += divisible[1] // 3
	else:
		toPrint += divisible[1]
		divisible[2] -= divisible[1]
		toPrint += divisible[2] // 3
	print(toPrint)
	test_cases -= 1


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	c = Counter((int(x) % 3 for x in input().split()))
	(x, y) = (min(c[1], c[2]), max(c[1], c[2]))
	r = c[0] + x + (y - x) // 3
	print(r)


for i in range(int(input())):
	n = int(input())
	c = [0] * 3
	for i in map(int, input().split()):
		c[i % 3] += 1
	(x, y) = (min(c[1], c[2]), max(c[1], c[2]))
	print(c[0] + x + (y - x) // 3)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	occ = [0, 0, 0]
	for ai in a:
		occ[ai % 3] += 1
	ans = min(occ[1], occ[2])
	occ[1] -= ans
	occ[2] -= ans
	ans += occ[0]
	ans += occ[1] // 3
	ans += occ[2] // 3
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	(ct0, ct1, ct2) = (0, 0, 0)
	for i in map(int, input().split()):
		if i % 3 == 0:
			ct0 += 1
		if i % 3 == 1:
			ct1 += 1
		if i % 3 == 2:
			ct2 += 1
	x = min(ct1, ct2)
	ct0 += x
	(ct1, ct2) = (ct1 - x, ct2 - x)
	ct0 += ct1 // 3
	ct0 += ct2 // 3
	print(ct0)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = b = c = int(0)
	x = list(map(int, input().split()))
	for i in range(n):
		if x[i] % 3 == 0:
			a += 1
		elif x[i] % 3 == 1:
			b += 1
		else:
			c += 1
	if b >= c:
		a += (b - c) // 3 + c
	else:
		a += (c - b) // 3 + b
	print(a)


q = int(input())
for i in range(q):
	N = int(input())
	a = [int(i) % 3 for i in input().split(' ')]
	one = a.count(1)
	two = a.count(2)
	ans = min(one, two)
	one -= ans
	two -= ans
	ans += one // 3
	ans += two // 3
	print(ans + a.count(0))


t = int(input())
i = 1
while i <= t:
	i += 1
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	m1 = 0
	m2 = 0
	for j in a:
		if j % 3 == 2:
			m2 += 1
		elif j % 3 == 1:
			m1 += 1
		else:
			count += 1
	count = count + min(m2, m1)
	if m2 < m1:
		m1 = m1 - m2
		m1 = m1 // 3
		count += m1
	elif m2 > m1:
		m2 = m2 - m1
		m2 = m2 // 3
		count += m2
	print(count)


for q in range(int(input())):
	junk = input()
	data = [0, 0, 0]
	for i in input().split():
		data[int(i) % 3] += 1
	ans = data[0]
	if data[1] > data[2]:
		ans += data[2]
		ans += (data[1] - data[2]) // 3
	else:
		ans += data[1]
		ans += (data[2] - data[1]) // 3
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	store = [0, 0, 0]
	for j in a:
		store[j % 3] += 1
	mi = min(store[1], store[2])
	store[1] -= mi
	store[2] -= mi
	print(store[0] + mi + (store[1] + store[2]) // 3)


for _ in range(int(input())):
	N = int(input())
	A = [int(x) for x in input().split()]
	(x, cnt, L) = (0, 0, [])
	for i in A:
		if i % 3 == 0:
			x += 1
		else:
			L.append(i)
	for i in range(len(L)):
		L[i] = L[i] % 3
	(one, two) = (0, 0)
	for i in L:
		if i == 1:
			one += 1
		else:
			two += 1
	if one > two:
		x += two + (one - two) // 3
	else:
		x += one + (two - one) // 3
	print(x)


a = int(input())
while a != 0:
	t = int(input())
	arr = [int(x) for x in input().split()]
	cnt1 = 0
	cnt2 = 0
	cnt = 0
	ex1 = 0
	ex2 = 0
	xx1 = 0
	xx2 = 0
	total = 0
	for (val, i) in enumerate(arr, start=0):
		if i % 3 == 0:
			cnt += 1
		elif i % 3 == 1:
			cnt1 += 1
		else:
			cnt2 += 1
	while cnt2 != 0 and cnt1 != 0:
		cnt2 -= 1
		cnt1 -= 1
		cnt += 1
	if cnt1 % 3 == 0:
		xx1 = cnt1 / 3
	else:
		xx1 = cnt1 / 3
		xx1 = int(xx1)
	if cnt2 % 3 == 0:
		xx2 = cnt2 / 3
	else:
		xx2 = cnt2 / 3
		xx2 = int(xx2)
	total = cnt + xx1 + xx2
	total = int(total)
	print(total)
	a -= 1


q = int(input())
for z in range(q):
	n = int(input())
	array = list(map(int, input().split()))
	mod_0 = 0
	mod_1 = 0
	mod_2 = 0
	output = 0
	for x in array:
		if x % 3 == 0:
			mod_0 += 1
		if x % 3 == 1:
			mod_1 += 1
		if x % 3 == 2:
			mod_2 += 1
	min_of_mod = min(mod_1, mod_2)
	output += mod_0
	output += min(mod_1, mod_2)
	mod_1 -= min_of_mod
	mod_2 -= min_of_mod
	output += (mod_1 + mod_2) // 3
	print(output)


import math
cases = int(input())
for i in range(0, cases):
	l = int(input())
	ln = [int(j) for j in input().split(' ')]
	ms = [0, 0, 0]
	for j in range(0, len(ln)):
		ms[ln[j] % 3] += 1
	s = ms[0] + min(ms[1], ms[2]) + math.floor((max(ms[1], ms[2]) - min(ms[1], ms[2])) / 3)
	print(s)


kol = [0, 0, 0]
t = int(input())
for j in range(t):
	input()
	a = [int(i) for i in input().split()]
	for i in range(len(a)):
		kol[a[i] % 3] += 1
	print(kol[0] + min(kol[1], kol[2]) + abs(kol[1] - kol[2]) // 3)
	kol = [0, 0, 0]


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	rem = [A[i] % 3 for i in range(n)]
	ans = rem.count(0)
	a = rem.count(1)
	b = rem.count(2)
	if a <= b:
		ans += a
		b -= a
		ans += b // 3
	else:
		ans += b
		a -= b
		ans += a // 3
	print(ans)


import sys
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
readl = lambda : list(map(int, sys.stdin.readline().split()))
readt = lambda : tuple(map(int, sys.stdin.readline().split()))
read = lambda : sys.stdin.readline().rstrip()
readi = lambda : int(read())
readmi = lambda : map(int, sys.stdin.readline().split())
readms = lambda : map(str, sys.stdin.readline().split())
t = readi()
for i in range(t):
	n = readi()
	p = readl()
	one = 0
	two = 0
	zero = 0
	for i in range(n):
		if p[i] % 3 == 0:
			zero += 1
		elif p[i] % 3 == 1:
			one += 1
		elif p[i] % 3 == 2:
			two += 1
	ans = zero
	m = min(one, two)
	one -= m
	two -= m
	ans += m
	ans += one // 3
	ans += two // 3
	print(ans)


def fun(y):
	n = int(input())
	num = [int(x) for x in input().split()]
	l = len(num)
	s[y] = 0
	for i in range(0, l):
		num[i] = num[i] % 3
	t0 = num.count(0)
	t1 = num.count(1)
	t2 = num.count(2)
	mi = min(t1, t2)
	ma = max(t1, t2)
	q = int((ma - mi) / 3)
	for j in range(0, l):
		s[y] = s[y] + num[j]
	m[y] = t0 + mi + q
n = int(input())
s = [0] * n
m = [0] * n
for y in range(0, n):
	fun(y)
for k in range(0, n):
	print(m[k])


for _ in range(int(input())):
	n = int(input())
	l = [int(i) for i in input().split()]
	cnt = [0] * 3
	for i in l:
		cnt[i % 3] += 1
	ans = cnt[0]
	curr = min(cnt[1], cnt[2])
	cnt[1] -= curr
	cnt[2] -= curr
	ans += curr
	ans += cnt[1] // 3
	ans += cnt[2] // 3
	print(ans)


t = int(input())
for a in range(t):
	no = int(input())
	arr = list(map(int, input().split()))
	ca = 0
	cb = 0
	count = 0
	for elm in arr:
		x = elm % 3
		if not x:
			count = count + 1
		elif x == 1:
			ca = ca + 1
		else:
			cb = cb + 1
	if ca > cb:
		count = count + cb + (ca - cb) // 3
	elif cb > ca:
		count = count + ca + (cb - ca) // 3
	else:
		count = count + ca
	print(count)


n = int(input())
for _ in range(n):
	k = int(input())
	m = [0, 0, 0]
	l = list(map(int, input().split(' ')))
	for i in l:
		m[i % 3] += 1
	res = m[0]
	s = min(m[1], m[2])
	res += s
	ans = (m[1] + m[2] - s - s) // 3
	print(res + ans)


for _ in range(int(input())):
	n = int(input())
	b = []
	k = 0
	a = list(map(int, input().split()))
	for i in range(n):
		if a[i] % 3 != 0:
			b.append(a[i] % 3)
		else:
			k += 1
	s = b.count(1)
	t = b.count(2)
	k = k + min(s, t)
	y = abs(s - t)
	p = y // 3
	k = k + p
	print(k)


for i in range(int(input())):
	x = int(input())
	y = [int(i) for i in input().split()]
	a = 0
	b = 0
	c = 0
	for i in range(x):
		if y[i] % 3 != 0:
			if y[i] % 3 == 2:
				a += 1
			else:
				b += 1
			y[i] = y[i] % 3
		else:
			y[i] = 3
			c += 1
	y.sort()
	z = min(a, b) + c + (a - min(a, b)) // 3 + (b - min(a, b)) // 3
	print(z)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = [i % 3 for i in l]
	s1 = s.count(1)
	s2 = s.count(2)
	ans = min(s1, s2)
	s1 -= ans
	s2 -= ans
	if s1 == 0:
		ans += s2 // 3
	elif s2 == 0:
		ans += s1 // 3
	print(ans + s.count(0))


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	r = [0] * 3
	for i in a:
		r[i % 3] += 1
	cnt = r[0]
	(r1, r2) = tuple(r[1:])
	if r1 > r2:
		(r1, r2) = (r2, r1)
	cnt += r1
	cnt += (r2 - r1) // 3
	print(cnt)


def f():
	input()
	a = [0] * 3
	for i in map(int, input().split()):
		a[i % 3] += 1
	x = min(a[1:])
	print(a[0] + x + (a[1] + a[2] - 2 * x) // 3)
for i in range(int(input())):
	f()


n = int(input())
res = []
for i in range(n):
	count = 0
	mod1 = 0
	mod2 = 0
	t = int(input())
	a = list(map(int, input().split()))
	for elem in a:
		if elem % 3 == 0:
			count += 1
		elif elem % 3 == 1:
			mod1 += 1
		else:
			mod2 += 1
	if mod1 > mod2:
		count += mod2
		mod1 -= mod2
		count += mod1 // 3
	else:
		count += mod1
		mod2 -= mod1
		count += mod2 // 3
	res.append(count)
for r in res:
	print(r)


for _ in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	c_arr = [0, 0, 0]
	for i in arr:
		c_arr[i % 3] += 1
	ans = c_arr[0]
	temp = min(c_arr[1:])
	ans += temp
	ans += ((c_arr[1] if c_arr[1] > c_arr[2] else c_arr[2]) - temp) // 3
	print(ans)


t_num = int(input().strip())
for t in range(t_num):
	n = int(input().strip())
	nums = list(map(int, input().strip().split()))
	counts = [0, 0, 0]
	for num in nums:
		counts[num % 3] += 1
	res = counts[0]
	if counts[1] > counts[2]:
		res += counts[2]
		res += (counts[1] - counts[2]) // 3
	else:
		res += counts[1]
		res += (counts[2] - counts[1]) // 3
	print(res)


numeroCasos = int(input())
for i in range(numeroCasos):
	n = int(input())
	lista = [int(x) for x in input().split()]
	resto1 = 0
	resto2 = 0
	contador = 0
	for i in range(len(lista)):
		resto = lista[i] % 3
		if resto == 0:
			contador += 1
		elif resto == 1:
			resto1 += 1
		elif resto == 2:
			resto2 += 1
	diferenca = min(resto1, resto2)
	contador += diferenca
	resto1 = resto1 - diferenca
	resto2 = resto2 - diferenca
	contador += resto1 // 3
	contador += resto2 // 3
	print(contador)


from collections import Counter
import io
import os
import sys
from atexit import register
import random
import math
import itertools
DEBUG = True
DEBUG = False
STRESSTEST = False
if not DEBUG:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
sys.stdout = io.BytesIO()
register(lambda : os.write(1, sys.stdout.getvalue()))
tokens = []
tokens_next = 0

def nextStr():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = input().split()
		tokens_next = 0
	tokens_next += 1
	if type(tokens[tokens_next - 1]) == str:
		return tokens[tokens_next - 1]
	return tokens[tokens_next - 1].decode()

def nextInt():
	return int(nextStr())

def nextIntArr(n):
	return [nextInt() for i in range(n)]

def print(*argv, end='\n'):
	for arg in argv:
		sys.stdout.write((str(arg) + ' ').encode())
	sys.stdout.write(end.encode())

def genTestCase():
	raise NotImplementedError

def bruteforce(a):
	raise NotImplementedError

def doStressTest():
	while True:
		curTest = genTestCase()
		mySoln = solve(curTest)
		bruteforceSoln = bruteforce(curTest)
		if mySoln != bruteforceSoln:
			print('### Found case ###')
			print(curTest)
			print(f'{mySoln} should have been: {bruteforceSoln}')
			return

def solve(a):
	c = Counter()
	for i in a:
		c[i % 3] += 1
	res = min(c[1], c[2])
	c[1] -= res
	c[2] -= res
	res += c[1] // 3
	res += c[2] // 3
	res += c[0]
	return res
if not DEBUG and STRESSTEST:
	raise Exception('Wrong flags!')
if STRESSTEST:
	doStressTest()
else:
	t = nextInt()
	for _ in range(t):
		a = nextIntArr(nextInt())
		res = solve(a)
		print(res)
sys.stdout.flush()


n = int(input())
for i in range(n):
	x = int(input())
	nums = list(map(int, input().split()))
	nums = list(map(lambda x: x % 3, nums))
	qtd0 = nums.count(0)
	qtd1 = nums.count(1)
	qtd2 = nums.count(2)
	if qtd1 == qtd2:
		qtd0 += qtd1
	elif qtd2 > qtd1:
		qtd0 += qtd1
		qtd2 -= qtd1
		qtd0 += qtd2 // 3
	else:
		qtd0 += qtd2
		qtd1 -= qtd2
		qtd0 += qtd1 // 3
	print(qtd0)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	x = 0
	y = 0
	z = 0
	for i in range(0, n):
		if a[i] % 3 == 0:
			x += 1
		elif a[i] % 3 == 1:
			y += 1
		else:
			z += 1
	if y <= z:
		print(x + y + (z - y) // 3)
	else:
		print(x + z + (y - z) // 3)


n = int(input())
for i in range(n):
	x = int(input())
	l = list(map(int, input().rstrip().split()))
	v1 = 0
	v2 = 0
	v3 = 0
	for j in l:
		if j % 3 == 1:
			v1 += 1
		elif j % 3 == 2:
			v2 += 1
		else:
			v3 += 1
	print(v3 + min(v1, v2) + int((max(v1, v2) - min(v1, v2)) / 3.0))


t = int(input())
for _ in range(t):
	n = int(input())
	nums = [int(x) % 3 for x in input().split(' ') if x]
	diff_remainder_pair_count = min(nums.count(1), nums.count(2))
	count_1 = nums.count(1) - diff_remainder_pair_count
	count_2 = nums.count(2) - diff_remainder_pair_count
	print(nums.count(0) + diff_remainder_pair_count + count_1 // 3 + count_2 // 3)


n = int(input())
for i in range(n):
	t = int(input())
	a = [int(k) % 3 for k in input().split()]
	(d, b, c) = (0, 0, 0)
	for j in range(len(a)):
		if a[j] == 0:
			d += 1
		if a[j] == 1:
			b += 1
		if a[j] == 2:
			c += 1
	f = min(b, c)
	print(f + d + (b - f) // 3 + (c - f) // 3)


def mer(x):
	c0 = 0
	c1 = 0
	c2 = 0
	for el in range(len(x)):
		x[el] = x[el] % 3
		if x[el] % 3 == 0:
			c0 += 1
		if x[el] % 3 == 1:
			c1 += 1
		if x[el] % 3 == 2:
			c2 += 1
	return c0 + min(c1, c2) + (c2 - min(c1, c2)) // 3 + (c1 - min(c1, c2)) // 3
q = int(input())
l = []
for i in range(q):
	n = int(input())
	l.append([])
	inp = input().split()
	for j in range(n):
		l[i].append(int(inp[j]))
for el in l:
	print(mer(el))


t = int(input())
for i in range(t):
	n = int(input())
	tr = 0
	m = 0
	o = 0
	a = list(map(int, input().split()))
	for j in range(n):
		if a[j] % 3 == 0:
			tr = tr + 1
		elif a[j] % 3 == 1:
			o = o + 1
		elif a[j] % 3 == 2:
			m = m + 1
	tr = tr + min(o, m)
	tr = tr + (max(o, m) - min(o, m)) // 3
	print(tr)


t = int(input())
for i in range(t):
	n = int(input())
	d = 0
	e = 0
	a = list(map(int, input().split()))
	c = 0
	for j in a:
		if j % 3 == 0:
			c += 1
	for j in a:
		if (j + 2) % 3 == 0:
			d += 1
	for j in a:
		if (j + 1) % 3 == 0:
			e += 1
	x = d - min(d, e)
	y = e - min(d, e)
	print(c + min(d, e) + (x + y) // 3)


def inputSeperator(inputStr):
	return list(map(int, inputStr.split(' ')))
queries = int(input())
for i in range(queries):
	result = 0
	n = int(input())
	myList = inputSeperator(input())
	modulo = [i % 3 for i in myList]
	result += modulo.count(0)
	result += min(modulo.count(1), modulo.count(2))
	result += abs(modulo.count(1) - modulo.count(2)) // 3
	print(result)


def ii(t):
	if t == 0:
		return list(map(int, input().split()))
	elif t == 1:
		return int(input())
	elif t == 2:
		return input()
p = ii(1)
for pppp in range(p):
	t = ii(1)
	q = ii(0)
	at = []
	pt = []
	for i in range(t):
		if q[i] % 3 == 0:
			at.append(q[i])
		else:
			pt.append(q[i] % 3)
	count = len(at)
	jt = len(pt)
	ar = pt.count(1)
	pr = pt.count(2)
	if ar == pr:
		count = count + ar
		ar = 0
		pr = 0
	elif ar < pr:
		count = count + ar
		pr = pr - ar
		count = count + pr // 3
	elif ar > pr:
		count = count + pr
		ar = ar - pr
		s = 1 * ar
		count = count + ar // 3
	print(count)


t = int(input())
for i in range(t):
	ost_0 = 0
	ost_1 = 0
	ost_2 = 0
	n = int(input())
	array = list(map(int, input().split()))
	ar = array
	for elem in ar:
		if elem % 3 == 1:
			ost_1 += 1
		elif elem % 3 == 2:
			ost_2 += 1
		else:
			ost_0 += 1
	n = min(ost_2, ost_1) + ost_0
	if ost_1 > ost_2:
		n += (ost_1 - ost_2) // 3
	elif ost_2 > ost_1:
		n += (ost_2 - ost_1) // 3
	print(n)


for _ in range(int(input())):
	n = int(input())
	arr = [0, 0, 0]
	for el in input().split(' '):
		arr[int(el) % 3] += 1
	ans = arr[0] + min(arr[1], arr[2]) + abs(arr[1] - arr[2]) // 3
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	m = [0, 0, 0]
	for i in l:
		m[i % 3] += 1
	print(m[0] + min(m[1], m[2]) + abs(m[1] - m[2]) // 3)


def func(L):
	(result, one, two) = (0, 0, 0)
	for i in range(len(L)):
		if L[i] % 3 == 0:
			result += 1
			L[i] = 0
		else:
			L[i] = L[i] % 3
			if L[i] == 1:
				one += 1
			if L[i] == 2:
				two += 1
	if two == one:
		result += one
		return result
	elif one > two:
		one -= two
		result += two
		result += one // 3
		return result
	else:
		two -= one
		result += one
		result += two * 2 // 6
		return result
n = int(input())
for i in range(n):
	input()
	L = []
	L = list(map(int, input().split()))
	print(func(L))


import math

def fact(n):
	ans = 1
	for i in range(2, n + 1):
		ans *= i
	return ans

def comb(n, c):
	return fact(n) // (fact(n - c) * c)
for _ in range(int(input())):
	n = int(input())
	ans = 0
	cnt = 0
	nums = list(map(int, input().split()))
	c0 = 0
	c1 = 0
	c2 = 0
	for i in range(n):
		if nums[i] % 3 == 0:
			c0 += 1
		elif nums[i] % 3 == 1:
			c1 += 1
		else:
			c2 += 1
	sub = min(c2, c1)
	c0 += sub
	c2 -= sub
	c1 -= sub
	if c2 > 2:
		c0 += c2 // 3
	if c1 > 2:
		c0 += c1 // 3
	print(c0)


T = int(input())
for _ in range(T):
	N = int(input())
	l = list(map(int, input().split()))
	d = dict()
	d[1] = 0
	d[2] = 0
	d[0] = 0
	for i in l:
		d[i % 3] += 1
	if d[1] > d[2]:
		a = d[1] - d[2]
		print(a // 3 + d[2] + d[0])
	else:
		a = d[2] - d[1]
		print(a // 3 + d[1] + d[0])


t = int(input())
for i in range(t):
	n = int(input())
	cnt1 = 0
	cnt2 = 0
	cnt3 = 0
	ar = list(map(int, input().split()))
	for i in ar:
		if i % 3 == 0:
			cnt3 += 1
		elif i % 3 == 1:
			cnt1 += 1
		else:
			cnt2 += 1
	if cnt1 > cnt2:
		cnt1 -= cnt2
		cnt3 += cnt2
		cnt3 += cnt1 // 3
	else:
		cnt2 -= cnt1
		cnt3 += cnt1
		cnt3 += cnt2 // 3
	print(cnt3)


cases = int(input())
while cases:
	cases -= 1
	num = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	ones = 0
	twos = 0
	for n in arr:
		md = n % 3
		if md == 0:
			ans += 1
		elif md == 1:
			ones += 1
		else:
			twos += 1
	mn = min(ones, twos)
	ans += mn
	ones -= mn
	twos -= mn
	ans += twos // 3
	ans += ones // 3
	print(ans)


q = int(input())
for _ in range(q):
	n = int(input())
	nums = list(map(int, input().split()))
	rem0 = 0
	rem1 = 0
	rem2 = 0
	for i in nums:
		if i % 3 == 0:
			rem0 += 1
		elif i % 3 == 1:
			rem1 += 1
		elif i % 3 == 2:
			rem2 += 1
	if rem2 >= rem1:
		print(rem0 + rem1 + (rem2 - rem1) // 3)
	else:
		print(rem0 + rem2 + (rem1 - rem2) // 3)


t = int(input())
while t:
	z = int(input())
	l = list(map(int, input().rstrip().split(' ')))
	l1 = [i for i in l if i % 3]
	count = z - len(l1)
	for i in range(len(l1)):
		l1[i] = l1[i] % 3
	ones = l1.count(1)
	twos = l1.count(2)
	if twos >= ones:
		count = count + ones
		twos = twos - ones
		count += twos // 3
	elif ones > twos:
		count = count + twos
		ones = ones - twos
		count = count + ones // 3
	print(count)
	t -= 1


import math

def merge_it_fun(my_list, n1):
	x_mod0 = 0
	x_mod1 = 0
	x_mod2 = 0
	for x in my_list:
		if x % 3 == 0:
			x_mod0 += 1
		elif x % 3 == 1:
			x_mod1 += 1
		else:
			x_mod2 += 1
	print(x_mod0 + min(x_mod1, x_mod2) + math.floor(abs(x_mod1 - x_mod2) / 3))
n = int(input())
for _ in range(n):
	n1 = int(input())
	my_list = list(map(int, input().split()))
	merge_it_fun(my_list, n1)


q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, input().split(' ')))
	res = 0
	a1 = 0
	a2 = 0
	for j in range(n):
		if a[j] % 3 == 0:
			res += 1
		elif a[j] % 3 == 1:
			a1 += 1
		elif a[j] % 3 == 2:
			a2 += 1
	if a1 == a2:
		res += a1
	elif a1 < a2:
		res += a1
		res += (a2 - a1) // 3
	else:
		res += a2
		res += (a1 - a2) // 3
	print(res)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = [0] * 3
	for num in a:
		count[num % 3] += 1
	ret = count[0]
	minUsed = min(count[1], count[2])
	ret += minUsed + (count[1] - minUsed) // 3 + (count[2] - minUsed) // 3
	print(ret)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(q, w, e) = (0, 0, 0)
	for i in a:
		z = i % 3
		if z == 0:
			q += 1
		elif z == 1:
			w += 1
		else:
			e += 1
	q += min(w, e) + (max(w, e) - min(w, e)) // 3
	print(q)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(inp())
	a = lis()
	for i in range(n):
		a[i] = a[i] % 3
	cnt = [0] * 3
	for i in range(n):
		cnt[a[i]] += 1
	temp = min(cnt[1], cnt[2])
	print(cnt[0] + temp + (cnt[1] - temp) // 3 + (cnt[2] - temp) // 3)
testcase(int(inp()))


t = int(input())
for i in range(0, t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(map(lambda x: x % 3, l))
	a = l1.count(0)
	b = l1.count(1)
	c = l1.count(2)
	ans = a
	if b > c:
		ans = ans + c
		b = b - c
		ans = ans + b // 3
	elif c > b:
		ans += b
		c = c - b
		ans += c // 3
	else:
		ans += b
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	seti = set()
	l.sort()
	count = 0
	for i in range(n):
		if l[i] % 3 == 0:
			seti.add(i)
			count += 1
	for i in range(n):
		if l[i] % 3 != 0:
			for j in range(i + 1, n):
				if l[j] % 3 != 0:
					if (l[i] + l[j]) % 3 == 0 and j not in seti and (i not in seti):
						count += 1
						seti.add(j)
						seti.add(i)
						break
	k = 0
	for i in range(n):
		if i not in seti:
			k += l[i]
			if k % 3 == 0:
				count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	(a, b, c) = (0, 0, 0)
	for i in arr:
		if i % 3 == 0:
			a += 1
		elif i % 3 == 1:
			b += 1
		else:
			c += 1
	m = min(b, c)
	d = abs(b - c) // 3
	print(a + m + d)


q = int(input())
for i in range(q):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	b = [a[i] % 3 for i in range(n)]
	c0 = 0
	c1 = 0
	c2 = 0
	for i in range(n):
		if b[i] == 0:
			c0 += 1
		elif b[i] == 1:
			c1 += 1
		else:
			c2 += 1
	res = c0 + min(c1, c2) + abs(c1 - c2) // 3
	print(res)


n = int(input())
arr1 = []
arr = []
for i in range(0, n):
	m = int(input())
	arr = list(map(int, input().split()))
	count1 = 0
	count2 = 0
	count3 = 0
	for j in range(0, len(arr)):
		if arr[j] % 3 == 0:
			count1 += 1
			continue
		else:
			arr[j] = arr[j] % 3
			if arr[j] == 1:
				count2 += 1
			elif arr[j] == 2:
				count3 += 1
	if count2 >= count3:
		x = count1 + count3 + (count2 - count3) // 3
	elif count2 < count3:
		x = count1 + count2 + (count3 - count2) // 3
	arr1.append(x)
for i in range(0, n):
	print(arr1[i])


t = int(input())
for u in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	guys = [0, 0, 0]
	for guy in a:
		guys[guy % 3] += 1
	tot = guys[0]
	a = min(guys[1], guys[2])
	guys[1] -= a
	guys[2] -= a
	tot += a
	tot += guys[1] // 3
	tot += guys[2] // 3
	print(tot)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arr1 = [0, 0, 0]
	for j in range(n):
		arr1[arr[j] % 3] += 1
	ans = arr1[0]
	ans1 = ans
	ans1 += arr1[1] // 3
	ans1 += arr1[2] // 3
	k = min(arr1[1], arr1[2])
	ans += k
	arr1[1] -= k
	arr1[2] -= k
	ans += arr1[1] // 3
	ans += arr1[2] // 3
	print(max(ans, ans1))


import math
n = input()
n = int(n)
b = [[0 for x in range(0)] for y in range(n)]
for i in range(n):
	a = int(input())
	f = [int(j) % 3 for j in input().split()][:a]
	b[i] = f
for i in range(n):
	t = 0
	z = 0
	one = 0
	two = 0
	for j in range(len(b[i])):
		if b[i][j] == 0:
			z = z + 1
		elif b[i][j] == 1:
			one = one + 1
		else:
			two = two + 1
	t = z
	if one == two:
		t = t + one
	else:
		m = min(one, two)
		t = t + (m + (one + two - 2 * m) / 3)
	print(math.floor(t))


t = int(input())
for i in range(1, t + 1):
	n = int(input())
	a = [int(i) for i in input().split()]
	k1 = 0
	k2 = 0
	k3 = 0
	for j in range(0, n):
		if a[j] % 3 == 1:
			k1 += 1
		elif a[j] % 3 == 2:
			k2 += 1
		else:
			k3 += 1
	q = min(k1, k2)
	print(k3 + q + (k1 - q) // 3 + (k2 - q) // 3)


t = int(input())
for i in range(t):
	n = int(input())
	li = [int(x) for x in input().split()]
	total = 0
	count_0 = 0
	count_1 = 0
	count_2 = 0
	for x in li:
		rem = x % 3
		if rem == 0:
			count_0 += 1
		elif rem == 1:
			count_1 += 1
		else:
			count_2 += 1
	total = total + count_0
	mi = min(count_1, count_2)
	count_1 = count_1 - mi
	count_2 -= mi
	total = total + mi + count_1 // 3 + count_2 // 3
	print(total)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
msi = lambda : map(int, stdin.readline().split())
lsi = lambda : list(msi())
t = ii()
for _ in range(t):
	n = ii()
	a = li()
	a = [e % 3 for e in a]
	result = a.count(0)
	result += min(a.count(1), a.count(2))
	result += abs(a.count(1) - a.count(2)) // 3
	print(result)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = c = 0
	for item in a:
		if item % 3 == 1:
			b += 1
		elif item % 3 == 2:
			c += 1
	if b < c:
		print(n - c + (c - b) // 3)
	else:
		print(n - b + (b - c) // 3)


n = int(input())
for i in range(n):
	a = int(input())
	k = list(map(lambda x: x % 3, map(int, input().split())))
	zero = k.count(0)
	one = k.count(1)
	two = k.count(2)
	extra = min(k.count(1), k.count(2))
	print(zero + extra + (one - extra) // 3 + (two - extra) // 3)


T = int(input())
ans = []
for _ in range(T):
	input()
	A = [int(_) for _ in input().split()]
	cnt = [0] * 3
	for a in A:
		cnt[a % 3] += 1
	M = max(cnt[1:])
	m = min(cnt[1:])
	ans += [cnt[0] + m + (M - m) // 3]
print(*ans, sep='\n')


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split(' ')))
	b = [x % 3 for x in a]
	answer = [0, 0, 0]
	for bn in b:
		answer[bn] += 1
	couple = min(answer[1], answer[2])
	extra = (max(answer[1], answer[2]) - couple) // 3
	print(answer[0] + couple + extra)
	t -= 1


import os
import heapq
import sys
import math
import bisect
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def binaryToDecimal(n):
	return int(n, 2)

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = inar()
		freq = [0, 0, 0]
		for i in range(n):
			freq[arr[i] % 3] += 1
		if freq[1] == freq[2]:
			print(freq[1] + freq[0])
		elif freq[1] > freq[2]:
			print(freq[0] + freq[2] + (freq[1] - freq[2]) // 3)
		else:
			print(freq[0] + freq[1] + (freq[2] - freq[1]) // 3)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	v = {0: 0, 1: 0, 2: 0}
	x = [int(c) % 3 for c in input().split()]
	for i in x:
		v[i] += 1
	ans = 0
	ans += v[0]
	temp = min(v[1], v[2])
	ans += temp
	v[1] -= temp
	v[2] -= temp
	ans += v[1] // 3
	ans += v[2] // 3
	print(ans)


t = int(input())

def solve(a):
	l = [0, 0, 0]
	for i in range(len(a)):
		l[a[i] % 3] += 1
	return l[0] + min(l[1:]) + abs(l[1] - l[2]) // 3
for i in range(t):
	input()
	a = list(map(int, input().split()))
	print(solve(a))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a = [i % 3 for i in a]
	ans = a.count(0)
	m = a.count(1)
	w = a.count(2)
	if m == w:
		ans += m
	elif m > w:
		ans += w
		m -= w
		ans += m // 3
	else:
		ans += m
		w -= m
		ans += w // 3
	print(ans)


t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	a = input().strip().split(' ')
	j = 0
	for i in a:
		a[j] = int(int(i) % 3)
		j = j + 1
	print(a.count(0) + min(a.count(1), a.count(2)) + (a.count(1) - min(a.count(1), a.count(2))) // 3 + (a.count(2) - min(a.count(1), a.count(2))) // 3)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	D = {0: 0, 1: 0, 2: 0}
	for val in A:
		val = val % 3
		D[val] += 1
	count = D[0]
	Min = min([D[1], D[2]])
	Max = max([D[1], D[2]])
	count += Min
	D[1] -= Min
	D[2] -= Min
	count += D[1] // 3
	count += D[2] // 3
	print(count)


def solve(arr):
	D = {0: 0, 1: 0, 2: 0}
	for x in arr:
		D[x] += 1
	pairs = min(D[1], D[2])
	return D[0] + pairs + (D[1] - pairs) // 3 + (D[2] - pairs) // 3
Q = int(input())
for _ in range(Q):
	input()
	print(solve([*map(lambda x: int(x) % 3, input().split(' '))]))


q = int(input())
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	a = [i % 3 for i in a]
	l = a.count(0)
	(a1, a2) = (a.count(1), a.count(2))
	l += min(a1, a2)
	l += abs(a1 - a2) // 3
	print(l)


t = int(input())
for _ in range(t):
	n = int(input())
	kr3 = 0
	kr2 = 0
	kr1 = 0
	lst = list(map(int, input().split()))
	for a in lst:
		ost = a % 3
		if ost == 0:
			kr3 += 1
		if ost == 1:
			kr1 += 1
		if ost == 2:
			kr2 += 1
	print(kr3 + min(kr2, kr1) + abs(kr1 - kr2) // 3)


import sys
import collections

def solve(xs):
	counter = collections.Counter([x % 3 for x in xs])
	annilate = min(counter[1], counter[2])
	rest = max(counter[1], counter[2]) - annilate
	return counter[0] + annilate + rest // 3
_tc = int(input())
for _ in range(_tc):
	x = int(input())
	a = [int(s) for s in input().split()]
	res = solve(a)
	print(res)


q = int(input())
for _ in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	vi = dict(zip([0, 1, 2], [0, 0, 0]))
	for x in a:
		vi[x % 3] = vi[x % 3] + 1
	print(vi[0] + min(vi[1], vi[2]) + (max(vi[1], vi[2]) - min(vi[1], vi[2])) // 3)


import math
from decimal import *
t = int(input())
l = []
le = []
count = 0
c1 = 0
c2 = 0
for k in range(t):
	a = int(input())
	ls = list(map(int, input().split()))
	le.append(a)
	l.append(ls)
for i in range(len(l)):
	lt = l[i]
	for m in range(len(lt)):
		lt[m] = lt[m] % 3
	for e in lt:
		if e == 0:
			count += 1
	lt = [value for value in lt if value != 0]
	for x in lt:
		if x == 1:
			c1 += 1
		if x == 2:
			c2 += 1
	mi = min(c1, c2)
	count += mi
	ln = []
	for n in lt:
		if c1 != c2:
			if c1 == mi:
				if n == 2:
					ln.append(2)
				if Decimal(len(ln)) == c2 - mi:
					break
			if c2 == mi:
				if n == 1:
					ln.append(1)
				if Decimal(len(ln)) == c1 - mi:
					break
	mul = math.floor(Decimal(len(ln) / 3))
	count += mul
	print(Decimal(count))
	count = 0
	c1 = 0
	c2 = 0


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	st = []
	for i in range(n):
		if a[i] % 3 == 0:
			c = c + 1
		else:
			st.append(a[i])
	for i in range(len(st)):
		st[i] = st[i] % 3
	st.sort()
	c1 = st.count(1)
	c2 = st.count(2)
	if c1 >= c2:
		c = c + c2
		c = c + (c1 - c2) // 3
	else:
		c = c + c1
		c = c + (c2 - c1) // 3
	print(c)


for i in range(int(input())):
	N = int(input())
	Answer = [0, 0, 0]
	for j in list(map(int, input().split())):
		Answer[j % 3] += 1
	Min = min(Answer[1], Answer[2])
	print(Answer[0] + (Answer[1] - Min) // 3 + (Answer[2] - Min) // 3 + Min)


def f():
	l = [int(k) % 3 for k in input().split()]
	a = sum([k == 1 for k in l])
	b = sum([k == 2 for k in l])
	(a, b) = sorted((a, b))
	c = len(l) - a - b
	return a + c + (b - a) // 3
for k in range(int(input())):
	input()
	print(f())


def f(x):
	ost_0 = 0
	ost_1 = 0
	ost_2 = 0
	for i in x:
		if i % 3 == 0:
			ost_0 += 1
		if i % 3 == 1:
			ost_1 += 1
		if i % 3 == 2:
			ost_2 += 1
		if ost_1 >= ost_2:
			q = (ost_1 - ost_2) // 3
		else:
			q = (ost_2 - ost_1) // 3
	print(ost_0 + min(ost_1, ost_2) + q)
n = int(input())
m = [None] * n
for i in range(n):
	input()
	m[i] = list(map(int, input().split()))
for i in range(n):
	f(m[i])


import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
	return int(input())

def getList():
	return list(map(int, input().split()))

def solve():
	n = getN()
	nums = getList()
	cnt = [0, 0]
	sanbai = 0
	for num in nums:
		if num % 3 == 1:
			cnt[0] += 1
		elif num % 3 == 2:
			cnt[1] += 1
		elif num != 0:
			sanbai += 1
	ans = min(cnt)
	ans += (max(cnt) - ans) // 3
	ans += sanbai
	print(ans)
t = getN()
for times in range(t):
	solve()


from collections import Counter

def read_nums():
	return [int(x) for x in input().split()]

def solve(nums):
	nums = [x % 3 for x in nums]
	c = Counter(nums)
	res = c[0]
	min_c1_c2 = min(c[1], c[2])
	res += min_c1_c2
	c[1] -= min_c1_c2
	c[2] -= min_c1_c2
	res += c[1] // 3
	res += c[2] // 3
	return res

def main():
	(t,) = read_nums()
	for _ in range(t):
		_ = read_nums()
		nums = read_nums()
		print(solve(nums))
main()


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))[:n]
	b = []
	c = 0
	for i in a:
		b.append(i % 3)
	x = b.count(0)
	y = b.count(1)
	z = b.count(2)
	c = c + x
	f = min(y, z)
	c = c + min(y, z)
	d = max(y, z) - min(y, z)
	if d >= 3:
		c = c + d // 3
	print(c)


for _ in range(int(input())):
	n = int(input())
	b = list(map(int, input().split()))
	a = [b[i] % 3 for i in range(n)]
	k1 = a.count(1)
	k2 = a.count(2)
	k = a.count(0)
	if k1 > k2:
		k += k2
		k1 -= k2
		k += k1 // 3
	else:
		k += k1
		k2 -= k1
		k += k2 // 3
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = [i % 3 for i in a]
	c0 = a.count(0)
	c1 = a.count(1)
	c2 = a.count(2)
	x = min(c1, c2)
	c1 -= x
	c2 -= x
	s = c0 + x + c1 // 3 + c2 // 3
	print(s)


test_cases = int(input())
result_list = []
for test in range(test_cases):
	length = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	count = [0, 0, 0, 0]
	for i in range(length):
		count[arr[i] % 3] += 1
	if abs(count[1] - count[2]) >= 3:
		count[3] = int(abs(count[1] - count[2]) / 3)
	ans = count[0] + min(count[1], count[2]) + count[3]
	result_list.append(ans)
for i in result_list:
	print(i)


n = int(input())
llist = {}
for i in range(n):
	llist[i] = []
	llist[i].append(int(input()))
	lllist = []
	llist[i].append([int(i) for i in input().split()])
for (key, value) in llist.items():
	llist2 = []
	for item in value[1]:
		llist2.append(item % 3)
	value[1] = llist2
for (key, value) in llist.items():
	cnt = 0
	cnt += value[1].count(0)
	if (1 in value[1]) & (2 in value[1]):
		count1 = value[1].count(1)
		count2 = value[1].count(2)
		if count1 == count2:
			cnt += count1
		else:
			minm = min(count1, count2)
			cnt += minm
			for i in range(minm):
				value[1].remove(1)
				value[1].remove(2)
	cnt += abs(value[1].count(1) - value[1].count(2)) / 3
	print(int(cnt))


qcount = int(input())
for qnumb in range(qcount):
	n = int(input())
	k = list(map(int, input().split()))
	w = [0, 0, 0]
	for i in k:
		w[i % 3] += 1
	z = min([w[1], w[2]])
	w[0] += z
	w[0] += (w[1] - z) // 3
	w[0] += (w[2] - z) // 3
	print(w[0])


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = 0
	l = []
	for i in range(n):
		if a[i] % 3 == 0:
			c = c + 1
		else:
			l.append(a[i] % 3)
	y = min(l.count(1), l.count(2))
	print(c + (l.count(1) - y) // 3 + (l.count(2) - y) // 3 + y)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0, 0, 0]
	for x in a:
		b[x % 3] += 1
	print(b[0] + min(b[1], b[2]) + abs(b[2] - b[1]) // 3)


RI = lambda : [int(x) for x in input().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
t = int(input())
for _ in range(t):
	n = int(input())
	l = RI()
	d = df(int)
	ans = 0
	for i in range(n):
		if l[i] % 3 == 0:
			ans += 1
		elif l[i] % 3 == 1:
			d[1] += 1
		else:
			d[2] += 1
	if d[1] > d[2]:
		ans += d[2]
		ans += (d[1] - d[2]) // 3
	else:
		ans += d[1]
		ans += (d[2] - d[1]) // 3
	print(ans)


for _ in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	k1 = 0
	k2 = 0
	k3 = 0
	for i in b:
		if i % 3 == 0:
			k3 += 1
		elif i % 3 == 1:
			k1 += 1
		else:
			k2 += 1
	l = min(k1, k2)
	m = (k1 - l) // 3
	n = (k2 - l) // 3
	print(k3 + l + m + n)


for _ in range(int(input().strip())):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt1 = 0
	cnt0 = 0
	cnt2 = 0
	for i in range(len(arr)):
		arr[i] = arr[i] % 3
		if arr[i] == 1:
			cnt1 += 1
		elif arr[i] == 2:
			cnt2 += 1
		elif arr[i] == 0:
			cnt0 += 1
	temp = min(cnt1, cnt2)
	rem = max(cnt1, cnt2) - temp
	temp += rem // 3
	temp += cnt0
	print(temp)


n = int(input())
for i in range(n):
	q = int(input())
	(zero, one, two) = (0, 0, 0)
	for i in map(int, input().split()):
		rest = i % 3
		if rest == 0:
			zero += 1
		elif rest == 1:
			one += 1
		else:
			two += 1
	ob = min(one, two)
	one -= ob
	two -= ob
	print(zero + ob + (one + two) // 3)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [0, 0, 0]
	for i in map(int, input().split()):
		a[i % 3] += 1
	print(a[0] + min(a[1], a[2]) + abs(a[1] - a[2]) // 3)


from collections import Counter
for _ in range(int(input())):
	input()
	c = Counter((int(x) % 3 for x in input().split()))
	print(int(c[0] + min(c[1], c[2]) + (max(c[1], c[2]) - min(c[1], c[2])) // 3))


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	b = len(list(filter(lambda x: x % 3 == 0, a)))
	c = list(filter(lambda x: x % 3 != 0, a))
	d = list(map(lambda x: x % 3, c))
	(e, f) = ([], [])
	for i in range(len(d)):
		if d[i] == 1:
			e.append(d[i])
		else:
			f.append(d[i])
	f = len(f)
	e = len(e)
	if f >= e:
		b = b + e + (f - e) // 3
	else:
		b = b + f + (e - f) // 3
	print(b)
	t = t - 1


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	d = {}
	ans = 0
	for i in range(n):
		d[a[i] % 3] = d.get(a[i] % 3, 0) + 1
	n1 = d.get(1, 0)
	n2 = d.get(2, 0)
	if n1 <= n2:
		ans = n1 + (n2 - n1) // 3
	elif n2 < n1:
		left = n1 - n2
		ans = left // 3 + n2
	print(ans + d.get(0, 0))


t = int(input())

def digits_sum(a):
	total = 0
	while a > 0:
		total += a % 10
		a //= 10
	return int(total)
for i in range(t):
	n = int(input())
	counts = [0 for i in range(3)]
	for x in input().split():
		a = int(x)
		r = digits_sum(a) % 3
		counts[r] += 1
	pairs = min(counts[1], counts[2])
	dangling = max(counts[1], counts[2]) - pairs
	total = counts[0] + pairs + int(dangling / 3)
	print(total)


def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def min(a, b):
	if a < b:
		return a
	else:
		return b

def max(a, b):
	if a > b:
		return a
	else:
		return b
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cnt1 = 0
	cnt2 = 0
	cnt3 = 0
	for x in a:
		if x % 3 == 0:
			cnt3 += 1
		elif x % 3 == 2:
			cnt2 += 1
		else:
			cnt1 += 1
	m = min(cnt2, cnt1)
	cnt2 -= m
	cnt1 -= m
	res = cnt3 + m + cnt2 // 3 + cnt1 // 3
	print(res)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = [var % 3 for var in a]
	k = min(a.count(1), a.count(2)) + a.count(0) + abs(a.count(1) - a.count(2)) // 3
	print(k)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a = [i % 3 for i in a]
	zero = 0
	one = 0
	two = 0
	for i in a:
		if i == 0:
			zero += 1
		elif i == 1:
			one += 1
		else:
			two += 1
	cnt = zero
	x = min(one, two)
	cnt += x
	one -= x
	two -= x
	cnt += one // 3
	cnt += two // 3
	print(cnt)


t = int(input())
for i in range(t):
	n = int(input())
	r0 = 0
	r1 = 0
	r2 = 0
	a = list(map(int, input().split()))
	for elem in a:
		if elem % 3 == 0:
			r0 += 1
		elif elem % 3 == 1:
			r1 += 1
		else:
			r2 += 1
	kol = r0
	if r1 >= r2:
		kol += r2
		r1 -= r2
		kol += r1 // 3
	else:
		kol += r1
		r2 -= r1
		kol += r2 // 3
	print(kol)


q = int(input())
for i in range(q):
	n = int(input())
	mas = list(map(int, input().split()))
	a = 0
	b = 0
	c = 0
	for i in range(n):
		if mas[i] % 3 == 1:
			a += 1
		elif mas[i] % 3 == 2:
			b += 1
		else:
			c += 1
	print(min(a, b) + c + (a - min(a, b)) // 3 + (b - min(a, b)) // 3)


def read():
	n = int(input())
	a = list(map(int, input().split()))
	return (n, a)

def solve(n, a):
	c = [0] * 3
	for ai in a:
		c[ai % 3] += 1
	d = min(c[1], c[2])
	c[1] -= d
	c[2] -= d
	return c[0] + d + c[1] // 3 + c[2] // 3
for i in range(int(input())):
	result = solve(*read())
	print(result)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = [0, 0, 0]
	for i in range(n):
		l[a[i] % 3] += 1
	m = 0
	m += l[0]
	l[0] = 0
	m1 = min(l[1], l[2])
	m += m1
	(l[1], l[2]) = (l[1] - m1, l[2] - m1)
	if l[1] >= 3:
		m += l[1] // 3
	elif l[2] >= 3:
		m += l[2] // 3
	print(m)


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	for i in range(n):
		lst[i] = lst[i] % 3
	c0 = lst.count(0)
	c1 = lst.count(1)
	c2 = lst.count(2)
	c0 = c0 + min(c1, c2)
	c1 = max(c1, c2) - min(c1, c2)
	c0 = c0 + c1 // 3
	print(c0)


import math
import bisect
import heapq
from collections import defaultdict

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, x, y) = egcd(b % a, a)
		return (g, y - b // a * x, x)

def mulinv(b, n):
	(g, x, _) = egcd(b, n)
	if g == 1:
		return x % n

def isprime(n):
	for d in range(2, int(math.sqrt(n)) + 1):
		if n % d == 0:
			return False
	return True

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	elif p == 3:
		return list(input())
	else:
		return int(input())

class DisjointSet:
	_disjoint_set = list()

	def __init__(self, init_arr):
		self._disjoint_set = []
		if init_arr:
			for item in list(set(init_arr)):
				self._disjoint_set.append([item])

	def _find_index(self, elem):
		for item in self._disjoint_set:
			if elem in item:
				return self._disjoint_set.index(item)
		return None

	def find(self, elem):
		for item in self._disjoint_set:
			if elem in item:
				return self._disjoint_set[self._disjoint_set.index(item)]
		return None

	def union(self, elem1, elem2):
		index_elem1 = self._find_index(elem1)
		index_elem2 = self._find_index(elem2)
		if index_elem1 != index_elem2 and index_elem1 is not None and (index_elem2 is not None):
			self._disjoint_set[index_elem2] = self._disjoint_set[index_elem2] + self._disjoint_set[index_elem1]
			del self._disjoint_set[index_elem1]
		return self._disjoint_set

	def get(self):
		return self._disjoint_set

def graph(n, m, edg=False):
	edges = []
	visited = [0] * n
	g = [list() for _ in range(n + 1)]
	for i in range(m):
		(u, v) = f(1)
		g[u].append(v)
		g[v].append(u)
		if edg:
			edges.append((u, v))
	if edg:
		return (g, visited, edg)
	else:
		return (g, visited)

def bfs(g, visited):
	queue = [1]
	visited[1] = 1
	for u in queue:
		for v in g[u]:
			if visited[v] == 0:
				queue.append(v)
			visited[v] = 1

def dfs(u, g, visited):
	print(u)
	visited[u] = 1
	for v in g[u]:
		if visited[v] == 0:
			dfs(v, g, visited)
t = f()
for i in range(t):
	n = f()
	cl = f(2)
	count = 0
	a = 0
	b = 0
	for i in range(n):
		if cl[i] % 3 == 0:
			count += 1
		elif cl[i] % 3 == 1:
			a += 1
		else:
			b += 1
	print(count + min(a, b) + (max(a, b) - min(a, b)) // 3)


nq = int(input())
res = []
for i in range(nq):
	n = int(input())
	temp = list(map(int, input().split()))
	rem_0 = 0
	rem_1 = 0
	rem_2 = 0
	for num in temp:
		if num % 3 == 0:
			rem_0 += 1
		elif num % 3 == 1:
			rem_1 += 1
		else:
			rem_2 += 1
	mi = min(rem_1, rem_2)
	rem_1 -= mi
	rem_2 -= mi
	res.append(rem_0 + mi + rem_1 // 3 + rem_2 // 3)
print(*res, sep='\n')


n = int(input())
n1 = [0] * n
a = [[]] * n
ans = [0] * n
for i in range(n):
	n1[i] = int(input())
	a[i] = list(map(int, input().split()))
for i in range(n):
	ismod = [0, 0, 0]
	for j in range(len(a[i])):
		ismod[a[i][j] % 3] += 1
	ans[i] += ismod[0] + min(ismod[1], ismod[2])
	if ismod[1] >= ismod[2]:
		ans[i] += (ismod[1] - ismod[2]) // 3
	else:
		ans[i] += (ismod[2] - ismod[1]) // 3
for i in ans:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	mods = [0, 0, 0]
	for num in a:
		mods[num % 3] += 1
	val = min(mods[1], mods[2])
	mods[0] = mods[0] + val
	mods[1] = mods[1] - val
	mods[2] = mods[2] - val
	mods[0] = mods[0] + int(mods[1] / 3) + int(mods[2] / 3)
	print(mods[0])


q = int(input())
b = [0, 0, 0]
kq = 0
for i in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0, 0, 0]
	for j in range(n):
		t = a[j] % 3
		b[t] += 1
	mn = min(b[1], b[2])
	kq = b[0] + mn
	b[1] -= mn
	b[2] -= mn
	kq = kq + int((b[1] + b[2]) / 3)
	print(kq)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	cnt0 = 0
	cnt1 = 0
	cnt2 = 0
	for i in A:
		if i % 3 == 0:
			cnt0 += 1
		elif i % 3 == 1:
			cnt1 += 1
		else:
			cnt2 += 1
	print(cnt0 + min(cnt1, cnt2) + abs(cnt1 - cnt2) // 3)


t = int(input())
for i in range(t):
	n = int(input())
	cs = [0, 0, 0]
	for x in input().split():
		cs[int(x) % 3] += 1
	k = cs[0]
	k2 = min(cs[2], cs[1])
	k += k2
	cs[2] -= k2
	cs[1] -= k2
	k += (cs[1] + cs[2]) // 3
	print(k)


q = int(input())
for j in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		l[i] = l[i] % 3
	l.sort()
	cnt = l.count(0)
	ones = l.count(1)
	twos = l.count(2)
	if ones > twos:
		cnt += min(ones, twos) + (ones - twos) // 3
	else:
		cnt += min(ones, twos) + (twos - ones) // 3
	print(cnt)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		d = collections.defaultdict(lambda : 0)
		for x in a:
			d[x % 3] += 1
		ans = d[0] + min(d[1], d[2])
		cnt = d[1] + d[2] - 2 * min(d[1], d[2])
		ans += cnt // 3
		print(ans)
main()


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def dinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def main():
	n = int(input())
	a = rinput()
	s = 0
	d = 0
	f = 0
	for val in a:
		if val % 3 == 0:
			s += 1
		elif val % 3 == 2:
			d += 1
		else:
			f += 1
	if d == f:
		print(s + d)
	elif d > f:
		print(s + f + (d - f) // 3)
	else:
		print(s + d + (f - d) // 3)
for i in range(int(input())):
	main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = d = e = 0
	for i in range(n):
		if a[i] % 3 == 0:
			c += 1
		elif a[i] % 3 == 1:
			d += 1
		else:
			e += 1
	c += min(d, e)
	f = min(d, e)
	d -= f
	e -= f
	c += d // 3
	c += e // 3
	print(c)


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0, 0, 0]
	for i in range(n):
		b[a[i] % 3] += 1
	m = min(b[1], b[2])
	print(b[0] + m + (b[1] - m) // 3 + (b[2] - m) // 3)


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	ans = 0
	cnt = [0, 0, 0]
	for each in ar:
		each %= 3
		cnt[each] += 1
	ans = cnt[0]
	mn = min(cnt[1], cnt[2])
	cnt[1] -= mn
	cnt[2] -= mn
	ans = ans + mn + (cnt[1] + cnt[2]) // 3
	print(ans)


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		stat = {0: 0, 1: 0, 2: 0}
		for i in range(n):
			carry = a[i] % 3
			z = stat.get(carry, 0) + 1
			stat[carry] = z
		estim = min(stat.get(1, 0), stat.get(2, 0))
		stat[1] -= estim
		stat[2] -= estim
		print(stat.get(0, 0) + estim + stat[1] // 3 + stat[2] // 3)
main()


t = int(input())
while t > 0:
	n = int(input())
	l = [int(s) for s in input().split()]
	sum1 = c1 = c2 = 0
	for i in l:
		if i % 3 == 0:
			sum1 += 1
		elif i % 3 == 1:
			c1 += 1
		else:
			c2 += 1
	sum1 += min(c1, c2)
	if c1 - c2 > 0:
		sum1 += (c1 - c2) // 3
	if c2 - c1 > 0:
		sum1 += (c2 - c1) // 3
	print(sum1)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	freq = [0] * 3
	for i in a:
		freq[i % 3] += 1
	l = freq[1]
	m = freq[2]
	mi = min(l, m)
	ma = max(l, m)
	ans = (ma - mi) // 3
	ans += freq[0] + mi
	print(ans)


T = int(input())
testcase = 0
while testcase < T:
	n = int(input())
	array = input()
	array = [int(x) for x in array.split(' ')]
	freq = {}
	freq[0] = 0
	freq[1] = 0
	freq[2] = 0
	for num in array:
		freq[num % 3] += 1
	m = min(freq[1], freq[2])
	freq[0] += m
	freq[1] -= m
	freq[2] -= m
	freq[0] += freq[1] // 3
	freq[0] += freq[2] // 3
	print(freq[0])
	testcase += 1


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
sys.setrecursionlimit(100000000)
inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
jn = lambda x, l: x.join(map(str, l))
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
mod = 1000000007

def ceil(x):
	d = int(x)
	if x == d:
		return int(x)
	return int(x) + 1

def ceildiv(x, d):
	if x % d == 0:
		return x // d
	return x // d + 1
t = int(input())
for _ in range(t):
	n = int(input())
	l = seq()
	l1 = [x % 3 for x in l]
	r2 = l1.count(2)
	r1 = l1.count(1)
	r0 = l1.count(0)
	tot = r0
	com = min(r1, r2)
	tot += com
	rem = max(r1, r2) - min(r1, r2)
	remcom = rem // 3
	tot += remcom
	print(tot)


from pprint import pprint
import sys
input = sys.stdin.readline
from collections import Counter
q = int(input())
for _ in range(q):
	n = int(input())
	dat = list(map(int, input().split()))
	dat = list(map(lambda x: x % 3, dat))
	c = Counter(dat)
	res = 0
	c0 = c[0]
	c1 = c[1]
	c2 = c[2]
	res += c0
	can = min(c1, c2)
	res += can
	c1 -= can
	c2 -= can
	res += c1 // 3
	res += c2 // 3
	print(res)


def nu(n, a):
	s = 0
	c = [0, 0, 0]
	for i in range(n):
		a[i] = a[i] % 3
		if a[i] % 3 == 0:
			c[0] += 1
		elif a[i] % 3 == 1:
			c[1] += 1
		else:
			c[2] += 1
	k = min(c[1], c[2])
	c[1] -= k
	c[2] -= k
	s += c[0] + k
	if c[2] == 0:
		s += c[1] // 3
	else:
		s += c[2] // 3
	return s
n = int(input())
for _ in range(n):
	print(nu(int(input()), list(map(int, input().split()))))


from math import factorial, ceil
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	l = list(map(int, stdin.readline().split()))
	shan = [0, 0, 0]
	for a in l:
		shan[a % 3] += 1
	count = shan[0]
	a = min(shan[1], shan[2])
	shan[1] -= a
	shan[2] -= a
	count += a
	count += shan[1] // 3 + shan[2] // 3
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c0 = 0
	c1 = 0
	c2 = 0
	for e in l:
		y = e % 3
		if y == 0:
			c0 += 1
		elif y == 1:
			c1 += 1
		elif y == 2:
			c2 += 1
	c = c0 + min(c1, c2) + (max(c1, c2) - min(c1, c2)) // 3
	print(c)


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	A = list(map(int, input().split()))
	Query.append((N, A))
for (N, A) in Query:
	count = [0, 0, 0]
	for a in A:
		count[a % 3] += 1
	(a1, a2) = (count[1], count[2])
	ans = count[0]
	if a1 >= a2:
		ans += a2 + (a1 - a2) // 3
	else:
		ans += a1 + (a2 - a1) // 3
	print(ans)


def howmany(lst):
	m1 = 0
	m2 = 0
	m3 = 0
	for elem in lst:
		x = elem % 3
		if x == 0:
			m3 += 1
		elif x == 1:
			m1 += 1
		else:
			m2 += 1
	return m3 + min(m1, m2) + abs(m2 - m1) // 3
n = int(input())
for i in range(n):
	k = int(input())
	lst = list(map(int, input().split()))
	print(howmany(lst))


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	c = [0] * 3
	for i in a:
		c[i % 3] += 1
	mi = min(c[1], c[2])
	c[0] += mi
	c[1] -= mi
	c[2] -= mi
	print(c[0] + (c[1] + c[2]) // 3)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	rem = [i % 3 for i in a]
	count = Counter(rem)
	tot = count[0]
	cb = min(count[1], count[2])
	tot += cb
	if count[1] - cb > 0:
		tot += (count[1] - cb) // 3
	if count[2] - cb > 0:
		tot += (count[2] - cb) // 3
	print(tot)


t = int(input())
for cas in range(t):
	n = int(input())
	a = [int(e) for e in input().split()]
	b = [0, 0, 0]
	for i in a:
		b[i % 3] += 1
	print(b[0] + min(b[1], b[2]) + abs(b[2] - b[1]) // 3)


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	f = [0] * 3
	for i in a:
		f[i % 3] += 1
	(l, m) = (f[1], f[2])
	(mi, ma) = (min(l, m), max(l, m))
	a = (ma - mi) // 3
	a += f[0] + mi
	print(a)


from collections import Counter as C
Q = int(input())
for _ in range(Q):
	N = int(input())
	A = [int(a) for a in input().split()]
	p = C([i % 3 for i in A])
	ans = p[0]
	(a, b) = (p[1], p[2])
	m = min(p[1], p[2])
	a -= m
	b -= m
	ans += m
	ans += (a + b) // 3
	print(ans)


def main():
	for i in range(int(input())):
		n = int(input())
		a = [int(i) for i in input().split()]
		thr = 0
		tw = 0
		on = 0
		for val in a:
			if val % 3 == 0:
				thr += 1
			elif val % 3 == 2:
				tw += 1
			else:
				on += 1
		if tw == on:
			print(thr + tw)
		elif tw > on:
			print(thr + on + (tw - on) // 3)
		else:
			print(thr + tw + (on - tw) // 3)
main()


q = int(input())
ans = []
for i in range(q):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = [0, 0, 0]
	for j in range(n):
		cnt[a[j] % 3] += 1
	otv = cnt[0] + min(cnt[1], cnt[2])
	if cnt[1] > cnt[2]:
		otv += (cnt[1] - cnt[2]) // 3
	else:
		otv += (cnt[2] - cnt[1]) // 3
	ans.append(otv)
for elem in ans:
	print(elem)


from sys import setcheckinterval, stdin
setcheckinterval(1000)
iin = lambda : int(stdin.readline())
lin = lambda : list(map(int, stdin.readline().split()))
for _ in range(iin()):
	n = iin()
	a = lin()
	dc = {0: 0, 1: 0, 2: 0}
	for i in a:
		dc[i % 3] += 1
	ans = dc[0]
	mn = min(dc[1], dc[2])
	lf = max(dc[1], dc[2]) - mn
	ans += mn + lf // 3
	print(ans)


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	(c, s, k) = (0, 0, 0)
	for i in range(n):
		a[i] = a[i] % 3
		if a[i] == 0:
			c = c + 1
		elif a[i] == 1:
			s = s + 1
		else:
			k = k + 1
	d = min(s, k)
	c = c + d
	k = k - d
	s = s - d
	s = s // 3
	k = k // 3
	c = c + s + k
	print(c)


n = int(input())
for i in range(n):
	t = int(input())
	a = list(map(int, input().split()))
	(a1, a2, a3) = (0, 0, 0)
	for j in a:
		if j % 3 == 1:
			a1 += 1
		elif j % 3 == 2:
			a2 += 1
		else:
			a3 += 1
		x = 0
		if a1 >= a2:
			x = a2 + a3 + (a1 - a2) // 3
		else:
			x = a1 + a3 + (a2 - a1) // 3
	print(min(t, x))


n = int(input())
for j in range(n):
	l = int(input())
	a = list(map(int, input().split()))
	cnt0 = 0
	cnt1 = 0
	cnt2 = 0
	for i in a:
		if i % 3 == 0:
			cnt0 += 1
		elif i % 3 == 1:
			cnt1 += 1
		elif i % 3 == 2:
			cnt2 += 1
	print(cnt0 + min(cnt1, cnt2) + (max(cnt1, cnt2) - min(cnt1, cnt2)) // 3)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c0 = 0
	c1 = 0
	c2 = 0
	sum = 0
	for i in range(n):
		if l[i] % 3 == 0:
			c0 += 1
		elif l[i] % 3 == 1:
			c1 += 1
		else:
			c2 += 1
	sum = sum + c0
	sum += min(c1, c2)
	sum += (max(c1, c2) - min(c1, c2)) // 3
	print(sum)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	h = [0, 0, 0]
	for i in range(n):
		h[l[i] % 3] += 1
	s = min(h[1], h[2])
	h[1] = h[1] - s
	h[2] = h[2] - s
	print(h[0] + s + h[1] // 3 + h[2] // 3)


t = int(input())
while t > 0:
	n = int(input())
	a = list(map(int, input().split()))
	arr = [0, 0, 0]
	for i in range(n):
		arr[a[i] % 3] += 1
	arr[0] += min(arr[1], arr[2])
	if arr[1] <= arr[2]:
		arr[2] = arr[2] - arr[1]
		arr[1] = 0
	if arr[2] < arr[1]:
		arr[1] = arr[1] - arr[2]
		arr[2] = 0
	if arr[1] != 0:
		count = arr[1] // 3
		arr[0] += count
	if arr[2] != 0:
		count = arr[2] * 2 // 6
		arr[0] += count
	print(arr[0])
	t -= 1


for _ in range(int(input())):
	n = int(input())
	l = sorted(list(map(lambda x: int(x) % 3, input().split())))
	c = 0
	count_0 = l.count(0)
	count_1 = l.count(1)
	count_2 = l.count(2)
	c += count_0
	if count_1 <= count_2:
		c += count_1
		d = count_2 - count_1
		c += d // 3
	else:
		c += count_2
		d = count_1 - count_2
		c += d // 3
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	count = 0
	d = dict()
	for i in range(n):
		if a[i] % 3 == 0:
			count += 1
		a[i] = a[i] % 3
		if a[i] == 1:
			d[1] = d.get(1, 0) + 1
		elif a[i] == 2:
			d[2] = d.get(2, 0) + 1
	if 1 not in d and 2 not in d:
		print(count)
	elif 1 not in d:
		print(count + d[2] // 3)
	elif 2 not in d:
		print(count + d[1] // 3)
	else:
		if d[2] >= d[1]:
			count += d[1]
			count += abs(d[1] - d[2]) // 3
		else:
			count += d[2]
			count += abs(d[1] - d[2]) // 3
		print(count)


from collections import Counter
for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter([j % 3 for j in a])
	if c[1] > c[2]:
		l = (c[1] - c[2]) // 3
		c[1] -= 2 * l
		c[2] += l
	elif c[2] > c[1]:
		l = (c[2] - c[1]) // 3
		c[2] -= 2 * l
		c[1] += l
	print(c[0] + min(c[1], c[2]))


for tt in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt1 = 0
	cnt2 = 0
	cnt0 = 0
	for i in range(n):
		if arr[i] % 3 == 0:
			cnt0 += 1
		if arr[i] % 3 == 1:
			cnt1 += 1
		if arr[i] % 3 == 2:
			cnt2 += 1
	result = cnt0 + min(cnt1, cnt2) + abs(cnt1 - cnt2) // 3
	print(result)


from sys import stdin
q = int(stdin.readline().strip())
for i in range(q):
	n = int(stdin.readline().strip())
	s = list(map(int, stdin.readline().strip().split()))
	u = 0
	z = 0
	d = 0
	for i in range(n):
		s[i] = s[i] % 3
		if s[i] == 0:
			z += 1
		elif s[i] == 1:
			u += 1
		else:
			d += 1
	ans = 0
	ans += z
	ans += min(u, d)
	if u <= d:
		d -= u
		x = 0
		for i in range(d):
			x += 2
			x = x % 3
			if x == 0:
				ans += 1
	else:
		u -= d
		x = 0
		for i in range(u):
			x += 1
			x = x % 3
			if x == 0:
				ans += 1
	print(ans)


def div(a):
	count = [0 for x in range(3)]
	for i in range(len(a)):
		a[i] = a[i] % 3
		count[a[i]] += 1
	ans = count[0]
	k = min(count[1], count[2])
	ans += k
	count[1] -= k
	count[2] -= k
	if count[1] > 0:
		k = count[1] // 3
		ans += k
	if count[2] > 0:
		k = count[2] // 3
		ans += k
	print(ans)
T = int(input())
for i in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	div(a)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	(s, r, t, count) = (0, 0, 0, 0)
	for i in range(len(a)):
		if a[i] % 3 == 0:
			t += 1
		elif a[i] % 3 == 1:
			s += 1
		else:
			r += 1
	count += t
	if s >= r:
		count += r
		s -= r
		count += s // 3
	else:
		count += s
		r -= s
		count += r // 3
	print(count)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	a = dict()
	for i in range(n):
		try:
			a[arr[i] % 3] += 1
		except:
			a[arr[i] % 3] = 1
	ans = 0
	temp = temp2 = 1
	try:
		ans = a[0]
	except:
		ans = 0
	try:
		ans += a[2]
		ans -= a[2]
	except:
		temp = 0
	try:
		ans += a[1]
		ans -= a[1]
	except:
		temp2 = 0
	if temp and temp2 and (a[2] - a[1] > 0):
		ans += a[1]
		a[2] -= a[1]
		a[1] = 0
	elif temp and temp2:
		ans += a[2]
		a[1] -= a[2]
		a[2] = 0
	else:
		ans += 0
	try:
		ans += a[2] // 3
	except:
		ans += 0
	try:
		ans += a[1] // 3
	except:
		ans += 0
	print(ans)


for _ in range(int(input())):
	x = int(input())
	li = list(map(int, input().split()))
	cnt = 0
	(one, two) = (0, 0)
	for i in li:
		if i % 3 == 0:
			cnt += 1
		elif i % 3 == 1:
			one += 1
		else:
			two += 1
	m = min(one, two)
	one -= m
	two -= m
	cnt += m
	print(cnt + one // 3 + two // 3)


ans = []
for _ in range(int(input())):
	a = int(input())
	s = [int(i) for i in input().split()]
	cnt_0 = 0
	cnt_1 = 0
	cnt_2 = 0
	for i in range(a):
		if s[i] % 3 == 0:
			cnt_0 += 1
		elif s[i] % 3 == 1:
			cnt_1 += 1
		else:
			cnt_2 += 1
	ans1 = cnt_0 + min(cnt_1, cnt_2) + (max(cnt_1, cnt_2) - min(cnt_1, cnt_2)) // 3
	ans.append(ans1)
	cnt_0 = 0
	cnt_1 = 0
	cnt_2 = 0
for i in range(len(ans)):
	print(ans[i])


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	input()
	d = [0] * 3
	for i in map(int, input().split()):
		d[i % 3] += 1
	print(d[0] + min(d[1:]) + (max(d[1:]) - min(d[1:])) // 3)


for _ in range(int(input())):
	n = int(input())
	cnt = 0
	p = []
	l = list((int(c) for c in input().split()))
	for i in l:
		p.append(i % 3)
	z = p.count(0)
	q = min(p.count(1), p.count(2))
	n = (max(p.count(1), p.count(2)) - q) // 3
	print(z + q + n)


t = int(input())
for w in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	count0 = 0
	count1 = 0
	count2 = 0
	for i in range(n):
		if arr[i] % 3 == 0:
			count0 += 1
		elif arr[i] % 3 == 1:
			count1 += 1
		else:
			count2 += 1
	mini = min(count2, count1)
	count1 = count1 - mini
	count2 = count2 - mini
	count1 = count1 // 3
	count2 = count2 // 3
	ans = count0 + mini + count1 + count2
	print(ans)


from math import *
t = int(input())
while t:
	t -= 1
	s = 0
	n = int(input())
	a = list(map(int, input().split()))
	s = 0
	b = []
	for i in range(n):
		if a[i] % 3 != 0:
			b.append(a[i] % 3)
		else:
			s += 1
	f = b.count(1)
	f1 = len(b) - f
	d = min(f, f1)
	s += d
	f -= d
	f1 -= d
	s += f // 3
	s += f1 // 3
	print(s)


t = int(input())
while t:
	m = int(input())
	l = list(map(int, input().split()))
	c = 0
	d = 0
	e = 0
	for i in range(m):
		if l[i] % 3 == 0:
			c += 1
		elif l[i] % 3 == 1:
			d += 1
		else:
			e += 1
	if d > e:
		c += e
		d -= e
		c += d // 3
	else:
		c += d
		e -= d
		c += e // 3
	t -= 1
	print(c)


from collections import defaultdict as dfd
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	brr = [i % 3 for i in arr if i % 3 != 0]
	cnt = n - len(brr)
	d = dfd(int)
	for i in brr:
		d[i] += 1
	if len(set(d.keys())) == 2:
		val = min(d.values())
		d[1] -= val
		d[2] -= val
		cnt += val
	for (i, j) in d.items():
		cnt += j // 3
		j %= 3
	print(cnt)


query = int(input())
for q in range(query):
	n = int(input())
	arr = list(map(int, input().split()))
	count = [0, 0, 0]
	total = 0
	for i in arr:
		count[i % 3] += 1
	if count[1] == count[2]:
		total = count[0] + count[1]
	elif count[1] >= count[2]:
		total = count[0] + count[2] + (count[1] - count[2]) // 3
	elif count[2] >= count[1]:
		total = count[0] + count[1] + (count[2] - count[1]) // 3
	print(total)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split(' ')))
	b = [0] * 3
	for x in l:
		b[x % 3] += 1
	x = min(b[1], b[2])
	b[1] -= x
	b[2] -= x
	print(b[0] + x + b[1] // 3 + b[2] // 3)


q = int(input())
for i in range(q):
	p = int(input())
	l = [int(i) for i in input().split()]
	a1 = 0
	a2 = 0
	a3 = 0
	for j in l:
		if j % 3 == 0:
			a3 += 1
		if j % 3 == 2:
			a2 += 1
		if j % 3 == 1:
			a1 += 1
	print(a3 + min(a1, a2) + abs(max(a1, a2) - min(a1, a2)) // 3)


for loop in range(int(input())):
	input()
	arr = list(map(int, input().split()))
	arr2 = list(filter(lambda x: not x % 3 == 0, arr))
	arr3 = list(map(lambda x: x % 3, arr2))
	counter = len(arr) - len(arr2)
	while 2 in arr3 and 1 in arr3:
		arr3.remove(2)
		arr3.remove(1)
		counter += 1
	arr4 = list(filter(lambda x: x == 1, arr3))
	arr5 = list(filter(lambda x: x == 2, arr3))
	counter += len(arr4) // 3
	counter += len(arr5) // 3
	print(counter)


t = int(input())
for i in range(0, t):
	n = int(input())
	L = list(map(int, input().split()))
	M = list(map(lambda x: x % 3, L))
	a = 0
	b = 0
	c = 0
	for i in range(0, n):
		if M[i] == 0:
			a += 1
		elif M[i] == 1:
			b += 1
		else:
			c += 1
	z = min(c, b)
	y = c + b - 2 * z
	x = a + z + y // 3
	print(x)


tests = int(input())
for i in range(tests):
	count = 0
	num = int(input())
	numbers = list(map(int, input().split()))
	rest1 = 0
	rest2 = 0
	for n in numbers:
		if n % 3 == 0:
			count += 1
		elif n % 3 == 1:
			rest1 += 1
		elif n % 3 == 2:
			rest2 += 1
	pairs = min(rest1, rest2)
	rest = max(rest1, rest2) - pairs
	count += pairs + int(rest / 3)
	print(count)


for _ in range(int(input())):
	cnt = 0
	num1 = 0
	num2 = 0
	t = int(input())
	a = [int(i) for i in input().split()]
	for i in a:
		if i % 3 == 0:
			cnt += 1
		if i % 3 == 1:
			num1 += 1
		if i % 3 == 2:
			num2 += 1
	left = (num2 - min(num1, num2)) // 3
	print(cnt + min(num1, num2) + (num1 - min(num1, num2)) // 3 + left)


for _ in range(int(input())):
	n = int(input())
	s = [0] * 3
	for x in map(int, input().split()):
		s[x % 3] += 1
	t = min(s[1], s[2])
	print(s[0] + (s[1] - t) // 3 + (s[2] - t) // 3 + t)


t = int(input())
for kase in range(t):
	n = int(input())
	a = sorted(map(lambda x: x % 3, map(int, input().split(' '))))
	cnt = [0, 0, 0]
	for x in a:
		cnt[x] += 1
	ans = cnt[0] + min(cnt[1], cnt[2])
	ans += (max(cnt[1], cnt[2]) - min(cnt[1], cnt[2])) // 3
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(_) for _ in input().split()]
	cnt = [0, 0, 0]
	for j in a:
		cnt[j % 3] += 1
	mi = min(cnt[1], cnt[2])
	ans = cnt[0] + mi + (cnt[1] - mi) // 3 + (cnt[2] - mi) // 3
	print(ans)


t = int(input())
for abc in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	zero = 0
	one = 0
	two = 0
	for i in range(n):
		if a[i] % 3 == 0:
			zero += 1
		elif a[i] % 3 == 1:
			one += 1
		else:
			two += 1
	mini = min(one, two)
	zero += mini
	one -= mini
	two -= mini
	zero += one // 3
	one = one % 3
	zero += two // 3
	two = two % 3
	print(zero)


for i in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	(a, b, c) = (0, 0, 0)
	for (i, x) in enumerate(lst):
		if x % 3 == 0:
			a += 1
		elif x % 3 == 1:
			b += 1
		else:
			c += 1
	res = min(b, c)
	b -= res
	c -= res
	print(a + res + b // 3 + c // 3)


for _ in range(int(input())):
	n = int(input())
	z = 0
	o = 0
	t = 0
	L = list(map(int, input().split()))
	for l in L:
		z += 1 if l % 3 == 0 else 0
		o += 1 if l % 3 == 1 else 0
		t += 1 if l % 3 == 2 else 0
	if o >= t:
		print(z + t + (o - t) // 3)
	else:
		print(z + o + (t - o) // 3)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	x = list(map(int, input().split()))
	r = []
	for i in x:
		r.append(i % 3)
	cnt2 = 0
	cnt1 = 0
	cnt = 0
	for i in r:
		if i == 0:
			cnt += 1
		elif i == 1:
			cnt1 += 1
		else:
			cnt2 += 1
	ans = 0
	minn = min(cnt1, cnt2)
	rem = abs(cnt1 - cnt2)
	rem = int(rem / 3)
	ans = cnt + minn + rem
	print(ans)


queries = int(input())
for query in range(queries):
	n = int(input())
	arr = list(map(int, input().split()))
	mod0 = 0
	mod1 = 0
	mod2 = 0
	for i in arr:
		x = i % 3
		if x == 0:
			mod0 += 1
		elif x == 1:
			mod1 += 1
		elif x == 2:
			mod2 += 1
	if mod1 < mod2:
		ans = mod0 + mod1 + (mod2 - mod1) // 3
	elif mod2 < mod1:
		ans = mod0 + mod2 + (mod1 - mod2) // 3
	else:
		ans = mod0 + mod1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l = [i % 3 for i in l]
	c = l.count(0)
	two = l.count(2)
	one = l.count(1)
	if two >= one:
		c += one
		two -= one
		c += two // 3
	else:
		c += two
		one -= two
		c += one // 3
	print(c)


from collections import Counter

def helper(n):
	pass
q = int(input())
for _ in range(q):
	input()
	arr = map(lambda num: int(num) % 3, input().strip().split(' '))
	count_nums = Counter(arr)
	answer = count_nums[0]
	answer += min(count_nums[1], count_nums[2])
	answer += max(0, abs(count_nums[1] - count_nums[2])) // 3
	print(answer)


N = int(input())
L = [0] * N
for i in range(N):
	n = int(input())
	m = list(map(int, input().split()))
	k_1 = 0
	k_2 = 0
	for j in m:
		if j % 3 == 1:
			k_1 += 1
		elif j % 3 == 2:
			k_2 += 1
		else:
			L[i] += 1
	r = min(k_1, k_2)
	L[i] += r + abs(k_2 - k_1) // 3
for i in L:
	print(i)


test = int(input())
for e in range(test):
	n = int(input())
	a = list(map(int, input().split(' ')))
	a0 = []
	a1 = []
	a2 = []
	c0 = 0
	c1 = 0
	c2 = 0
	for i in range(n):
		if a[i] % 3 == 0:
			a0.append(a[i])
			c0 += 1
		elif a[i] % 3 == 1:
			a1.append(a[i])
			c1 += 1
		else:
			a2.append(a[i])
			c2 += 1
	c0 = c0 + min(c1, c2)
	if c1 > c2:
		c0 += (c1 - c2) // 3
	elif c2 > c1:
		c0 += (c2 - c1) // 3
	print(c0)


t = int(input())
for i in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	cnt = [0] * 1000
	for j in x:
		cnt[j % 3] += 1
	l = min(cnt[1], cnt[2])
	cnt[1] -= l
	cnt[2] -= l
	print(cnt[0] + l + cnt[1] // 3 + cnt[2] // 3)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split(' ')))
	remainders = [0, 0, 0]
	answer = 0
	for ele in a:
		remainders[ele % 3] += 1
	answer += remainders[0]
	answer += min(remainders[1], remainders[2])
	answer += (max(remainders[1], remainders[2]) - min(remainders[1], remainders[2])) // 3
	print(answer)


q = int(input())
for i in range(q):
	n = int(input())
	a = [int(x) for x in input().split()]
	count = 0
	b = 0
	c = 0
	for j in a:
		if j % 3 == 0:
			count += 1
		elif j % 3 == 1:
			b += 1
		else:
			c += 1
	d = min(b, c)
	count += d + (b - d) // 3 + (c - d) // 3
	print(count)


from sys import stdin, stdout
q = int(stdin.readline())
while q != 0:
	n = int(stdin.readline())
	freq = [0] * 3
	v = stdin.readline().split(' ')
	for i in range(n):
		x = int(v[i])
		x %= 3
		freq[x] += 1
	if freq[1] > freq[2]:
		freq[1] -= freq[2]
		print(freq[0] + freq[2] + freq[1] // 3)
	else:
		freq[2] -= freq[1]
		print(freq[0] + freq[1] + freq[2] // 3)
	q -= 1


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	count1 = 0
	count2 = 0
	l = list(map(int, input().split()))
	j = 0
	while j < len(l):
		if l[j] % 3 == 1:
			count1 += 1
			j += 1
		elif l[j] % 3 == 2:
			count2 += 1
			j += 1
		elif l[j] % 3 == 0:
			count += 1
			j += 1
	count = count + min(count1, count2) + int(abs(count1 - count2) / 3)
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	x = 0
	y = 0
	z = 0
	for j in range(n):
		if arr[j] % 3 == 0:
			x += 1
		elif arr[j] % 3 == 1:
			y += 1
		else:
			z += 1
	p = min(y, z)
	print(x + p + (y + z - 2 * p) // 3)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	c1 = 0
	c2 = 0
	c3 = 0
	for i in arr:
		if i % 3 == 1:
			c1 += 1
		elif i % 3 == 2:
			c2 += 1
		else:
			c3 += 1
	ans = c3 + min(c1, c2) + (max(c1, c2) - min(c1, c2)) // 3
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ls = [0, 0]
	cnt = 0
	for i in range(n):
		if arr[i] % 3 == 0:
			cnt += 1
		elif arr[i] % 3 == 1:
			ls[0] += 1
		elif arr[i] % 3 == 2:
			ls[1] += 1
	cnt += min(ls[0], ls[1])
	rem = abs(ls[0] - ls[1])
	if rem > 0:
		cnt += rem // 3
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	a = [ele % 3 for ele in s]
	c0 = 0
	c1 = 0
	c2 = 0
	for ele in a:
		if ele == 0:
			c0 += 1
		elif ele == 1:
			c1 += 1
		else:
			c2 += 1
	ans1 = min(c1, c2)
	ans2 = abs(c1 - c2) // 3
	print(c0 + ans1 + ans2)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	for i in a:
		b.append(i % 3)
	x = b.count(0)
	y = min(b.count(1), b.count(2))
	z = (b.count(1) - y) // 3 + (b.count(2) - y) // 3
	print(x + y + z)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	freq = [0] * 3
	rem = 0
	for i in range(len(a)):
		freq[a[i] % 3] += 1
	ans = freq[0] + min(freq[1], freq[2]) + (freq[1] - min(freq[1], freq[2]) + (freq[2] - min(freq[1], freq[2]))) // 3
	print(ans)


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	t = 0
	s = 0
	for e in a:
		if e % 3 == 1:
			t += 1
		elif e % 3 == 2:
			s += 1
	if t >= s:
		ans = n - (t + s) + s + (t - s) // 3
	else:
		ans = n - (t + s) + t + (s - t) // 3
	print(ans)


from collections import defaultdict
for _ in range(int(input())):
	input()
	c = 0
	rests = defaultdict(int)
	for a in [*map(int, input().split())]:
		if a % 3 == 0:
			c += 1
		else:
			rests[a % 3] += 1
	m = min(rests[1], rests[2])
	rests[1] -= m
	rests[2] -= m
	c += m + rests[1] // 3 + rests[2] // 3
	print(c)


n = int(input())
for i in range(n):
	input()
	a = list(map(int, input().split()))
	a1 = 0
	a2 = 0
	a0 = 0
	for j in range(len(a)):
		if a[j] % 3 == 0:
			a0 += 1
		elif a[j] % 3 == 1:
			a1 += 1
		else:
			a2 += 1
	s1 = min(a1, a2) + a0
	s2 = 0
	(a1, a2) = (a1 - min(a1, a2), a2 - min(a1, a2))
	while a1 and a2:
		s2 += min(a1, a2)
		(a1, a2) = (a1 - min(a1, a2), a2 - min(a1, a2))
	if a1 >= 3:
		s2 += a1 // 3
	if a2 >= 3:
		s2 += a2 // 3
	print(s1 + s2)


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	d = {0: 0, 1: 0, 2: 0}
	for i in l:
		d[i % 3] += 1
	c = d[0]
	a = min(d[1], d[2])
	c += a
	d[1] -= a
	d[2] -= a
	if d[1] != 0:
		c += d[1] // 3
	if d[2] != 0:
		c += d[2] // 3
	print(c)
	t -= 1


def main():
	t = int(input())
	for _ in range(t):
		n = input()
		num = [int(x) % 3 for x in input().split()]
		one = num.count(1)
		two = num.count(2)
		mn = min(one, two)
		print(num.count(0) + mn + (one - mn) // 3 + (two - mn) // 3)
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	k = [0] * 3
	for i in arr:
		k[i % 3] += 1
	ans = k[0]
	minn = min(k[1], k[2])
	ans += minn
	ans += max(0, k[1] - minn) // 3
	ans += max(0, k[2] - minn) // 3
	print(ans)


from collections import Counter
for _ in range(int(input())):
	input()
	nums = Counter((int(i) % 3 for i in input().split()))
	sum_ = nums[0] + min(nums[1], nums[2]) + (nums[1] - min(nums[1], nums[2])) // 3 + (nums[2] - min(nums[1], nums[2])) // 3
	print(sum_)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	lis = []
	c = 0
	for j in range(n):
		if l[j] % 3 == 0:
			c = c + 1
		else:
			lis.append(l[j] % 3)
	c1 = 0
	c2 = 0
	for j in range(len(lis)):
		if lis[j] == 1:
			c1 = c1 + 1
		else:
			c2 = c2 + 1
	q = min(c1, c2)
	if c2 > c1:
		y = c2 - c1
		print(c + c1 + y // 3)
	else:
		x = c1 - c2
		print(c + c2 + x // 3)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	t = I()
	aa = [[I(), LI()] for _ in range(t)]
	r = []
	for (n, a) in aa:
		d = collections.defaultdict(int)
		for c in a:
			d[c % 3] += 1
		k = d[0]
		l = min(d[1], d[2])
		k += l
		d[1] -= l
		k += d[1] // 3
		d[2] -= l
		k += d[2] // 3
		r.append(k)
	return JA(r, '\n')
print(main())


times = int(input())
for i in range(times):
	l = int(input())
	m = [int(x) for x in input().split()]
	remainders = [0, 0, 0]
	for j in m:
		remainders[j % 3] += 1
	print(remainders[0] + min(remainders[1], remainders[2]) + (max(remainders[1], remainders[2]) - min(remainders[1], remainders[2])) // 3)


import sys
n = 0
b = 0
x = 0
for line in sys.stdin:
	if n == 0:
		n = int(line.strip())
	elif b % 2 == 0:
		x = int(line.strip())
		b += 1
	else:
		b += 1
		l = list(map(int, line.strip().split()))
		counter = 0
		c1 = 0
		c2 = 0
		for i in l:
			if i % 3 == 0:
				counter += 1
			elif i % 3 == 1:
				c1 += 1
			else:
				c2 += 1
		counter += min(c1, c2)
		counter += (max(c1, c2) - min(c1, c2)) // 3
		print(counter)
	if n == b // 2:
		sys.exit()


q = int(input())
for i in range(q):
	a = int(input())
	sum = 0
	list1 = [0, 0, 0, 0, 0, 0, 0]
	for j in map(int, input().split()):
		list1[j % 3] += 1
	ans = 0
	t = min(list1[1], list1[2])
	ans += t
	list1[1] -= t
	list1[2] -= t
	ans += list1[1] // 3 + list1[2] // 3
	ans += list1[0]
	print(ans)


for iio in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	a = 0
	b = 0
	c = 0
	for i in range(n):
		x = l[i] % 3
		if x == 0:
			a += 1
		if x == 1:
			b += 1
		if x == 2:
			c += 1
	if b > c:
		print(a + c + (b - c) // 3)
	else:
		print(a + b + (c - b) // 3)


t = int(input())
for i in range(t):
	k = int(input())
	ct = ct1 = ct2 = 0
	l = list(map(int, input().strip().split()))[:k]
	for x in l:
		if x % 3 == 0:
			ct += 1
		elif x % 3 == 1:
			ct1 += 1
		elif x % 3 == 2:
			ct2 += 1
	if ct1 >= ct2:
		ct = ct + ct2
		rem = (ct1 - ct2) // 3
	else:
		ct = ct + ct1
		rem = (ct2 - ct1) // 3
	print(ct + rem)


import sys

def solve():
	sys.stdin.readline()
	a = list(map(int, sys.stdin.readline().split()))
	cnt = [0] * 3
	for x in a:
		cnt[x % 3] += 1
	ans = cnt[0]
	x = min(cnt[1], cnt[2])
	ans += x
	cnt[1] -= x
	cnt[2] -= x
	ans += cnt[1] // 3
	ans += cnt[2] // 3
	print(ans)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [i % 3 for i in a]
	zero = 0
	one = 0
	two = 0
	for i in b:
		if i == 0:
			zero += 1
		elif i == 1:
			one += 1
		else:
			two += 1
	print(zero + min(one, two) + (one - min(one, two)) // 3 + (two - min(two, one)) // 3)


t = int(input())
array = []
array_size = []
for _ in range(t):
	array_size.append(int(input()))
	array.append(list(map(int, input().split())))
for i in array:
	count_1 = 0
	count_2 = 0
	count_3 = 0
	for j in i:
		if j % 3 == 0:
			count_3 += 1
		if j % 3 == 1:
			count_1 += 1
		if j % 3 == 2:
			count_2 += 1
	while count_1 and count_2:
		count_3 += 1
		count_1 -= 1
		count_2 -= 1
	while count_1 >= 3:
		count_3 += 1
		count_1 -= 3
	while count_2 >= 3:
		count_3 += 1
		count_2 -= 3
	print(count_3)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(s) for s in input().split(' ')]
	(ost0, ost1, ost2) = (0, 0, 0)
	col = 0
	for el in a:
		if el % 3 == 0:
			ost0 += 1
		elif el % 3 == 1:
			ost1 += 1
		elif el % 3 == 2:
			ost2 += 1
	col += ost0 + min(ost1, ost2) + (max(ost1, ost2) - min(ost1, ost2)) // 3
	print(col)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) % 3 for x in input().split()]
	ans = 0
	ans += a.count(0)
	(one, two) = (0, 0)
	for i in a:
		if i == 1:
			one += 1
		elif i == 2:
			two += 1
	ans += min(one, two)
	mn = min(one, two)
	one -= mn
	two -= mn
	ans += one // 3
	ans += two // 3
	print(ans)


t = int(input())
from collections import Counter
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	l = [l[i] % 3 for i in range(n)]
	c = Counter(l)
	ans = c[0]
	if min(c[2], c[1]) > 0:
		ans += min(c[2], c[1])
	if abs(c[1] - c[2]) > 0:
		ans += abs(c[1] - c[2]) // 3
	print(ans)
	t -= 1


n = int(input())
for i in range(n):
	rem1 = 0
	rem2 = 0
	rem0 = 0
	a = 0
	k = int(input())
	arr = {}
	str = input()
	arr = str.split()
	for j in range(k):
		arr[j] = int(arr[j])
		if arr[j] % 3 == 1:
			rem1 += 1
		elif arr[j] % 3 == 2:
			rem2 += 1
		else:
			rem0 += 1
	a += min(rem1, rem2)
	a += abs(rem1 - rem2) // 3
	a += rem0
	print(a)


t = int(input())
for query in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		a[i] %= 3
	zeros = a.count(0)
	ones = a.count(1)
	twos = a.count(2)
	m = min(ones, twos)
	ones -= m
	twos -= m
	ans = zeros + m + ones // 3 + twos // 3
	print(ans)


def answer(count):
	out = count[0]
	tmp = min(count[1], count[2])
	count[1] -= tmp
	count[2] -= tmp
	out += tmp
	nokori = max(count[1], count[2])
	tmp2 = nokori // 3
	out += tmp2
	return out
t = int(input())
for i in range(t):
	n = int(input())
	count = [0 for i in range(3)]
	for elm in input().split(' '):
		a = int(elm) % 3
		count[a] += 1
	out = answer(count)
	print(out)


from collections import Counter
t = int(input())
for i in range(t):
	input()
	c = Counter((i % 3 for i in map(int, input().split())))
	mi = min(c[1], c[2])
	ma = max(c[1], c[2])
	print(c[0] + mi + (ma - mi) // 3)


t = int(input())
for _ in range(t):
	n = int(input())
	zero = 0
	one = 0
	two = 0
	arr = list(map(int, input().split()))
	for i in arr:
		if i % 3 == 0:
			zero += 1
		elif i % 3 == 1:
			one += 1
		else:
			two += 1
	minVal = min(one, two)
	answer = minVal
	one -= minVal
	two -= minVal
	answer += one // 3
	answer += two // 3
	answer += zero
	print(answer)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	ans = 0
	one = 0
	two = 0
	for i in A:
		if i % 3 == 0:
			ans += 1
		if i % 3 == 1:
			one += 1
		if i % 3 == 2:
			two += 1
	a = min(one, two)
	ans += a
	one -= a
	two -= a
	ans += one // 3
	ans += two // 3
	print(ans)


t = int(input())
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s1 = 0
	s2 = 0
	for x in a:
		if x % 3 == 1:
			s1 += 1
		if x % 3 == 2:
			s2 += 1
	print(n - s1 - s2 + min(s1, s2) + abs(s1 - s2) // 3)


import math
for usl in range(int(input())):
	length = int(input())
	numbers = input().split()
	numbers2 = []
	divcount = 0
	if len(numbers) >= 1:
		for i in numbers:
			numbers2.append(int(i) % 3)
		onecount = 0
		twocount = 0
		for i in numbers2:
			if i == 1:
				onecount += 1
			if i == 2:
				twocount += 1
			if i == 0:
				divcount += 1
		minim = min(twocount, onecount)
		divcount += minim
		onecount -= minim
		twocount -= minim
		divcount += onecount // 3
		divcount += twocount // 3
	print(divcount)


for j in range(int(input())):
	n = int(input())
	(k, u, p) = (0, 0, 0)
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	for i in range(n):
		if l[i] % 3 == 0:
			k = k + 1
		elif l[i] % 3 == 2:
			p = p + 1
		elif l[i] % 3 == 1:
			u = u + 1
	if u > p:
		k = k + p
		u = u - p
		k = k + u // 3
	else:
		k = k + u
		p = p - u
		k = k + p // 3
	print(k)


t = int(input())
for tt in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	a0 = 0
	a1 = 0
	a2 = 0
	for x in a:
		if x % 3 == 0:
			a0 += 1
		elif x % 3 == 1:
			a1 += 1
		else:
			a2 += 1
	a3 = min(a1, a2)
	a1 -= a3
	a2 -= a3
	ans = a0 + a3
	if a1 > 0:
		ans += a1 // 3
	if a2 > 0:
		ans += a2 // 3
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	A = [int(x) % 3 for x in input().split()]
	c0 = A.count(0)
	c1 = A.count(1)
	c2 = A.count(2)
	if c2 >= c1:
		print(c0 + c1 + (c2 - c1) // 3)
	else:
		print(c0 + c2 + (c1 - c2) // 3)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split(' ')))
	mod = [x % 3 for x in a]
	val = mod.count(0)
	one = mod.count(1)
	two = mod.count(2)
	if one <= two:
		val += one
		two -= one
		one = 0
		more = int(two * 2 / 6)
		val += more
	elif two < one:
		val += two
		one -= two
		two = 0
		more = int(one / 3)
		val += more
	print(val)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	cnt = Counter((int(i) % 3 for i in input().split()))
	v = min(cnt[2], cnt[1])
	cnt[1] -= v
	cnt[2] -= v
	v += cnt[0]
	v += cnt[1] // 3 + cnt[2] // 3
	print(v)


from collections import defaultdict
from sys import stdin

def solve():
	q = int(stdin.readline().strip())
	for _ in range(q):
		stdin.readline()
		a = [int(i) % 3 for i in stdin.readline().strip().split()]
		counts = defaultdict(int)
		for e in a:
			counts[e] += 1
		result = counts[0]
		ones = counts[1]
		twos = counts[2]
		extra = min(ones, twos)
		ones -= extra
		twos -= extra
		result += extra
		result += ones // 3
		result += twos // 3
		print(result)
solve()


n = int(input())
num = []
for i in range(n):
	t = int(input())
	s = list(map(int, input().split()))
	s = [i % 3 for i in s]
	c0 = s.count(0)
	c1 = s.count(1)
	c2 = s.count(2)
	num.append(c0 + min(c1, c2) + (max(c1, c2) - min(c1, c2)) // 3)
for n in num:
	print(n)


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	(q, w, e) = (0, 0, 0)
	for j in range(n):
		if a[j] % 3 == 0:
			q += 1
		elif a[j] % 3 == 1:
			w += 1
		else:
			e += 1
	r = min(w, e)
	q = q + r
	w = w - r
	e = e - r
	if w == 0:
		e = e // 3
		q = q + e
	if e == 0:
		w = w // 3
		q = q + w
	print(q)
	t -= 1


def main():
	tc = int(input())
	for i in range(tc):
		nn = int(input())
		nums = [int(n) for n in input().split()]
		cnt = [0, 0, 0]
		for n in nums:
			if n % 3 == 0:
				cnt[0] = cnt[0] + 1
			elif n % 3 == 1:
				cnt[1] = cnt[1] + 1
			elif n % 3 == 2:
				cnt[2] = cnt[2] + 1
		print(int(cnt[0] + min(cnt[1], cnt[2]) + (max(cnt[2], cnt[1]) - min(cnt[1], cnt[2])) / 3))
main()


t = int(input())
while t != 0:
	n = int(input())
	arr = list(map(int, input().split()))
	cnt = [0] * 3
	for i in arr:
		i %= 3
		cnt[i] += 1
	sum = 0
	k = min(cnt[1], cnt[2])
	cnt[1] -= k
	cnt[2] -= k
	sum += k
	k = int(cnt[1] / 3)
	cnt[1] -= k * 3
	sum += k
	k = int(cnt[2] / 3)
	cnt[2] -= k * 3
	sum += k
	sum += cnt[0]
	print(sum)
	t -= 1


from sys import stdin

def solve(tc):
	t = int(stdin.readline().strip())
	for _ in range(t):
		n = int(stdin.readline().strip())
		cnt = [0, 0, 0]
		li = list(map(int, stdin.readline().split()))
		for num in li:
			cnt[num % 3] += 1
		onetwo = min(cnt[1], cnt[2])
		cnt[0] += onetwo
		cnt[1] -= onetwo
		cnt[2] -= onetwo
		print(cnt[0] + cnt[1] // 3 + cnt[2] // 3)
LOCAL_TEST = not __debug__
if LOCAL_TEST:
	infile = __file__.split('.')[0] + '-test.in'
	stdin = open(infile, 'r')
tcs = int(stdin.readline().strip()) if LOCAL_TEST else 1
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [i % 3 for i in a]
	val1 = b.count(0)
	val2 = min(b.count(1), b.count(2))
	val3 = (b.count(1) - val2) // 3 + (b.count(2) - val2) // 3
	ans.append(val1 + val2 + val3)
print(*ans, sep='\n')


n = int(input())
brr = [0] * n
for i in range(n):
	k = int(input())
	arr = [int(i) % 3 for i in input().split()]
	s = 0
	a0 = arr.count(0)
	a1 = arr.count(1)
	a2 = arr.count(2)
	s += a0
	if a1 > a2:
		s += a2
		a1 -= a2
		s += a1 // 3
	elif a2 > a1:
		s += a1
		a2 -= a1
		s += a2 // 3
	else:
		s += a1
	brr[i] = s
for i in brr:
	print(i)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(j) for j in input().split()]
	res = 0
	count1 = 0
	count2 = 0
	for j in a:
		if j % 3 == 0:
			res += 1
		elif j % 3 == 1:
			count1 += 1
		elif j % 3 == 2:
			count2 += 1
	x = min(count1, count2)
	res += x
	res += (count1 - x) // 3
	res += (count2 - x) // 3
	print(res)