Three guys play a game: first, each person writes down $n$ distinct words of length $3$. Then, they total up the number of points as follows:

if a word was written by one person — that person gets 3 points,

if a word was written by two people — each of the two gets 1 point,

if a word was written by all — nobody gets any points.

In the end, how many points does each player have?


-----Input-----

The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 100$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains an integer $n$ ($1 \leq n \leq 1000$) — the number of words written by each person.

The following three lines each contain $n$ distinct strings — the words written by each person. Each string consists of $3$ lowercase English characters.


-----Output-----

For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $i$-th integer should be the number of points earned by the $i$-th guy.


-----Examples-----

Input
3
1
abc
def
abc
3
orz for qaq
qaq orz for
cod for ces
5
iat roc hem ica lly
bac ter iol ogi sts
bac roc lly iol iat
Output
1 3 1 
2 2 6 
9 11 5


-----Note-----

In the first test case:

The word ${abc}$ was written by the first and third guys — they each get $1$ point.

The word ${def}$ was written by the second guy only — he gets $3$ points.

Difficulty: EASY
Tags: Data structures

Implementation
Skill types: Data structures

Starter code:

Solutions:
T = int(input())
for i in range(T):
	n = int(input())
	P1 = set(input().split())
	P2 = set(input().split())
	P3 = set(input().split())
	(S1, S2, S3) = (0, 0, 0)
	I = P1.intersection(P2, P3)
	P1.difference_update(I)
	P2.difference_update(I)
	P3.difference_update(I)
	I12 = P1.intersection(P2)
	I23 = P2.intersection(P3)
	I31 = P3.intersection(P1)
	S1 += len(I12) * 1 + len(I31) * 1
	S2 += len(I23) * 1 + len(I12) * 1
	S3 += len(I23) * 1 + len(I31) * 1
	P1.difference_update(I12)
	P2.difference_update(I12)
	P2.difference_update(I23)
	P3.difference_update(I23)
	P3.difference_update(I31)
	P1.difference_update(I31)
	S1 += len(P1) * 3
	S2 += len(P2) * 3
	S3 += len(P3) * 3
	print(S1, S2, S3)


N = int(input())
for _ in range(N):
	_ = input()
	set_1 = set(input().split())
	set_2 = set(input().split())
	set_3 = set(input().split())
	set_12 = set_1 & set_2
	set_13 = set_1 & set_3
	set_23 = set_2 & set_3
	set_123 = set_12 & set_3
	p1_1 = len(set_12) + len(set_13) - 2 * len(set_123)
	p3_1 = len(set_1) - len(set_12) - len(set_13) + len(set_123)
	p1_2 = len(set_12) + len(set_23) - 2 * len(set_123)
	p3_2 = len(set_2) - len(set_12) - len(set_23) + len(set_123)
	p1_3 = len(set_13) + len(set_23) - 2 * len(set_123)
	p3_3 = len(set_3) - len(set_23) - len(set_13) + len(set_123)
	print(p1_1 * 1 + p3_1 * 3, p1_2 * 1 + p3_2 * 3, p1_3 * 1 + p3_3 * 3)


t = int(input())
for i in range(t):
	(pl_1, pl_2, pl_3) = (list(), list(), list())
	lst = [pl_1, pl_2, pl_3]
	n = int(input())
	for k in range(3):
		inp = set(input().split())
		lst[k].extend((inp, 3 * n))
	a = pl_1[0].intersection(pl_2[0], pl_3[0])
	if len(a) > 0:
		pl_1[0].difference_update(a)
		pl_2[0].difference_update(a)
		pl_3[0].difference_update(a)
		pl_1[1] -= 3 * len(a)
		pl_2[1] -= 3 * len(a)
		pl_3[1] -= 3 * len(a)
	if len(pl_1[0].intersection(pl_2[0])) > 0:
		pl_1[1] -= 2 * len(pl_1[0].intersection(pl_2[0]))
		pl_2[1] -= 2 * len(pl_1[0].intersection(pl_2[0]))
	if len(pl_1[0].intersection(pl_3[0])) > 0:
		pl_1[1] -= 2 * len(pl_1[0].intersection(pl_3[0]))
		pl_3[1] -= 2 * len(pl_1[0].intersection(pl_3[0]))
	if len(pl_2[0].intersection(pl_3[0])) > 0:
		pl_3[1] -= 2 * len(pl_2[0].intersection(pl_3[0]))
		pl_2[1] -= 2 * len(pl_2[0].intersection(pl_3[0]))
	print(pl_1[1], pl_2[1], pl_3[1])


import sys
input = sys.stdin.readline
t = int(input())
for t_item in range(t):
	n = int(input())
	a = set([i for i in input().split()])
	b = set([i for i in input().split()])
	c = set([i for i in input().split()])
	used = []
	x = 0
	y = 0
	z = 0
	ab = a.intersection(b)
	abc = ab.intersection(c)
	ac = a.intersection(c)
	bc = b.intersection(c)
	x = (len(a) - (len(ab) + len(ac) - len(abc))) * 3 + (len(ab) + len(ac) - 2 * len(abc))
	y = (len(b) - (len(ab) + len(bc) - len(abc))) * 3 + (len(ab) + len(bc) - 2 * len(abc))
	z = (len(c) - (len(ac) + len(bc) - len(abc))) * 3 + (len(ac) + len(bc) - 2 * len(abc))
	print(x, y, z)


import sys
input = sys.stdin.readline

def print(*args, end='\n', sep=' ') -> None:
	sys.stdout.write(sep.join(map(str, args)) + end)

def Solve():
	for t in range(int(input())):
		n = int(input())
		ans = [n * 3] * 3
		a = set(input().split())
		b = set(input().split())
		c = set(input().split())
		Abc = len(a.intersection(b, c))
		ans[0] -= 3 * Abc
		ans[0] -= 2 * (len(a.intersection(b)) + len(a.intersection(c)) - 2 * Abc)
		ans[1] -= 3 * Abc
		ans[1] -= 2 * (len(b.intersection(a)) + len(b.intersection(c)) - 2 * Abc)
		ans[2] -= 3 * Abc
		ans[2] -= 2 * (len(c.intersection(b)) + len(c.intersection(a)) - 2 * Abc)
		print(*ans)
Solve()


t = int(input())
for i in range(0, t):
	g = int(input())
	arr1 = input()
	arr1 = arr1.split(' ')
	arr2 = input()
	arr2 = arr2.split(' ')
	arr3 = input()
	arr3 = arr3.split(' ')
	p1 = 0
	p2 = 0
	p3 = 0
	s1 = set(arr1)
	s2 = set(arr2)
	s3 = set(arr3)
	s12 = s1.intersection(s2)
	s23 = s2.intersection(s3)
	s13 = s1.intersection(s3)
	s123 = s12.intersection(s3)
	s12 = len(s12)
	s13 = len(s13)
	s23 = len(s23)
	s1 = len(s1)
	s2 = len(s2)
	s3 = len(s3)
	s123 = len(s123)
	os1 = s1 - s12 - s13 + s123
	os2 = s2 - s12 - s23 + s123
	os3 = s3 - s23 - s13 + s123
	s1score = 3 * os1 + s12 + s13 - 2 * s123
	s2score = 3 * os2 + s23 + s12 - 2 * s123
	s3score = 3 * os3 + s23 + s13 - 2 * s123
	print(s1score, s2score, s3score)


t = int(input())
while t > 0:
	n = int(input())
	p1 = input().split()
	p2 = input().split()
	p3 = input().split()
	s1 = 0
	s2 = 0
	s3 = 0
	p12 = list(set(p1) & set(p2))
	p23 = list(set(p2) & set(p3))
	p13 = list(set(p1) & set(p3))
	p123 = list(set(p12) & set(p23))
	s1 = 3 * (len(p1) - len(p12) - len(p13) + len(p123)) + len(p12) + len(p13) - 2 * len(p123)
	s2 = 3 * (len(p2) - len(p12) - len(p23) + len(p123)) + len(p12) + len(p23) - 2 * len(p123)
	s3 = 3 * (len(p3) - len(p23) - len(p13) + len(p123)) + len(p23) + len(p13) - 2 * len(p123)
	print(s1, s2, s3)
	t -= 1


for _ in range(int(input())):
	x = int(input())
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	(c1, c2, c3, c4) = (len(a & b), len(b & c), len(a & c), len(a & b & c))
	first = 3 * x - 2 * (c1 + c3) + c4
	second = 3 * x - 2 * (c1 + c2) + c4
	third = 3 * x - 2 * (c2 + c3) + c4
	print(first, second, third)


for _ in range(int(input())):
	n = int(input())
	p1 = set(input().split())
	p2 = set(input().split())
	p3 = set(input().split())
	(s1, s2, s3) = (0, 0, 0)
	i3 = p1.intersection(p2, p3)
	p1 = p1.difference(i3)
	p2 = p2.difference(i3)
	p3 = p3.difference(i3)
	i3 = p1.intersection(p2)
	p1 = p1.difference(i3)
	p2 = p2.difference(i3)
	s1 += len(i3)
	s2 += len(i3)
	i3 = p2.intersection(p3)
	p2 = p2.difference(i3)
	p3 = p3.difference(i3)
	s2 += len(i3)
	s3 += len(i3)
	i3 = p3.intersection(p1)
	p1 = p1.difference(i3)
	p3 = p3.difference(i3)
	s3 += len(i3)
	s1 += len(i3)
	s1 += len(p1) * 3
	s2 += len(p2) * 3
	s3 += len(p3) * 3
	print(s1, s2, s3)


def solution():
	n = int(input())
	(points1, points2, points3) = (0, 0, 0)
	words1 = set(input().split())
	words2 = set(input().split())
	words3 = set(input().split())
	union123 = words1 & words2 & words3
	words1 -= union123
	words2 -= union123
	words3 -= union123
	union12 = words1 & words2
	points1 += len(union12)
	points2 += len(union12)
	words1 -= union12
	words2 -= union12
	union13 = words1 & words3
	points1 += len(union13)
	points3 += len(union13)
	words1 -= union13
	words3 -= union13
	union23 = words2 & words3
	points2 += len(union23)
	points3 += len(union23)
	words2 -= union23
	words3 -= union23
	points1 += 3 * len(words1)
	points2 += 3 * len(words2)
	points3 += 3 * len(words3)
	print(points1, points2, points3)

def main():
	t = int(input())
	while t:
		solution()
		t -= 1
main()


t = int(input())
for i in range(0, t):
	n = int(input())
	L = set(input().split())
	M = set(input().split())
	N = set(input().split())
	(a, b, c) = (0, 0, 0)
	K = L & M & N
	L = L - K
	M = M - K
	N = N - K
	n = len(L)
	C = L & M
	D = L & N
	E = M & N
	L = L - C - D
	M = M - C - E
	N = N - D - E
	a = 3 * len(L) + len(C) + len(D)
	b = 3 * len(M) + len(C) + len(E)
	c = 3 * len(N) + len(D) + len(E)
	print(a, b, c)


def solve():
	n = int(input())
	l1 = set(input().split())
	l2 = set(input().split())
	l3 = set(input().split())
	a = 0
	b = 0
	c = 0
	all = len(l1 & l2 & l3)
	ab = len(l1 & l2) - all
	bc = len(l2 & l3) - all
	ac = len(l1 & l3) - all
	a += ab + ac + 3 * (len(l1) - (all + ab + ac))
	b += ab + bc + 3 * (len(l2) - (all + ab + bc))
	c += bc + ac + 3 * (len(l3) - (all + bc + ac))
	print(a, b, c)
t = int(input())
while t > 0:
	solve()
	t -= 1


def sp(la, all, ab, ac):
	return (la - all - ab - ac) * 3 + ab + ac
n = int(input())
for i in range(n):
	p = int(input())
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	la = len(a)
	lb = len(b)
	lc = len(c)
	all = len(a.intersection(b).intersection(c))
	ab = len(b.intersection(a)) - all
	bc = len(b.intersection(c)) - all
	ca = len(c.intersection(a)) - all
	print(sp(la, all, ab, ca), sp(lb, all, bc, ab), sp(lc, all, ca, bc))


import sys

def checkScore(num, w1, w2, w3):
	w1 = set(w1.split())
	w2 = set(w2.split())
	w3 = set(w3.split())
	s1 = 3 * num
	s2 = 3 * num
	s3 = 3 * num
	for word in w1:
		if word in w2:
			if word in w3:
				s1 -= 3
				s2 -= 3
				s3 -= 3
				w2.remove(word)
				w3.remove(word)
			else:
				s1 -= 2
				s2 -= 2
				w2.remove(word)
		elif word in w3:
			s1 -= 2
			s3 -= 2
			w3.remove(word)
	for word in w2:
		if word in w3:
			s2 -= 2
			s3 -= 2
	print(s1, s2, s3)

def main():
	num = int(sys.stdin.readline())
	for line in range(num):
		wordLength = int(sys.stdin.readline())
		w1 = sys.stdin.readline()
		w2 = sys.stdin.readline()
		w3 = sys.stdin.readline()
		checkScore(wordLength, w1, w2, w3)
main()


x = int(input())
for k in range(x):
	n = int(input())
	first = input().split()
	second = input().split()
	third = input().split()
	(res1, res2, res3) = (3 * n, 3 * n, 3 * n)
	set1 = set(first)
	set2 = set(second)
	set3 = set(third)
	allset = set1 & set2 & set3
	res1 -= 3 * len(allset)
	res2 -= 3 * len(allset)
	res3 -= 3 * len(allset)
	set1 -= allset
	set2 -= allset
	set3 -= allset
	res1 -= 2 * (len(set1 & set2) + len(set1 & set3))
	res2 -= 2 * (len(set1 & set2) + len(set2 & set3))
	res3 -= 2 * (len(set3 & set2) + len(set1 & set3))
	print(res1, ' ', res2, ' ', res3)


t = int(input())
for i in range(t):
	n = int(input())
	c1 = 0
	c2 = 0
	c3 = 0
	l1 = set(input().split())
	l2 = set(input().split())
	l3 = set(input().split())
	cno1 = len(l1.difference(l2).difference(l3))
	cno2 = len(l2.difference(l1).difference(l3))
	cno6 = len(l3.difference(l1).difference(l2))
	cno3 = len(l1.intersection(l2).difference(l3))
	cno4 = len(l2.intersection(l3).difference(l1))
	cno5 = len(l3.intersection(l1).difference(l2))
	c1 += 3 * cno1 + cno3 + cno5
	c2 += 3 * cno2 + cno3 + cno4
	c3 += 3 * cno6 + cno4 + cno5
	print(str(c1) + ' ' + str(c2) + ' ' + str(c3))


def solve():
	for _ in range(int(input())):
		n = int(input())
		x = set(input().split())
		y = set(input().split())
		z = set(input().split())
		a = 0
		b = 0
		c = 0
		temp = set(x)
		for w in temp:
			if w in y and w in z:
				x.remove(w)
				y.remove(w)
				z.remove(w)
			elif w in y:
				a += 1
				b += 1
				x.remove(w)
				y.remove(w)
			elif w in z:
				a += 1
				c += 1
				x.remove(w)
				z.remove(w)
		temp = set(y)
		for w in temp:
			if w in z:
				b += 1
				c += 1
				y.remove(w)
				z.remove(w)
		a += 3 * len(x)
		b += 3 * len(y)
		c += 3 * len(z)
		print(a, b, c)
solve()


def get():
	return set(input().split())
for _ in range(int(input())):
	input()
	a = get()
	b = get()
	c = get()
	every = a & b & c
	a -= every
	b -= every
	c -= every
	ab = a & b
	ac = a & c
	bc = b & c
	a = a - ab - ac
	b = b - ab - bc
	c = c - ac - bc
	print(len(ab) + len(ac) + 3 * len(a), len(ab) + len(bc) + 3 * len(b), len(bc) + len(ac) + 3 * len(c))


I = lambda : input().split(' ')
for i in range(int(*I())):
	I()
	(a, b, c) = ({*I()}, {*I()}, {*I()})
	for i in range(3):
		print(2 * len(a - b - c) + len(a) - len(a & b & c), end=' ')
		(a, b, c) = (b, c, a)
	print()


def f(A, B, C, k):
	(set_a, set_b, set_c) = (set(A), set(B), set(C))
	x1 = len(set_a.intersection(set_b).intersection(set_c))
	x2 = len(set_a.intersection(set_c) - set_b)
	x4 = len(set_a.intersection(set_b) - set_c)
	x3 = len(set_b.intersection(set_c) - set_a)
	k1 = (k - x1 - x4 - x2) * 3 + x2 + x4
	k2 = (k - x1 - x3 - x4) * 3 + x3 + x4
	k3 = (k - x1 - x2 - x3) * 3 + x2 + x3
	return f'{k1} {k2} {k3}'
t = int(input())
for _ in range(t):
	k = int(input())
	A = input().split()
	B = input().split()
	C = input().split()
	print(f(A, B, C, k))


t = int(input())
for _ in range(t):
	n = int(input())
	x = set(input().split(' '))
	y = set(input().split(' '))
	z = set(input().split(' '))
	cp1 = cp2 = cp3 = n * 3
	vse = x.intersection(y, z)
	xy = x.intersection(y)
	yz = z.intersection(y)
	xz = x.intersection(z)
	t = len(vse)
	cxy = len(xy)
	cyz = len(yz)
	cxz = len(xz)
	cp1 += -2 * cxy - 2 * cxz + t
	cp2 += -2 * cxy - 2 * cyz + t
	cp3 += -2 * cxz - 2 * cyz + t
	print(cp1, cp2, cp3)


for _ in range(int(input())):
	n = int(input())
	a = [i for i in input().split()]
	b = [i for i in input().split()]
	c = [i for i in input().split()]
	a = set(a)
	b = set(b)
	c = set(c)
	pa = pb = pc = 3 * n
	z = a.intersection(b)
	z2 = a.intersection(c)
	z3 = b.intersection(c)
	z4 = a.intersection(c).intersection(b)
	p = len(z4)
	if p:
		pa -= p * 3
		pb -= p * 3
		pc -= p * 3
	if z2:
		z2 = len(z2) - p
		pa -= z2 * 2
		pc -= z2 * 2
	if z3:
		z3 = len(z3) - p
		pc -= z3 * 2
		pb -= z3 * 2
	if z:
		z = len(z) - p
		pa -= z * 2
		pb -= z * 2
	print(pa, pb, pc)


t = int(input())
for i in range(t):
	n = int(input())
	s1 = input().split()
	s2 = input().split()
	s3 = input().split()
	si12 = set(s1).intersection(set(s2))
	si13 = set(s1).intersection(set(s3))
	si23 = set(s2).intersection(set(s3))
	sa = set(s2).intersection(si13)
	sc1 = 3 * n - 2 * (len(si12) + len(si13) - 2 * len(sa)) - 3 * len(sa)
	sc2 = 3 * n - 2 * (len(si12) + len(si23) - 2 * len(sa)) - 3 * len(sa)
	sc3 = 3 * n - 2 * (len(si23) + len(si13) - 2 * len(sa)) - 3 * len(sa)
	print(str(sc1) + ' ' + str(sc2) + ' ' + str(sc3))


def check(s1, s2, s3, n):
	l1 = s1.split()
	l2 = s2.split()
	l3 = s3.split()
	p1 = list(set(l1) & set(l2))
	p2 = list(set(l3) & set(l2))
	p3 = list(set(l1) & set(l3))
	p4 = list(set(p1) & set(l3))
	a = 1 * len(p1) + len(p3) - 2 * len(p4) + 3 * (len(l1) - len(p1) - len(p3) + len(p4))
	b = 1 * len(p1) + len(p2) - 2 * len(p4) + 3 * (len(l2) - len(p1) - len(p2) + len(p4))
	c = 1 * len(p2) + len(p3) - 2 * len(p4) + 3 * (len(l3) - len(p2) - len(p3) + len(p4))
	print(a, b, c)
n = int(input())
for i in range(n):
	l = int(input())
	s1 = input()
	s2 = input()
	s3 = input()
	check(s1, s2, s3, l)


N = int(input())
for i in range(N):
	len_s = int(input())
	s_1 = set(input().split())
	s_2 = set(input().split())
	s_3 = set(input().split())
	(res_1, res_2, res_3) = (0, 0, 0)
	for el in s_1:
		if el in s_2 or el in s_3:
			if el in s_2 and el in s_3:
				s_2.remove(el)
				s_3.remove(el)
				continue
			elif el in s_2:
				s_2.remove(el)
				res_1 += 1
				res_2 += 1
			else:
				s_3.remove(el)
				res_1 += 1
				res_3 += 1
		else:
			res_1 += 3
	for el in s_2:
		if el in s_3:
			s_3.remove(el)
			res_2 += 1
			res_3 += 1
		else:
			res_2 += 3
	res_3 += len(s_3) * 3
	print(res_1, res_2, res_3)


t = int(input())
lst = []
for i in range(t):
	n = int(input())
	s1 = set(input().split())
	s2 = set(input().split())
	s3 = set(input().split())
	m1 = s1 - s2 - s3
	m2 = s2 - s1 - s3
	m3 = s3 - s2 - s1
	cnt1 = len(m1) * 3
	cnt2 = len(m2) * 3
	cnt3 = len(m3) * 3
	m123 = s1 & s2 & s3
	m12 = s1 & s2
	m13 = s1 & s3
	m23 = s2 & s3
	m1213 = (m12 | m13) - m123
	m2123 = (m12 | m23) - m123
	m3132 = (m13 | m23) - m123
	cnt1 += len(m1213)
	cnt2 += len(m2123)
	cnt3 += len(m3132)
	lst.append([cnt1, cnt2, cnt3])
for l in lst:
	print(' '.join(map(str, l)))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

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

def getscore(l, m, n):
	lc = mc = nc = 0
	dl = {}
	dm = {}
	dn = {}
	for i in l:
		dl[i] = 1
		lc += 3
	for i in m:
		dm[i] = 1
		if i in dl:
			lc -= 2
			mc += 1
		else:
			mc += 3
	for i in n:
		if i in dl and i in dm:
			lc -= 1
			mc -= 1
		elif i in dl:
			nc += 1
			lc -= 2
		elif i in dm:
			mc -= 2
			nc += 1
		else:
			nc += 3
	print(lc, mc, nc)
t = inp()
for _ in range(t):
	n = int(input())
	l = input().strip().split(' ')
	m = input().strip().split(' ')
	n = input().strip().split(' ')
	getscore(l, m, n)


for _ in range(int(input())):
	n = int(input())
	l1 = set(map(str, input().split()))
	l2 = set(map(str, input().split()))
	l3 = set(map(str, input().split()))
	com1 = len(l1 & l2 & l3)
	com2 = len(l1 & l2)
	com3 = len(l1 & l3)
	com4 = len(l2 & l3)
	p1 = n * 3 - 2 * (com2 + com3 - 2 * com1) - 3 * com1
	p2 = n * 3 - 2 * (com2 + com4 - 2 * com1) - 3 * com1
	p3 = n * 3 - 2 * (com4 + com3 - 2 * com1) - 3 * com1
	print(p1, p2, p3)


for _ in range(int(input())):
	n = int(input())
	L1 = list(input().split())
	L2 = list(input().split())
	L3 = list(input().split())
	L = L1 + L2 + L3
	t = 0
	Ls = set(L)
	s = len(Ls)
	com_L1_L2 = 2 * n - len(set(L1 + L2))
	com_L1_L3 = 2 * n - len(set(L1 + L3))
	com_L3_L2 = 2 * n - len(set(L3 + L2))
	com_three = s + com_L1_L2 + com_L1_L3 + com_L3_L2 - 3 * n
	t = com_three
	uL12 = com_L1_L2 - com_three
	uL13 = com_L1_L3 - com_three
	uL32 = com_L3_L2 - com_three
	x = 3 * (n - (com_L1_L2 + com_L1_L3 - t)) + uL12 + uL13
	y = 3 * (n - (com_L1_L2 + com_L3_L2 - t)) + uL12 + uL32
	z = 3 * (n - (com_L1_L3 + com_L3_L2 - t)) + uL13 + uL32
	print(' '.join(list(map(str, [x, y, z]))))


for _ in range(int(input())):
	n = int(input())
	s1 = set()
	s2 = set()
	s3 = set()
	for i in range(3):
		s = input().split()
		if i == 0:
			for x in s:
				s1.add(x)
		elif i == 1:
			for x in s:
				s2.add(x)
		else:
			for x in s:
				s3.add(x)
	s1s2 = len(s1.intersection(s2))
	s2s3 = len(s2.intersection(s3))
	s1s3 = len(s1.intersection(s3))
	s1s2s3 = len(s1.intersection(s2, s3))
	p1 = (s1s2 - s1s2s3) * 1 + (s1s3 - s1s2s3) * 1 + (n - s1s3 - s1s2 + s1s2s3) * 3
	p2 = (s2s3 - s1s2s3) * 1 + (s1s2 - s1s2s3) * 1 + (n - s1s2 - s2s3 + s1s2s3) * 3
	p3 = (s1s3 - s1s2s3) * 1 + (s2s3 - s1s2s3) * 1 + (n - s1s3 - s2s3 + s1s2s3) * 3
	print(p1, p2, p3)


def word(a, b, c):
	result = 0
	for j in a:
		if j in b and j in c:
			continue
		elif j in b or j in c:
			result += 1
		else:
			result += 3
	return result
for i in range(int(input())):
	n = int(input())
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	print(word(a, b, c), word(b, c, a), word(c, a, b))


def word(a, b, c):
	g = 0
	for j in a:
		if j in b and j in c:
			g += 0
		elif j in b or j in c:
			g += 1
		else:
			g += 3
	return g
for i in range(int(input())):
	n = int(input())
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	d = []
	l = word(a, b, c)
	d.append(l)
	l = word(b, c, a)
	d.append(l)
	l = word(c, a, b)
	d.append(l)
	print(*d)


for _ in range(int(input())):
	n = int(input())
	list1 = set(input().split())
	list2 = set(input().split())
	list3 = set(input().split())
	num1 = num2 = num3 = 0
	num4 = 0
	for i in list1:
		if i in list2 and i in list3:
			num4 += 1
		elif i in list2:
			num1 += 1
			num2 += 1
		elif i in list3:
			num1 += 1
			num3 += 1
	for j in list2:
		if j in list3 and j not in list1:
			num2 += 1
			num3 += 1
	z = ''
	z = z + str(3 * (n - num1 - num4) + num1) + ' ' + str(3 * (n - num2 - num4) + num2) + ' ' + str(3 * (n - num3 - num4) + num3)
	print(z)


def solve():
	for _ in range(int(input())):
		n = int(input())
		x = set(input().split())
		y = set(input().split())
		z = set(input().split())
		vis = set()
		a = 0
		b = 0
		c = 0
		count_a = count_b = count_c = 0
		for w in x:
			if w in y and w in z and (w not in vis):
				count_c += 1
				count_a += 1
				count_b += 1
			elif w in y and w not in vis:
				a += 1
				b += 1
				count_a += 1
				count_b += 1
			elif w in z and w not in vis:
				a += 1
				c += 1
				count_a += 1
				count_c += 1
			vis.add(w)
		for w in y:
			if w in z and w not in vis:
				b += 1
				c += 1
				count_c += 1
				count_b += 1
				vis.add(w)
		a += 3 * (n - count_a)
		b += 3 * (n - count_b)
		c += 3 * (n - count_c)
		print(a, b, c)
solve()


def getPoints(a, b, c):
	ans = 0
	for i in a:
		if i in b and i in c:
			continue
		elif i in b or i in c:
			ans += 1
		else:
			ans += 3
	return ans
for i in range(int(input())):
	n = int(input())
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	print(getPoints(a, b, c), getPoints(b, a, c), getPoints(c, a, b))


from math import *
from collections import Counter

def solve():
	n = int(input())
	p1 = set(input().split())
	p2 = set(input().split())
	p3 = set(input().split())
	s1 = 0
	s2 = 0
	s3 = 0
	cnt = 0
	for i in p1:
		t2 = i in p2
		t3 = i in p3
		if t2 and t3:
			cnt += 1
			continue
		elif t2:
			s1 += 1
			s2 += 1
		elif t3:
			s1 += 1
			s3 += 1
			cnt += 1
		else:
			s1 += 3
	for i in p2:
		t1 = i in p1
		t3 = i in p3
		if t1 and t3:
			continue
		elif t3:
			cnt += 1
			s2 += 1
			s3 += 1
		elif t1:
			continue
		else:
			s2 += 3
	for i in p3:
		t1 = i in p1
		t2 = i in p2
		if t1 and t2:
			continue
		elif t1:
			continue
		elif t2:
			continue
		else:
			s3 += 3
	print(s1, s2, s3)
for _ in range(int(input())):
	solve()


def point_calculator(a, b, c):
	ans = 0
	for item in a:
		if item in b and item in c:
			continue
		elif item in b or item in c:
			ans += 1
		else:
			ans += 3
	return ans
n = int(input())
for _ in range(n):
	l = int(input())
	p1 = set(input().split(' '))
	p2 = set(input().split(' '))
	p3 = set(input().split(' '))
	print(point_calculator(p1, p2, p3), point_calculator(p2, p1, p3), point_calculator(p3, p2, p1))


def claculate(p, q, r):
	ans = 0
	for i in p:
		if i in q and i in r:
			continue
		elif i in q or i in r:
			ans += 1
		else:
			ans += 3
	return ans
for _ in range(int(input())):
	n = int(input())
	a = set(input().split(' '))
	b = set(input().split(' '))
	c = set(input().split(' '))
	print(claculate(a, b, c), claculate(b, a, c), claculate(c, a, b))


def C():
	n = int(input())
	score1 = 0
	score2 = 0
	score3 = 0
	words1 = set(input().split())
	words2 = set(input().split())
	words3 = set(input().split())
	for word in words1:
		if word in words2:
			words2.remove(word)
			if word in words3:
				words3.remove(word)
				continue
			score1 += 1
			score2 += 1
			continue
		if word in words3:
			words3.remove(word)
			if word in words2:
				words2.remove(word)
				continue
			score1 += 1
			score3 += 1
			continue
		score1 += 3
	for word in words2:
		if word in words3:
			words3.remove(word)
			score2 += 1
			score3 += 1
			continue
		score2 += 3
	score3 += 3 * len(words3)
	return (score1, score2, score3)
t = int(input())
answers = []
for _ in range(t):
	answers.append(C())
for answer in answers:
	print(*answer)


def solve(s1, s2, s3):
	score = 0
	for i in s1:
		if i in s2 and i in s3:
			score += 0
		elif i in s2 or i in s3:
			score += 1
		else:
			score += 3
	return score
for T in range(int(input())):
	N = input()
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	print(solve(a, b, c), solve(b, c, a), solve(c, b, a))


t = int(input())

def f(a, b, c):
	ans = 0
	m = {}
	for x in a:
		m[x] = 3
	for x in b:
		if x not in m:
			m[x] = 3
		else:
			m[x] = 1
	for x in c:
		if x not in m:
			m[x] = 3
		elif m[x] == 3:
			m[x] = 1
		else:
			m[x] = 0
	ans1 = ans2 = ans3 = 0
	for x in a:
		ans1 += m[x]
	for x in b:
		ans2 += m[x]
	for x in c:
		ans3 += m[x]
	print(ans1, ans2, ans3)
for i in range(t):
	n = int(input())
	p1 = input().split()
	p2 = input().split()
	p3 = input().split()
	f(p1, p2, p3)


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	a = set(map(str, input().split()))
	b = set(map(str, input().split()))
	c = set(map(str, input().split()))
	abc = a.intersection(b, c)
	ab = a.intersection(b)
	ac = a.intersection(c)
	bc = b.intersection(c)
	if abc.issubset(ab):
		ab.difference_update(abc)
	if abc.issubset(ac):
		ac.difference_update(abc)
	if abc.issubset(bc):
		bc.difference_update(abc)
	print(len(abc) * 0 + len(ab) * 1 + len(ac) * 1 + (n - len(abc) - len(ab) - len(ac)) * 3, end=' ')
	print(len(abc) * 0 + len(bc) * 1 + len(ab) * 1 + (n - len(abc) - len(bc) - len(ab)) * 3, end=' ')
	print(len(abc) * 0 + len(bc) * 1 + len(ac) * 1 + (n - len(abc) - len(bc) - len(ac)) * 3)


for _ in range(int(input())):
	n = int(input())
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	x = len(a - b - c) * 3 + len((a & b) - c) + len((a & c) - b)
	y = len(b - a - c) * 3 + len((b & a) - c) + len((b & c) - a)
	z = len(c - a - b) * 3 + len((c & a) - b) + len((c & b) - a)
	print(x, y, z)


for i in range(int(input())):
	n = int(input())
	set1 = set(input().split())
	set2 = set(input().split())
	set3 = set(input().split())
	all1 = set1.intersection(set2, set3)
	set1 -= all1
	set2 -= all1
	set3 -= all1
	set12 = set1.intersection(set2)
	set13 = set1.intersection(set3)
	set23 = set2.intersection(set3)
	k1 = len(set12) + len(set13)
	k2 = len(set12) + len(set23)
	k3 = len(set13) + len(set23)
	set1 -= set12.union(set13)
	set2 -= set12.union(set23)
	set3 -= set13.union(set23)
	k1 += len(set1) * 3
	k2 += len(set2) * 3
	k3 += len(set3) * 3
	print(k1, k2, k3)


def solve(l1, l2, l3):
	score = 0
	for k in l1:
		if k in l2 and k in l3:
			score += 0
		elif k in l2 or k in l3:
			score += 1
		else:
			score += 3
	return score
for i in range(int(input())):
	n = int(input())
	a = set(input().split(' '))
	b = set(input().split(' '))
	c = set(input().split(' '))
	print(solve(a, b, c), solve(b, c, a), solve(c, b, a))


def solve():
	n = int(input())
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	(a1, b1, c1) = (0, 0, 0)
	for elem in a:
		if elem in b and elem in c:
			pass
		elif elem in b or elem in c:
			a1 = a1 + 1
		else:
			a1 = a1 + 3
	for elem in b:
		if elem in a and elem in c:
			pass
		elif elem in a or elem in c:
			b1 = b1 + 1
		else:
			b1 = b1 + 3
	for elem in c:
		if elem in b and elem in a:
			pass
		elif elem in b or elem in a:
			c1 = c1 + 1
		else:
			c1 = c1 + 3
	print(a1, b1, c1)
tests_nr = int(input())
for test in range(tests_nr):
	solve()


import sys

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		st1 = set(input().split())
		st2 = set(input().split())
		st3 = set(input().split())
		a = len(st1 - (st2 | st3)) * 3
		a += len((st1 & st2) - st3)
		a += len((st1 & st3) - st2)
		b = len(st2 - (st1 | st3)) * 3
		b += len((st1 & st2) - st3)
		b += len((st3 & st2) - st1)
		c = len(st3 - (st1 | st2)) * 3
		c += len((st1 & st3) - st2)
		c += len((st3 & st2) - st1)
		print(a, b, c)
main()


for i in range(int(input())):
	n = int(input())
	p1 = input().split()
	p2 = input().split()
	p3 = input().split()
	sp1 = set(p1)
	sp2 = set(p2)
	sp3 = set(p3)
	a1 = 0
	a2 = 0
	a3 = 0
	for j in p1:
		if j not in sp2 and j not in sp3:
			a1 += 3
		elif j not in sp2 or j not in sp3:
			a1 += 1
	for j in p2:
		if j not in sp1 and j not in sp3:
			a2 += 3
		elif j not in sp1 or j not in sp3:
			a2 += 1
	for j in p3:
		if j not in sp2 and j not in sp1:
			a3 += 3
		elif j not in sp2 or j not in sp1:
			a3 += 1
	print(a1, a2, a3)


I = input
for _ in [0] * int(I()):
	I()
	(a, b, c) = ({*I().split()} for _ in [0] * 3)
	print(*(3 * len(x - y - z) + len(x & y - z) + len(x & z - y) for (x, y, z) in ((a, b, c), (b, a, c), (c, a, b))))


for i in range(int(input())):
	n = int(input())
	c1 = c2 = c3 = 0
	comp1 = set(input().split())
	comp2 = set(input().split())
	comp3 = set(input().split())
	x = comp2 | comp3
	c1 += 3 * len(comp1 - x)
	c1 += len(comp2 & comp1 - comp3)
	c1 += len(comp3 & comp1 - comp2)
	x = comp1 | comp3
	c2 += 3 * len(comp2 - x)
	c2 += len(comp2 & comp1 - comp3)
	c2 += len(comp2 & comp3 - comp1)
	x = comp1 | comp2
	c3 += 3 * len(comp3 - x)
	c3 += len(comp3 & comp1 - comp2)
	c3 += len(comp2 & comp3 - comp1)
	print(c1, c2, c3)


from xml.dom.expatbuilder import parseString
for i in range(int(input())):
	input()
	res1 = 0
	res2 = 0
	res3 = 0
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	set1 = a.intersection(b)
	res = set1.intersection(c)
	a = a - set(res)
	b = b - set(res)
	c = c - set(res)
	temp = a.intersection(b)
	res1 += len(temp)
	res2 += len(temp)
	a = a - set(temp)
	b = b - set(temp)
	temp = a.intersection(c)
	res1 += len(temp)
	res3 += len(temp)
	a = a - set(temp)
	c = c - set(temp)
	temp = b.intersection(c)
	res2 += len(temp)
	res3 += len(temp)
	c = c - set(temp)
	b = b - set(temp)
	print(res1 + len(a) * 3, end=' ')
	print(res2 + len(b) * 3, end=' ')
	print(res3 + len(c) * 3, end='')
	print()


for _ in range(int(input())):
	c_word = int(input())
	(line1, line2, line3) = (set(input().split()), set(input().split()), set(input().split()))
	print(3 * len(line1.difference(line3.union(line2))) + len(line1.intersection(line3.symmetric_difference(line2))), end=' ')
	print(3 * len(line2.difference(line3.union(line1))) + len(line2.intersection(line3.symmetric_difference(line1))), end=' ')
	print(3 * len(line3.difference(line1.union(line2))) + len(line3.intersection(line1.symmetric_difference(line2))), end=' ')
	print()


from itertools import chain

def solution(w1, w2, w3):
	res = [0, 0, 0]
	m = {}
	for word in list(chain(w1, w2, w3)):
		if word in m:
			m[word] += 1
		else:
			m[word] = 1
	for w in w1:
		if m[w] == 3:
			continue
		elif m[w] == 2:
			res[0] += 1
		else:
			res[0] += 3
	for w in w2:
		if m[w] == 3:
			continue
		elif m[w] == 2:
			res[1] += 1
		else:
			res[1] += 3
	for w in w3:
		if m[w] == 3:
			continue
		elif m[w] == 2:
			res[2] += 1
		else:
			res[2] += 3
	return res
n = int(input())
for _ in range(n):
	a = int(input())
	w1 = list(input().strip().split())
	w2 = list(input().strip().split())
	w3 = list(input().strip().split())
	print(*solution(w1, w2, w3))


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		words = {}
		score = [0, 0, 0]
		player_input = [[], [], []]
		for player in range(3):
			player_input[player] = input().split(' ')
			for w in player_input[player]:
				if not w in words:
					words[w] = 3
				elif words[w] == 3:
					words[w] = 1
				else:
					words[w] = 0
		for player in range(3):
			for w in player_input[player]:
				score[player] += words[w]
		print('{0} {1} {2}'.format(*score))
main()


t = int(input())
while t:
	first = second = third = 0
	n = int(input())
	u = {}
	d = {}
	words = list(input().split())
	for word in words:
		u[word] = 1
		first += 3
	words = list(input().split())
	for word in words:
		d[word] = 1
		if word in u:
			first -= 2
			second += 1
		else:
			second += 3
	words = list(input().split())
	for word in words:
		if word in d:
			if word in u:
				first -= 1
				second -= 1
			else:
				second -= 2
				third += 1
		elif word in u:
			first -= 2
			third += 1
		else:
			third += 3
	print(first, second, third)
	t -= 1


import sys
from collections import Counter

def run():
	n = int(sys.stdin.readline().strip())
	guy1 = sys.stdin.readline().split()
	guy2 = sys.stdin.readline().split()
	guy3 = sys.stdin.readline().split()
	cnt = Counter()
	cnt.update(guy1)
	cnt.update(guy2)
	cnt.update(guy3)
	s1 = s2 = s3 = 0
	for w in guy1:
		if cnt[w] == 1:
			s1 += 3
		if cnt[w] == 2:
			s1 += 1
	for w in guy2:
		if cnt[w] == 1:
			s2 += 3
		if cnt[w] == 2:
			s2 += 1
	for w in guy3:
		if cnt[w] == 1:
			s3 += 3
		if cnt[w] == 2:
			s3 += 1
	print(f'{s1} {s2} {s3}')
t = int(input())
for _ in range(t):
	run()


def ft_calcul(l, di):
	s = 0
	for x in l:
		if di[x] == 1:
			s += 3
		elif di[x] == 2:
			s += 1
		else:
			s += 0
	return s
for i in range(int(input())):
	n = int(input())
	l1 = list(input().split())
	l2 = list(input().split())
	l3 = list(input().split())
	l4 = l1 + l2 + l3
	di = {}
	for x in l4:
		if x in di:
			di[x] += 1
		else:
			di[x] = 1
	s1 = ft_calcul(l1, di)
	s2 = ft_calcul(l2, di)
	s3 = ft_calcul(l3, di)
	print(s1, s2, s3)


for _ in ' ' * int(input()):
	x = {}
	y = set()
	_ = input()
	p = q = r = 0
	for a in input().split():
		x[a] = 1
		p += 3
	for b in input().split():
		if b in x:
			x[b] += 1
			p -= 2
			q += 1
		else:
			y.add(b)
			x[b] = 1
			q += 3
	for c in input().split():
		if c in x:
			if x[c] == 2:
				p -= 1
				q -= 1
			else:
				if c in y:
					q -= 2
				else:
					p -= 2
				r += 1
		else:
			r += 3
	print(p, q, r)


def getScore(data):
	counts = {}
	for person in data:
		for name in person:
			counts[name] = counts.get(name, 0) + 1
	ans = []
	for person in data:
		score = 0
		for name in person:
			if counts[name] == 1:
				score += 3
			elif counts[name] == 2:
				score += 1
		ans.append(score)
	return ' '.join(map(str, ans))
t = int(input())
data = []
for i in range(t):
	n = int(input())
	for _ in range(3):
		data.append(input().split())
	print(getScore(data))
	data = []


def calculateScores(person1, person2, person3):
	p1_s = set(person1)
	p2_s = set(person2)
	p3_s = set(person3)
	score = 0
	for word in p1_s:
		if word in p2_s and word in p3_s:
			score += 0
		elif word in p2_s or word in p3_s:
			score += 1
		else:
			score += 3
	return str(score)
test_cases = int(input())
for i in range(test_cases):
	columns = input()
	person1 = input().split(' ')
	person2 = input().split(' ')
	person3 = input().split(' ')
	output = ''
	output += calculateScores(person1, person2, person3) + ' '
	output += calculateScores(person2, person1, person3) + ' '
	output += calculateScores(person3, person2, person1) + ' '
	print(output)


num_games = int(input())
for i in range(num_games):
	num_words = int(input())
	first_words = set(input().split(' '))
	second_words = set(input().split(' '))
	third_words = set(input().split(' '))
	first_score = 0
	second_score = 0
	third_score = 0
	for num in first_words:
		if num in second_words and num in third_words:
			second_words.remove(num)
			third_words.remove(num)
		elif num in second_words:
			second_words.remove(num)
			first_score += 1
			second_score += 1
		elif num in third_words:
			first_score += 1
			third_score += 1
			third_words.remove(num)
		else:
			first_score += 3
	for num in second_words:
		if num in third_words:
			second_score += 1
			third_score += 1
			third_words.remove(num)
		else:
			second_score += 3
	for num in third_words:
		third_score += 3
	print(first_score, second_score, third_score)


def solve():
	n = int(input())
	s1 = input().split()
	s2 = input().split()
	s3 = input().split()
	s = (s1, s2, s3)
	count = {}
	for string in s:
		for word in string:
			if word not in count:
				count[word] = 1
				continue
			count[word] += 1
	output_str = ''
	for string in s:
		points = 0
		for word in string:
			if count[word] == 1:
				points += 3
			elif count[word] == 2:
				points += 1
		output_str += str(points) + ' '
	print(output_str)

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


def gg(aa, b, c):
	v = aa & b & c
	vv = aa & b - v
	vvv = aa & c - v
	return len(aa - b & aa - c) * 3 + len(vv) + len(vvv)
for _ in range(int(input())):
	n = int(input())
	aa = set(input().split())
	b = set(input().split())
	c = set(input().split())
	print(gg(aa, b, c), gg(b, aa, c), gg(c, aa, b))


n = int(input())
for i in range(n):
	m = int(input())
	a = {x for x in input().split(' ')}
	b = {x for x in input().split(' ')}
	c = {x for x in input().split(' ')}
	na = 3 * len(a - (b | c)) + len(a & b.symmetric_difference(c))
	nb = 3 * len(b - (a | c)) + len(b & a.symmetric_difference(c))
	nc = 3 * len(c - (b | a)) + len(c & b.symmetric_difference(a))
	print(na, ' ', nb, ' ', nc, ' ')


numero = int(input())
for i in range(numero):
	soyMarvin = int(input())
	a = {x for x in input().split(' ')}
	b = {x for x in input().split(' ')}
	c = {x for x in input().split(' ')}
	na = 3 * len(a - (b | c)) + len(a & b.symmetric_difference(c))
	nb = 3 * len(b - (a | c)) + len(b & a.symmetric_difference(c))
	nc = 3 * len(c - (b | a)) + len(c & b.symmetric_difference(a))
	print(na + 1 - 1, ' ', nb, ' ', nc + 10 - 10, ' ')


for _ in range(int(input())):
	n = int(input())
	aa = set(input().split())
	bb = set(input().split())
	cc = set(input().split())
	x = len(aa - bb - cc) * 3 + len((aa & bb) - cc) + len((aa & cc) - bb)
	y = len(bb - aa - cc) * 3 + len((bb & aa) - cc) + len((bb & cc) - aa)
	z = len(cc - aa - bb) * 3 + len((cc & aa) - bb) + len((cc & bb) - aa)
	print(x, y, z)


n = int(input())
result = []
for i in range(n):
	x = int(input())
	first = input().split()
	second = input().split()
	third = input().split()
	dct = {}
	fscore = sscore = tscore = 3 * x
	for i in first:
		dct[i] = 1
	for i in second:
		if i in dct:
			dct[i] += 5
			fscore -= 2
			sscore -= 2
		else:
			dct[i] = 5
	for i in third:
		if i in dct:
			if dct[i] == 1:
				fscore -= 2
				tscore -= 2
			elif dct[i] == 5:
				sscore -= 2
				tscore -= 2
			else:
				fscore -= 1
				tscore -= 3
				sscore -= 1
	result.append([fscore, sscore, tscore])
for i in result:
	print(i[0], i[1], i[2])


for _ in range(int(input())):
	n = int(input())
	f = list(map(str, input().split()))
	s = list(map(str, input().split()))
	l = list(map(str, input().split()))
	f = set(f)
	s = set(s)
	l = set(l)
	one = 0
	two = 0
	tree = 0
	one = len(f.difference(s, l)) * 3
	two = len(s.difference(f, l)) * 3
	tree = len(l.difference(f, s)) * 3
	common = len(f.intersection(s, l))
	one += len(f.intersection(s)) - common
	one += len(f.intersection(l)) - common
	two += len(s.intersection(f)) - common
	two += len(s.intersection(l)) - common
	tree += len(l.intersection(f)) - common
	tree += len(l.intersection(s)) - common
	print(one, two, tree)


num = int(input())
for i in range(num):
	num = int(input())
	p = set(input().split())
	q = set(input().split())
	r = set(input().split())
	a = 3 * len(p - q - r) + len(p & q - r) + len(p & r - q)
	b = 3 * len(q - p - r) + len(p & q - r) + len(q & r - p)
	c = 3 * len(r - q - p) + len(p & r - q) + len(q & r - p)
	print(a, b, c)


import math

def solve():
	n = int(input())
	lst1 = list(input().split(' '))
	lst2 = list(input().split(' '))
	lst3 = list(input().split(' '))
	a = 0
	b = 0
	c = 0
	dct = {}
	for i in lst1:
		dct[i] = dct.get(i, 0) + 1
	for i in lst2:
		dct[i] = dct.get(i, 0) + 1
	for i in lst3:
		dct[i] = dct.get(i, 0) + 1
	for i in lst1:
		if dct[i] == 1:
			a += 3
		elif dct[i] == 2:
			a += 1
	for i in lst2:
		if dct[i] == 1:
			b += 3
		elif dct[i] == 2:
			b += 1
	for i in lst3:
		if dct[i] == 1:
			c += 3
		elif dct[i] == 2:
			c += 1
	print(a, b, c)
t = int(input())
while t:
	t -= 1
	solve()


import sys
import heapq
input = sys.stdin.readline
from collections import Counter, defaultdict

def inp():
	return int(input())

def inlt():
	return list(map(str, input().split()))

def check(first, second, third):
	score = 0
	for word in first:
		if word in second and word in third:
			score += 0
		elif word in second or word in third:
			score += 1
		else:
			score += 3
	return score

def main():
	length = inp()
	(first, second, third) = (inlt(), inlt(), inlt())
	first = set(first)
	second = set(second)
	third = set(third)
	scores = [check(first, second, third), check(second, first, third), check(third, first, second)]
	print(*scores)
t = inp()
for _ in range(t):
	main()


def f(n, a, b, c):
	s1 = set(a)
	s2 = set(b)
	s3 = set(c)
	x1 = g(n, s2, s3, a)
	x2 = g(n, s1, s3, b)
	x3 = g(n, s1, s2, c)
	return (x1, x2, x3)

def g(n, s1, s2, l):
	sum = 0
	for i in range(n):
		if l[i] in s1 and l[i] in s2:
			pass
		elif l[i] in s1 or l[i] in s2:
			sum += 1
		else:
			sum += 3
	return sum
t = int(input())
for i in range(t):
	n = int(input())
	a = input().split()
	b = input().split()
	c = input().split()
	(x1, x2, x3) = f(n, a, b, c)
	print(f'{x1} {x2} {x3}')


def get_res():
	memo = dict()
	word = []
	res = []
	for i in range(3):
		x = input().split(' ')
		word.append(x)
		for s in x:
			if s in memo:
				memo[s] += 1
			else:
				memo[s] = 1
	for i in range(3):
		total = 0
		for s in word[i]:
			if memo[s] == 1:
				total += 3
			if memo[s] == 2:
				total += 1
		res.append(total)
	return res
t = int(input())
res = []
for i in range(t):
	x = input()
	res.append(get_res())
for k in res:
	print(str(k[0]) + ' ' + str(k[1]) + ' ' + str(k[2]))


t = int(input())
for m in range(0, t):
	n = int(input())
	mydict = {}
	a1str = input()
	a2str = input()
	a3str = input()
	a1 = a1str.split()
	a2 = a2str.split()
	a3 = a3str.split()
	p1 = 0
	p2 = 0
	p3 = 0
	for i in a1:
		mydict[i] = 1
		p1 += 3
	for i in a2:
		if i in mydict.keys():
			mydict[i] += 2
			p1 -= 2
			p2 += 1
		else:
			mydict[i] = 2
			p2 += 3
	for i in a3:
		if i in mydict.keys():
			if mydict[i] == 3:
				p1 -= 1
				p2 -= 1
			elif mydict[i] == 2:
				p2 -= 2
				p3 += 1
			elif mydict[i] == 1:
				p1 -= 2
				p3 += 1
		else:
			p3 += 3
	print(p1, p2, p3)


t = int(input())
for k in range(0, t):
	n = int(input())
	(x, y, z) = (0, 0, 0)
	l1 = [str(x) for x in input().split()]
	l2 = [str(x) for x in input().split()]
	l3 = [str(x) for x in input().split()]
	s1 = set(l1)
	s2 = set(l2)
	s3 = set(l3)
	l4 = s1.intersection(s2)
	l5 = s2.intersection(s3)
	l6 = s3.intersection(s1)
	l7 = l4.intersection(s3)
	x += 3 * (len(l1) - len(l4) - len(l6) + len(l7))
	x += len(l4) + len(l6) - 2 * len(l7)
	y += 3 * (len(l2) - len(l4) - len(l5) + len(l7))
	y += len(l4) + len(l5) - 2 * len(l7)
	z += 3 * (len(l1) - len(l5) - len(l6) + len(l7))
	z += len(l5) + len(l6) - 2 * len(l7)
	print(x, y, z)


def count_score(first, second, third):
	counts = {}
	for word in first + second + third:
		counts.setdefault(word, 0)
		counts[word] += 1
	score = []
	for player in (first, second, third):
		current = 0
		for word in player:
			if counts[word] == 1:
				current += 3
			elif counts[word] == 2:
				current += 1
		score.append(current)
	return tuple(score)
for _ in range(int(input())):
	input()
	first = input().split()
	second = input().split()
	third = input().split()
	score = count_score(first, second, third)
	print(' '.join(map(str, score)))


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def inls():
	return list(map(str, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	cnt = inp()
	s1 = set(input().split())
	s2 = set(input().split())
	s3 = set(input().split())
	score_1 = 0
	for x in s1:
		if x in s2 and x in s3:
			score_1 += 0
		elif x in s3:
			score_1 += 1
		elif x in s2:
			score_1 += 1
		else:
			score_1 += 3
	score_2 = 0
	for x in s2:
		if x in s3 and x in s1:
			score_2 += 0
		elif x in s1:
			score_2 += 1
		elif x in s3:
			score_2 += 1
		else:
			score_2 += 3
	score_3 = 0
	for x in s3:
		if x in s1 and x in s2:
			score_3 += 0
		elif x in s1:
			score_3 += 1
		elif x in s2:
			score_3 += 1
		else:
			score_3 += 3
	print(f'{score_1} {score_2} {score_3}')


n = int(input())
point = []
while n != 0:
	dic = []
	(q1, q2, q3) = (0, 0, 0)
	n -= 1
	a = int(input())
	s = input()
	p1 = s.split(' ')
	p4 = set(p1)
	s = input()
	p2 = s.split(' ')
	p5 = set(p2)
	s = input()
	p3 = s.split(' ')
	p6 = set(p3)
	p7 = p4.intersection(p5, p6)
	p8 = p4.intersection(p5)
	p9 = p5.intersection(p6)
	p10 = p6.intersection(p4)
	for i in p4:
		if i in p7:
			q1 += 0
		elif i in p8 or i in p10:
			q1 += 1
		else:
			q1 += 3
	for i in p5:
		if i in p7:
			q2 += 0
		elif i in p8 or i in p9:
			q2 += 1
		else:
			q2 += 3
	for i in p6:
		if i in p7:
			q3 += 0
		elif i in p9 or i in p10:
			q3 += 1
		else:
			q3 += 3
	(point.append(q1), point.append(q2), point.append(q3))
for i in range(len(point) // 3):
	print(point[i * 3], point[i * 3 + 1], point[i * 3 + 2])


def save(word, wordsDic):
	for i in word:
		wordsDic[i] = wordsDic.get(i, 0) + 1

def solve(n, word1, word2, word3, wordsDic):
	save(word1, wordsDic)
	save(word2, wordsDic)
	save(word3, wordsDic)
	scores = []
	score = 0
	for i in word1:
		if wordsDic[i] == 2:
			score += 1
		elif wordsDic[i] == 1:
			score += 3
	scores.append(score)
	score = 0
	for i in word2:
		if wordsDic[i] == 2:
			score += 1
		elif wordsDic[i] == 1:
			score += 3
	scores.append(score)
	score = 0
	for i in word3:
		if wordsDic[i] == 2:
			score += 1
		elif wordsDic[i] == 1:
			score += 3
	scores.append(score)
	return ' '.join([str(i) for i in scores])
t = int(input())
for T in range(t):
	n = int(input())
	word1 = input().split(' ')
	word2 = input().split(' ')
	word3 = input().split(' ')
	words = {}
	print(solve(n, word1, word2, word3, words))


t = int(input())
for _ in range(t):
	n = int(input())
	s1 = set(map(str, input().split()))
	s2 = set(map(str, input().split()))
	s3 = set(map(str, input().split()))
	zero = len(s1.intersection(s2.intersection(s3)))
	n -= zero
	ans1 = (n - len(s1.intersection(s2)) - len(s1.intersection(s3)) + 2 * zero) * 3 + len(s1.intersection(s2)) + len(s1.intersection(s3)) - 2 * zero
	ans2 = (n - len(s2.intersection(s1)) - len(s2.intersection(s3)) + 2 * zero) * 3 + len(s2.intersection(s1)) + len(s2.intersection(s3)) - 2 * zero
	ans3 = (n - len(s3.intersection(s2)) - len(s3.intersection(s1)) + 2 * zero) * 3 + len(s3.intersection(s2)) + len(s3.intersection(s1)) - 2 * zero
	print(ans1, ans2, ans3)


t = int(input())
for x in range(t):
	n = int(input())
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	ans1 = ans2 = ans3 = 0
	for el in a:
		if el in b and el in c:
			continue
		elif el in b or el in c:
			ans1 += 1
		else:
			ans1 += 3
	for el in b:
		if el in a and el in c:
			continue
		elif el in a or el in c:
			ans2 += 1
		else:
			ans2 += 3
	for el in c:
		if el in b and el in a:
			continue
		elif el in b or el in a:
			ans3 += 1
		else:
			ans3 += 3
	print(ans1, ans2, ans3)


t = int(input())
for _ in range(t):
	n = int(input())
	a = set(input().split())
	b = set(input().split())
	c = set(input().split())
	sa = sb = sc = 0
	for w in set.intersection(a, b):
		if w not in c:
			sa += 1
			sb += 1
	for w in set.intersection(b, c):
		if w not in a:
			sb += 1
			sc += 1
	for w in set.intersection(c, a):
		if w not in b:
			sc += 1
			sa += 1
	for w in set.difference(a, set.union(b, c)):
		sa += 3
	for w in set.difference(b, set.union(a, c)):
		sb += 3
	for w in set.difference(c, set.union(a, b)):
		sc += 3
	print(sa, sb, sc)


def solve(s1, s2, s3):
	(ans1, ans2, ans3) = (0, 0, 0)
	for i in s1.union(s2).union(s3):
		if i in s1 and i not in s2 and (i not in s3):
			ans1 += 3
		elif i not in s1 and i in s2 and (i not in s3):
			ans2 += 3
		elif i not in s1 and i not in s2 and (i in s3):
			ans3 += 3
		elif i in s1 and i in s2 and (i not in s3):
			ans1 += 1
			ans2 += 1
		elif i in s1 and i not in s2 and (i in s3):
			ans1 += 1
			ans3 += 1
		elif i not in s1 and i in s2 and (i in s3):
			ans2 += 1
			ans3 += 1
	return (ans1, ans2, ans3)
for _ in range(int(input())):
	input()
	print(*solve(set(input().split()), set(input().split()), set(input().split())))


from itertools import count
import math
from collections import Counter
ints = lambda : list(map(int, input().split()))
alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
mx = 10 ** 5
inp = lambda : int(input())
for _ in range(inp()):
	n = inp()
	s1 = input().split()
	s2 = input().split()
	s3 = input().split()
	counts = Counter(s1 + s2 + s3)
	v1 = v2 = v3 = 0
	for x in s1:
		if counts[x] == 1:
			v1 += 3
		elif counts[x] == 2:
			v1 += 1
	for x in s2:
		if counts[x] == 1:
			v2 += 3
		elif counts[x] == 2:
			v2 += 1
	for x in s3:
		if counts[x] == 1:
			v3 += 3
		elif counts[x] == 2:
			v3 += 1
	print(v1, v2, v3)


def res(s1, s2, s3):
	ans = {}
	p = {1: 3, 2: 1, 3: 0}
	rs = [0, 0, 0]
	for s in s1 + s2 + s3:
		if s in ans:
			ans[s] += 1
		else:
			ans[s] = 1
	for s in s1:
		rs[0] += p[ans[s]]
	for s in s2:
		rs[1] += p[ans[s]]
	for s in s3:
		rs[2] += p[ans[s]]
	return rs
n = int(input())
for _ in range(n):
	n1 = int(input())
	s1 = input().split()
	s2 = input().split()
	s3 = input().split()
	print(*res(s1, s2, s3))


for _ in range(int(input())):
	n = int(input())
	s1 = [x for x in input().split()]
	if 'eht7834ht8hr' == 434323243:
		print('Tanmay')
	s2 = [x for x in input().split()]
	p1 = p2 = p3 = n * 3
	s3 = [x for x in input().split()]
	se2 = set()
	se3c = set()
	se1 = set()
	for i in s1:
		se1.add(i)
	for i in s2:
		if i in se1:
			p1 -= 2
			p2 -= 2
			se3c.add(i)
		se2.add(i)
	for i in s3:
		if i in se3c:
			p1 -= 1
			p2 -= 1
			p3 -= 3
			continue
		if i in se1:
			p1 -= 2
			p3 -= 2
		elif i in se2:
			p2 -= 2
			p3 -= 2
	print(p1, p2, p3)


import sys

def main():
	n = int(sys.stdin.readline().strip())
	d = {}
	for _ in range(n):
		sys.stdin.readline()
		s = sys.stdin.readline().strip().split()
		s2 = sys.stdin.readline().strip().split()
		s3 = sys.stdin.readline().strip().split()
		asnl = []
		for (i, j, k) in zip(s, s2, s3):
			if i not in d:
				d[i] = 1
			else:
				d[i] = d[i] + 1
			if j not in d:
				d[j] = 1
			else:
				d[j] = d[j] + 1
			if k not in d:
				d[k] = 1
			else:
				d[k] = d[k] + 1
		ans = 0
		ansl = []
		for m in s:
			if d[m] == 1:
				ans += 3
			elif d[m] == 2:
				ans += 1
		ansl.append(ans)
		ans = 0
		for m in s2:
			if d[m] == 1:
				ans += 3
			elif d[m] == 2:
				ans += 1
		ansl.append(ans)
		ans = 0
		for m in s3:
			if d[m] == 1:
				ans += 3
			elif d[m] == 2:
				ans += 1
		ansl.append(ans)
		for c in ansl:
			sys.stdout.write(str(c) + ' ')
		sys.stdout.write('\n')
		d.clear()
main()


def get_answer(a, b, c):
	counters = {}
	for i in [*a, *b, *c]:
		if i not in counters:
			counters[i] = 0
		counters[i] += 1
	result_scores = [0, 0, 0]
	for (index, elems) in enumerate([a, b, c]):
		for elem in elems:
			score_for_this_elem = 0
			if counters[elem] == 1:
				score_for_this_elem = 3
			elif counters[elem] == 2:
				score_for_this_elem = 1
			result_scores[index] += score_for_this_elem
	return f'{result_scores[0]} {result_scores[1]} {result_scores[2]}'
for _ in range(int(input())):
	input()
	(a, b, c) = [input().split() for i in range(3)]
	print(get_answer(a, b, c))


for _ in range(int(input())):
	n = int(input())
	w1 = input().split()
	w2 = input().split()
	w3 = input().split()
	w1 = set(w1)
	w2 = set(w2)
	w3 = set(w3)
	p1 = 0
	for x in w1:
		if x in w2 and x in w3:
			pass
		elif x in w2 or x in w3:
			p1 += 1
		else:
			p1 += 3
	p2 = 0
	for x in w2:
		if x in w1 and x in w3:
			pass
		elif x in w1 or x in w3:
			p2 += 1
		else:
			p2 += 3
	p3 = 0
	for x in w3:
		if x in w2 and x in w1:
			pass
		elif x in w2 or x in w1:
			p3 += 1
		else:
			p3 += 3
	print(p1, p2, p3)


for _ in range(int(input())):
	n = int(input())
	s = set(input().split())
	s1 = set(input().split())
	s2 = set(input().split())
	c = 0
	c1 = 0
	c2 = 0
	for i in s:
		if i in s1 and i in s2:
			s1.remove(i)
			s2.remove(i)
		elif i in s2 and i not in s1 or (i in s1 and i not in s2):
			c += 1
			if i in s1:
				c1 += 1
				s1.remove(i)
			else:
				c2 += 1
				s2.remove(i)
		else:
			c += 3
	for i in s1:
		if i in s and i in s2:
			s.remove(i)
			s2.remove(i)
		elif i in s2 and i not in s or (i in s and i not in s2):
			c1 += 1
			if i in s:
				c += 1
				s.remove(i)
			else:
				c2 += 1
				s2.remove(i)
		else:
			c1 += 3
	for i in s2:
		if i in s1 and i in s:
			s1.remove(i)
			s.remove(i)
		elif i in s and i not in s1 or (i in s1 and i not in s):
			c2 += 1
			if i in s1:
				c1 += 1
				s1.remove(i)
			else:
				c += 1
				s.remove(i)
		else:
			c2 += 3
	print(c, c1, c2)