Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef is playing a card game with his friend Morty Smith. 

The rules of the game are as follows:
- There are two piles of cards, pile $A$ and pile $B$, each with $N$ cards in it. Pile $A$ belongs to Chef and pile $B$ belongs to Morty.
- Each card has one positive integer on it
- The ‘power’ of a card is defined as the sum of digits of the integer on that card
- The game consists of $N$ rounds
- In each round, both players simultaneously draw one card each from the top of their piles and the player who draws the card with higher power wins this round and gets a point. If the powers of both players' cards are equal then they get $1$ point each. 
- The winner of the game is the player who has more points at the end of $N$ rounds. If both players have equal number of points then the game ends in a draw.

The game is now over and Chef has told Morty to find the winner. Unfortunately, this task is too complex for him. Help Morty find the winner. 

------  Input: ------

First line will contain $T$, number of testcases.
The first line of each test case will contain $N$, the number of rounds played.
The $i^{th}$ of the next $N$ lines of each test case will contain $A_{i}$ and $B_{i}$, the number on the card drawn by Chef and Morty respectively in round $i$.

------  Output: ------
For each test case, output two space separated integers on a new line:      
Output      
- $0$ if Chef wins,             
- $1$ if Morty wins,     
- $2$ if it is a draw,     
followed by the number of points the winner had.     
(If it is a draw then output either player’s points).

------  Constraints  ------
$1 ≤ T ≤ 1000$
$1 ≤ N ≤ 100$
$1 ≤ A_{i}, B_{i} ≤ 10^{9}$

------  Subtasks ------
$100$ points : No additional constraints

----- Sample Input 1 ------ 
2

3

10 4

8 12

7 6

2

5 10

3 4
----- Sample Output 1 ------ 
0 2

2 1
----- explanation 1 ------ 
Test Case $1$:

Round $1$: 

Chef’s card has power $1+0$ = $1$,     
Morty’s card has power $4$.      
Therefore, Morty wins the round.        

Round $2$: 

Chef’s card has power $8$,        
Morty’s card has power $1 + 2$ = $3$.       
Therefore, Chef wins the round.     

Round $3$: 

Chef’s card has power $7$,      
Morty’s card has power $6$.      
Therefore, Chef wins the round.         

Therefore, Chef wins the game with $2$ points (Morty has $1$ point).  

Test Case $2$:

Round $1$: 

Chef’s card has power $5$,     
Morty’s card has power $1 + 0 = 1$.      
Therefore, Chef wins the round.        

Round $2$: 

Chef’s card has power $3$,        
Morty’s card has power $4$.       
Therefore, Morty wins the round.     

Therefore, the game ends in a draw and both players have $1$ point each.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
for _ in range(int(input())):
	n = int(input())
	(ctot, mtot) = (0, 0)
	for r in range(n):
		(c, m) = input().split()
		(cs, ms) = (0, 0)
		for dc in c:
			cs += int(dc)
		for dm in m:
			ms += int(dm)
		if cs == ms:
			ctot += 1
			mtot += 1
		elif cs > ms:
			ctot += 1
		else:
			mtot += 1
	else:
		if ctot == mtot:
			print(2, ctot)
		elif ctot > mtot:
			print(0, ctot)
		else:
			print(1, mtot)


for i in range(int(input())):
	Length = int(input())
	(counta, countb) = (0, 0)
	for j in range(Length):
		ta = 0
		tb = 0
		(a, b) = map(int, input().split())
		if a > 9:
			a = str(a)
			for i in a:
				ta += int(i)
		else:
			ta = a
		if b > 9:
			b = str(b)
			for i in b:
				tb += int(i)
		else:
			tb = b
		if ta > tb:
			counta += 1
		elif tb > ta:
			countb += 1
		else:
			counta += 1
			countb += 1
	if counta > countb:
		print(0, counta)
	elif countb > counta:
		print(1, countb)
	else:
		print(2, counta)


for i in range(int(input())):
	n = int(input())
	(c, m) = (0, 0)
	for i in range(n):
		(a, b) = map(int, input().split())
		(c1, m1) = (0, 0)
		while a > 0:
			c1 = c1 + a % 10
			a = a // 10
		while b > 0:
			m1 = m1 + b % 10
			b = b // 10
		if c1 > m1:
			c = c + 1
		elif c1 < m1:
			m += 1
		else:
			c += 1
			m += 1
	if c > m:
		print(0, c)
	elif c < m:
		print(1, m)
	else:
		print(2, m)


def ans(n):
	r = 0
	while n > 0:
		r += n % 10
		n = n // 10
	return r
for _ in range(int(input())):
	n = int(input())
	(x, y) = (0, 0)
	for i in range(n):
		(a, b) = map(int, input().split())
		a = ans(a)
		b = ans(b)
		if a > b:
			x += 1
		elif a < b:
			y += 1
		else:
			x += 1
			y += 1
	if x > y:
		print(0, x)
	elif x < y:
		print(1, y)
	else:
		print(2, x)


t = int(input())
for i in range(t):
	n = int(input())
	g = 0
	h = 0
	for i in range(n):
		(a, b) = map(int, input().split())
		a = str(a)
		b = str(b)
		sum1 = 0
		sum2 = 0
		for i in range(len(a)):
			sum1 = sum1 + int(a[i])
		for i in range(len(b)):
			sum2 = sum2 + int(b[i])
		if sum1 > sum2:
			g = g + 1
		elif sum1 < sum2:
			h = h + 1
		elif sum1 == sum2:
			g = g + 1
			h = h + 1
	if g > h:
		print('0', +g)
	elif g == h:
		print('2', +g)
	else:
		print('1', +h)


for _ in range(int(input())):
	n = int(input())
	(chef, morty) = (0, 0)
	for i in range(n):
		(a, b) = map(int, input().split())
		k = 0
		for i in str(a):
			k = k + int(i)
		a = k
		k = 0
		for i in str(b):
			k = k + int(i)
		b = k
		if a > b:
			chef = chef + 1
		elif b > a:
			morty = morty + 1
		else:
			chef = chef + 1
			morty = morty + 1
	if chef > morty:
		print('0', chef)
	elif chef < morty:
		print('1', morty)
	else:
		print('2', chef)


t = int(input())
for _ in range(t):
	n = int(input())
	ap = 0
	bp = 0
	for i in range(n):
		line = input()
		words = line.split()
		nums = [int(w) for w in words]
		(a, b) = nums
		a_string = str(a)
		b_string = str(b)
		a_digit = [int(a_s) for a_s in a_string]
		b_digit = [int(b_s) for b_s in b_string]
		ad = sum(a_digit)
		bd = sum(b_digit)
		if ad > bd:
			ap += 1
		elif ad < bd:
			bp += 1
		else:
			ap += 1
			bp += 1
	if ap > bp:
		print(0, ap)
	elif ap < bp:
		print(1, bp)
	else:
		print(2, ap)


t = int(input())
for i in range(t):
	n = int(input())
	v = 0
	u = 0
	for i in range(n):
		(a, b) = map(int, input().split())
		l = list(map(int, str(a)))
		f = list(map(int, str(b)))
		r = sum(l)
		c = sum(f)
		if r > c:
			v = v + 1
		elif r < c:
			u = u + 1
		elif r == c:
			v = v + 1
			u = u + 1
	else:
		if v > u:
			print(0, v)
		elif v < u:
			print(1, u)
		elif u == v:
			print(2, v)


def cards(x):
	t = 0
	while x != 0:
		t = t + x % 10
		x = x // 10
	return t
t = int(input())
for i in range(t):
	n = int(input())
	l = []
	m = 0
	c = 0
	for i in range(n):
		(k, h) = map(int, input().split())
		l.append(k)
		l.append(h)
	for i in range(0, len(l), 2):
		if cards(l[i]) > cards(l[i + 1]):
			c = c + 1
		elif cards(l[i]) < cards(l[i + 1]):
			m = m + 1
		else:
			c = c + 1
			m = m + 1
	if c > m:
		print(0, c)
	elif m > c:
		print(1, m)
	else:
		print(2, c)


for i in range(int(input())):
	n = int(input())
	che = 0
	mor = 0
	for i in range(n):
		c = 0
		d = 0
		(a, b) = map(int, input().split())
		for i in str(a):
			c += int(i)
		for i in str(b):
			d += int(i)
		if c < d:
			mor += 1
		elif c > d:
			che += 1
		else:
			che += 1
			mor += 1
	if mor == che:
		print(2, che)
	elif mor < che:
		print(0, che)
	else:
		print(1, mor)


goals = int(input())
for distractions in range(goals):
	n = int(input())
	(life, wife) = (0, 0)
	for r in range(n):
		(c, m) = input().split()
		(cs, ms) = (0, 0)
		for dc in c:
			cs += int(dc)
		for dm in m:
			ms += int(dm)
		if cs == ms:
			life += 1
			wife += 1
		elif cs > ms:
			life += 1
		else:
			wife += 1
	else:
		if life == wife:
			print(2, life)
		elif life > wife:
			print(0, life)
		else:
			print(1, wife)


def check(a, b):
	a = str(a)
	b = str(b)
	l1 = [int(x) for x in a]
	l2 = [int(x) for x in b]
	if sum(l1) == sum(l2):
		return 2
	elif sum(l1) > sum(l2):
		return 0
	else:
		return 1
t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	m = 0
	for i in range(n):
		(a, b) = map(int, input().split())
		if check(a, b) == 2:
			m += 1
			c += 1
		elif check(a, b) == 0:
			c += 1
		else:
			m += 1
	if c == m:
		print(2, m)
	elif c > m:
		print(0, c)
	else:
		print(1, m)


def remainderA(a):
	su = 0
	while a != 0:
		rem = a % 10
		su += rem
		a = a // 10
	return su

def remainderB(b):
	suB = 0
	while b != 0:
		rem = b % 10
		suB += rem
		b = b // 10
	return suB
t = int(input())
for i in range(t):
	r = int(input())
	chef = 0
	morty = 1
	draw = 2
	c = 0
	m = 0
	for i in range(r):
		(a, b) = map(int, input().split())
		a1 = remainderA(a)
		b1 = remainderB(b)
		if a1 > b1:
			c += 1
		elif a1 < b1:
			m += 1
		elif a1 == b1:
			c += 1
			m += 1
	if c > m:
		print(chef, c)
	elif c < m:
		print(morty, m)
	elif c == m:
		print(draw, c)


t = int(input())
while t >= 1:
	n = int(input())
	(c1, c2, c3) = (0, 0, 0)
	while n >= 1:
		(a, b) = input().split()
		(s1, s2) = (0, 0)
		for i in str(a):
			s1 += int(i)
		for j in str(b):
			s2 += int(j)
		if s1 > s2:
			c1 = c1 + 1
		if s1 < s2:
			c2 = c2 + 1
		if s1 == s2:
			c1 = c1 + 1
			c2 = c2 + 1
		n -= 1
	if c1 > c2:
		print('0', c1)
	if c2 > c1:
		print('1', c2)
	if c1 == c2:
		print('2', c1)
	t -= 1


t = int(input())

def sum_digit(s):
	ans = 0
	for i in range(len(s)):
		ans += int(s[i])
	return ans
for _ in range(t):
	n = int(input())
	count_a = 0
	count_b = 0
	for i in range(n):
		(a, b) = map(str, input().split())
		tem_a = sum_digit(a)
		tem_b = sum_digit(b)
		if tem_a > tem_b:
			count_a += 1
		elif tem_b > tem_a:
			count_b += 1
		else:
			count_a += 1
			count_b += 1
	if count_a > count_b:
		print(0, count_a)
	elif count_b > count_a:
		print(1, count_b)
	else:
		print(2, count_a)


def sm(n):
	s = 0
	while n > 0:
		s += n % 10
		n = n // 10
	return s
t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	m = 0
	for _a in range(n):
		(a, b) = map(int, input().split())
		(sa, sb) = (sm(a), sm(b))
		if sa > sb:
			c += 1
		elif sa < sb:
			m += 1
		else:
			c += 1
			m += 1
	if c > m:
		print('0', c)
	elif m > c:
		print('1', m)
	else:
		print('2', c)


for i in range(int(input())):
	N = int(input())
	s1 = 0
	s2 = 0
	for j in range(N):
		A = input().split()
		c = 0
		d = 0
		for k in range(2):
			if k == 0:
				for l in A[k]:
					c = c + int(l)
			else:
				for l in A[k]:
					d = d + int(l)
		if c > d:
			s1 += 1
		elif c < d:
			s2 += 1
		else:
			s1 += 1
			s2 += 1
	if s1 > s2:
		print(0, ' ', s1)
	elif s1 < s2:
		print(1, ' ', s2)
	else:
		print(2, ' ', s2)


for i in range(int(input())):
	s = int(input())
	(C, M) = (0, 0)
	for i in range(s):
		(sc, sm) = map(str, input().split())
		(c, m) = (0, 0)
		for i in sc:
			c += int(i)
		for i in sm:
			m += int(i)
		if c > m:
			C += 1
		elif m > c:
			M += 1
		else:
			C += 1
			M += 1
	if C > M:
		print(0, C)
	elif C < M:
		print(1, M)
	else:
		print(2, C)


for _ in range(int(input())):
	rounds = int(input())
	(C, M) = (0, 0)
	for __ in range(rounds):
		(sc, sm) = map(str, input().split())
		(c, m) = (0, 0)
		for i in sc:
			c += int(i)
		for i in sm:
			m += int(i)
		if c > m:
			C += 1
		elif m > c:
			M += 1
		else:
			C += 1
			M += 1
	if C > M:
		print(0, C)
	elif C < M:
		print(1, M)
	else:
		print(2, C)


def sum_of_digits(n):
	lst = list(str(n))
	s = 0
	for i in lst:
		s += int(i)
	return s
t = int(input())
for _ in range(t):
	n = int(input())
	chef = 0
	mortey = 0
	for i in range(n):
		(c, m) = map(int, input().split())
		if sum_of_digits(c) == sum_of_digits(m):
			chef += 1
			mortey += 1
		elif sum_of_digits(c) > sum_of_digits(m):
			chef += 1
		else:
			mortey += 1
	if chef == mortey:
		print('2' + ' ' + str(chef))
	elif chef > mortey:
		print('0' + ' ' + str(chef))
	else:
		print('1' + ' ' + str(mortey))


def ds(a):
	c = 0
	for m in a:
		c += int(m)
	return c
for i in range(int(input())):
	c = 0
	m = 0
	for j in range(int(input())):
		(a, b) = map(str, input().split())
		(a, b) = (ds(a), ds(b))
		if a > b:
			c += 1
		elif b > a:
			m += 1
		else:
			m += 1
			c += 1
	if c > m:
		print('0', c)
	elif m > c:
		print('1', m)
	else:
		print(2, m)


for _ in range(int(input())):
	n = int(input())
	c = 0
	m = 0
	for x in range(n):
		(a, b) = input().split()
		s1 = 0
		s2 = 0
		for x in range(len(a)):
			s1 = s1 + int(a[x])
		for x in range(len(b)):
			s2 = s2 + int(b[x])
		if s1 > s2:
			c += 1
		elif s2 > s1:
			m += 1
		else:
			c += 1
			m += 1
	if c > m:
		print(0, c)
	elif m > c:
		print(1, m)
	else:
		print(2, m)


def getSum(n):
	sum = 0
	while n > 0:
		sum += int(n % 10)
		n = int(n / 10)
	return sum
for _ in range(int(input())):
	s1 = 0
	s2 = 0
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		(sum1, sum2) = (getSum(a), getSum(b))
		if sum1 > sum2:
			s1 += 1
		elif sum1 == sum2:
			s1 += 1
			s2 += 1
		else:
			s2 += 1
	if s1 > s2:
		print(0, s1)
	elif s1 == s2:
		print(2, s1)
	else:
		print(1, s2)


def digcnt(s):
	count = 0
	for d in s:
		count += int(d)
	return count
for _ in range(int(input())):
	n = int(input())
	(ctot, mtot) = (0, 0)
	for r in range(n):
		(c, m) = input().split()
		(cs, ms) = (0, 0)
		cs = digcnt(c)
		ms = digcnt(m)
		if cs == ms:
			ctot += 1
			mtot += 1
		elif cs > ms:
			ctot += 1
		else:
			mtot += 1
	else:
		if ctot == mtot:
			print(2, ctot)
		elif ctot > mtot:
			print(0, ctot)
		else:
			print(1, mtot)


def sep(num):
	add = 0
	while num != 0:
		n = num % 10
		add += n
		num = num // 10
	return add
for _ in range(int(input())):
	n = int(input())
	point_A = 0
	point_B = 0
	for i in range(n):
		(a, b) = map(int, input().split())
		a = sep(a)
		b = sep(b)
		if a > b:
			point_A += 1
		elif b > a:
			point_B += 1
		else:
			point_B += 1
			point_A += 1
	if point_A > point_B:
		print(0, point_A)
	elif point_A < point_B:
		print(1, point_B)
	else:
		print(2, point_B)


t = int(input())
for i in range(t):
	n = int(input())
	c = []
	m = []
	(c0, m0) = (0, 0)
	for k in range(n):
		(sm1, sm2) = (0, 0)
		(x, y) = list(map(int, input().split()))
		for d in str(x):
			sm1 += int(d)
		c.append(sm1)
		for d in str(y):
			sm2 += int(d)
		m.append(sm2)
	for l in range(len(c)):
		if c[l] > m[l]:
			c0 += 1
		elif c[l] < m[l]:
			m0 += 1
		else:
			m0 += 1
			c0 += 1
	if c0 > m0:
		print(0, end=' ')
		print(c0)
	elif m0 > c0:
		print(1, end=' ')
		print(m0)
	else:
		print(2, end=' ')
		print(c0)


def sumd(n):
	sumn = 0
	while n:
		r = n % 10
		sumn += r
		n //= 10
	return sumn
for _ in range(int(input())):
	(countchef, countmorty) = (0, 0)
	for i in range(int(input())):
		(A, B) = map(int, input().split())
		(chef, morty) = (sumd(A), sumd(B))
		if chef > morty:
			countchef += 1
		elif chef < morty:
			countmorty += 1
		else:
			countchef += 1
			countmorty += 1
	if countchef > countmorty:
		print(0, countchef)
	elif countchef < countmorty:
		print(1, countmorty)
	else:
		print(2, countchef)


for _ in range(int(input())):
	n = int(input())
	c = 0
	m = 0
	for _ in range(n):
		(ch, mo) = map(str, input().split())
		p_c = sum([int(ele) for ele in ch])
		p_m = sum([int(ele) for ele in mo])
		if p_c > p_m:
			c += 1
		elif p_c < p_m:
			m += 1
		elif p_c == p_m:
			c += 1
			m += 1
	if c > m:
		print(0, c)
	elif c < m:
		print(1, m)
	else:
		print(2, c)


import math
T = int(input())
for _ in range(T):
	n = int(input())
	chef = 0
	morty = 0
	for i in range(n):
		(c, m) = map(list, input().split())
		c = list(map(int, c))
		m = list(map(int, m))
		if sum(c) > sum(m):
			chef += 1
		elif sum(c) < sum(m):
			morty += 1
		else:
			morty += 1
			chef += 1
	if chef > morty:
		print(0, chef)
	elif chef < morty:
		print(1, morty)
	else:
		print(2, chef)


for _ in range(int(input())):
	n = int(input())
	(cp, mp) = (0, 0)
	for i in range(n):
		(a, b) = map(int, input().split())
		tota = 0
		while a > 0:
			diga = a % 10
			tota = tota + diga
			a = a // 10
		totb = 0
		while b > 0:
			digb = b % 10
			totb = totb + digb
			b = b // 10
		if tota > totb:
			cp += 1
		elif tota < totb:
			mp += 1
		else:
			cp += 1
			mp += 1
	if cp > mp:
		print('0 ' + str(cp))
	elif mp > cp:
		print('1 ' + str(mp))
	else:
		print('2 ' + str(cp))


t = int(input())

def sumq(a):
	l = [int(i) for i in a]
	q = int(sum(l))
	l.clear()
	return q
for i in range(t):
	n = int(input())
	ca = 0
	cb = 0
	for j in range(n):
		a = input().split()
		a1 = a[0]
		b1 = a[1]
		if sumq(a1) > sumq(b1):
			ca = ca + 1
		elif sumq(a1) < sumq(b1):
			cb = cb + 1
		else:
			ca = ca + 1
			cb = cb + 1
	if ca > cb:
		print('0', ca)
	elif ca < cb:
		print('1', cb)
	else:
		print('2', ca)


def dsum(number):
	sum_ = 0
	while number > 0:
		sum_ += int(number % 10)
		number = int(number / 10)
	return sum_
for _ in range(int(input())):
	result = {x: 0 for x in range(3)}
	for _ in range(int(input())):
		(a, b) = map(int, input().split())
		a1 = dsum(a)
		a2 = dsum(b)
		if a1 > a2:
			result[0] += 1
		elif a2 > a1:
			result[1] += 1
		else:
			result[0] += 1
			result[1] += 1
	if result[0] > result[1]:
		print(0, result[0])
	elif result[1] > result[0]:
		print(1, result[1])
	else:
		print(2, result[1])


def digi(n):
	num = 0
	while n > 0:
		num1 = n % 10
		num += num1
		n = n - num1
		n = n / 10
	return num
for t in range(int(input())):
	n = int(input())
	ca = 0
	cb = 0
	for cards in range(n):
		(a, b) = map(int, input().split(' '))
		a = digi(a)
		b = digi(b)
		if a == b:
			ca += 1
			cb += 1
		elif a > b:
			ca += 1
		else:
			cb += 1
	if ca == cb:
		print(2, ca)
	elif ca > cb:
		print(0, ca)
	else:
		print(1, cb)


for _ in range(int(input())):
	chef = 0
	mort = 0
	for i in range(int(input())):
		cans = 0
		mans = 0
		(x, y) = input().split(' ')
		for j in x:
			cans += int(j)
		for k in y:
			mans += int(k)
		if cans > mans:
			chef += 1
		elif mans == cans:
			chef += 1
			mort += 1
		else:
			mort += 1
	if chef > mort:
		print(f'{0} {chef}')
	elif chef == mort:
		print(f'{2} {chef}')
	else:
		print(f'{1} {mort}')


def digitsum(n):
	sum = 0
	for i in str(n):
		sum += int(i)
	return sum
t = int(input())
while t:
	n = int(input())
	arr = []
	cnt_c = 0
	cnt_m = 0
	for i in range(n):
		(x, y) = map(str, input().split())
		if digitsum(x) > digitsum(y):
			cnt_c += 1
		elif digitsum(y) > digitsum(x):
			cnt_m += 1
		else:
			cnt_m += 1
			cnt_c += 1
	print('0' if cnt_c > cnt_m else '1' if cnt_m > cnt_c else '2', end=' ')
	print(max(cnt_c, cnt_m))
	t -= 1


T = int(input())
for _ in range(T):
	n = int(input())
	p1 = 0
	p2 = 0
	for _ in range(n):
		(a, b) = map(str, input().split())
		c = 0
		m = 0
		for i in a:
			c += int(i)
		for j in b:
			m += int(j)
		if c > m:
			p1 += 1
		elif c == m:
			p2 += 1
			p1 += 1
		else:
			p2 += 1
	if p1 > p2:
		print(f'{0} {p1}')
	elif p1 == p2:
		print(f'{2} {p1}')
	else:
		print(f'{1} {p2}')


for _ in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))

	def sd(num):
		s = str(num)
		x = 0
		for i in range(len(s)):
			x += int(s[i])
		return x
	c = 0
	m = 0
	for i in range(n):
		if sd(l[i][0]) > sd(l[i][1]):
			c += 1
		elif sd(l[i][0]) < sd(l[i][1]):
			m += 1
		else:
			c += 1
			m += 1
	if c > m:
		print(0, c)
	elif c < m:
		print(1, m)
	else:
		print(2, c)


for i in range(int(input())):
	a = []
	(x, y) = (0, 0)
	for j in range(int(input())):
		a.append(input().split())
	for j in a:
		(d, e) = (0, 0)
		for k in j[0]:
			d += int(k)
		for k in j[1]:
			e += int(k)
		if d == e:
			x += 1
			y += 1
		elif d > e:
			x += 1
		else:
			y += 1
	if x == y:
		print(2, x)
	elif x > y:
		print(0, x)
	else:
		print(1, y)


def sum_of_digits(x):
	s = 0
	while x > 0:
		rem = x % 10
		s += rem
		x = x // 10
	return s
t = int(input())
for i in range(t):
	n = int(input())
	pa = 0
	pb = 0
	for j in range(n):
		(a, b) = map(int, input().split(' '))
		sa = sum_of_digits(a)
		sb = sum_of_digits(b)
		if sa > sb:
			pa += 1
		elif sb > sa:
			pb += 1
		else:
			pa += 1
			pb += 1
	if pa > pb:
		print('0', ' ', pa)
	elif pb > pa:
		print('1', ' ', pb)
	else:
		print('2', ' ', pa)


T = int(input())
for it in range(T):
	c = 0
	m = 0
	n = int(input())

	def dsum(x):
		sum = 0
		while x != 0:
			sum += x % 10
			x = x // 10
		return sum
	for i in range(n):
		(a, b) = map(int, input().split())
		if dsum(a) > dsum(b):
			c += 1
		elif dsum(a) < dsum(b):
			m += 1
		else:
			c += 1
			m += 1
	if c > m:
		print(0, c)
	elif c < m:
		print(1, m)
	else:
		print(2, c)


def sumdigits(n):
	s = 0
	while n > 0:
		d = n % 10
		s += d
		n = n // 10
	return s
n = int(input())
for _ in range(n):
	a = int(input())
	chef = morty = 0
	for k in range(a):
		(b, c) = map(int, input().split())
		b = sumdigits(b)
		c = sumdigits(c)
		if b > c:
			chef += 1
		elif b < c:
			morty += 1
		else:
			chef += 1
			morty += 1
	if chef > morty:
		print(0, chef, sep=' ')
	elif chef < morty:
		print(1, morty, sep=' ')
	else:
		print(2, chef, sep=' ')


import math
T = int(input())
for i in range(T):
	N = int(input())
	a = 0
	b = 0
	c = 0
	for i in range(N):
		s1 = 0
		s2 = 0
		(A, B) = map(int, input().split())
		while A != 0:
			n1 = math.floor(A % 10)
			s1 = s1 + n1
			A = A // 10
		while B != 0:
			n2 = math.floor(B % 10)
			s2 = s2 + n2
			B = B // 10
		if s2 < s1:
			a += 1
		elif s1 < s2:
			b += 1
		else:
			c += 1
	if a + c > b + c:
		print(0, a + c)
	elif b + c > a + c:
		print(1, b + c)
	else:
		print(2, a + c)


import math
for i in range(int(input())):
	x = int(input())
	c = 0
	d = 0
	e = 0
	for j in range(x):
		sum1 = 0
		sum2 = 0
		(a, b) = map(int, input().split())
		while a != 0:
			num1 = math.floor(a % 10)
			sum1 = sum1 + num1
			a = a // 10
		while b != 0:
			num2 = math.floor(b % 10)
			sum2 = sum2 + num2
			b = b // 10
		if sum2 < sum1:
			c += 1
		elif sum1 < sum2:
			d += 1
		else:
			e += 1
	if c + e > d + e:
		print(0, c + e)
	elif d + e > c + e:
		print(1, d + e)
	else:
		print(2, c + e)


t = int(input())

def func(list1):
	l = len(list1)
	c = 0
	for i in range(l):
		if list1[i] != ' ':
			c += 1
		else:
			break
	p = 0
	for i in range(c):
		p = p + int(list1[i])
	k = 0
	for i in range(c + 1, l):
		k = k + int(list1[i])
	return [p, k]
for i in range(t):
	n = int(input())
	c1 = 0
	c2 = 0
	for j in range(n):
		t = list(input())
		z = func(t)
		(tc, tm) = z
		if tc > tm:
			c1 = c1 + 1
		elif tc < tm:
			c2 = c2 + 1
		else:
			c1 = c1 + 1
			c2 = c2 + 1
	if c1 > c2:
		print('0', c1)
	elif c1 < c2:
		print('1', c2)
	else:
		print('2', c1)


t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	m = 0
	for j in range(n):
		sc = 0
		sm = 0
		(a, b) = input().split()
		a = int(a)
		b = int(b)
		for k in str(a):
			sc += int(k)
		for k in str(b):
			sm += int(k)
		if sm > sc:
			m += 1
		elif sc > sm:
			c += 1
		else:
			c += 1
			m += 1
	if c > m:
		print(0, c)
	elif m > c:
		print(1, m)
	else:
		print(2, c)


tc = int(input())
for i in range(tc):
	N = int(input())
	count1 = 0
	count2 = 0
	for j in range(N):
		AB = input().split()
		sum1 = 0
		sum2 = 0
		A = AB[0]
		B = AB[1]
		for k in range(len(A)):
			sum1 = sum1 + int(A[k])
		for k in range(len(B)):
			sum2 = sum2 + int(B[k])
		if sum1 > sum2:
			count1 = count1 + 1
		elif sum1 == sum2:
			count1 = count1 + 1
			count2 = count2 + 1
		else:
			count2 = count2 + 1
	if count1 > count2:
		print('', 0, '', count1)
	elif count2 > count1:
		print('', 1, '', count2)
	else:
		print('', 2, '', count1)


for _ in range(int(input())):
	(c, m) = (0, 0)
	for N in range(int(input())):
		(a, b) = map(str, input().split())
		a = sum([int(x) for x in a])
		b = sum([int(x) for x in b])
		if a > b:
			c += 1
		elif a < b:
			m += 1
		else:
			c += 1
			m += 1
	if c > m:
		print(0, c)
	elif c < m:
		print(1, m)
	else:
		print(2, m)


for _ in range(int(input())):
	c = m = 0
	for _ in range(int(input())):
		(a, b) = input().split()
		x = y = 0
		for i in a:
			x += int(i)
		for i in b:
			y += int(i)
		if x > y:
			c += 1
		elif y > x:
			m += 1
		else:
			c += 1
			m += 1
	print(f'0 {c}' if c > m else f'1 {m}' if m > c else f'2 {c}')


def sum_digits(num):
	total = 0
	while num != 0:
		total += num % 10
		num = num // 10
	return total
for _ in range(int(input())):
	n = int(input())
	(points_a, points_b) = (0, 0)
	for _ in range(n):
		(a, b) = map(int, input().split())
		a = sum_digits(a)
		b = sum_digits(b)
		if a > b:
			points_a += 1
		elif a < b:
			points_b += 1
		else:
			(points_a, points_b) = (points_a + 1, points_b + 1)
	if points_a > points_b:
		print(0, points_a)
	elif points_a < points_b:
		print(1, points_b)
	else:
		print(2, points_a)


def sum_digits(num):
	strr = str(num)
	list_of_number = list(map(int, strr.strip()))
	return sum(list_of_number)
for _ in range(int(input())):
	n = int(input())
	(points_a, points_b) = (0, 0)
	for _ in range(n):
		(a, b) = map(int, input().split())
		a = sum_digits(a)
		b = sum_digits(b)
		if a > b:
			points_a += 1
		elif a < b:
			points_b += 1
		else:
			(points_a, points_b) = (points_a + 1, points_b + 1)
	if points_a > points_b:
		print(0, points_a)
	elif points_a < points_b:
		print(1, points_b)
	else:
		print(2, points_a)


import sys

def f(s):
	r = 0
	for i in s:
		r += int(i)
	return r
for _ in range(int(sys.stdin.readline())):
	A = 0
	B = 0
	for _ in range(int(sys.stdin.readline())):
		(a, b) = map(str, input().split(' '))
		x = f(a)
		y = f(b)
		if x == y:
			A += 1
			B += 1
		elif x > y:
			A += 1
		else:
			B += 1
	if A == B:
		sys.stdout.write('2 ' + str(A) + '\n')
	elif A > B:
		sys.stdout.write('0 ' + str(A) + '\n')
	else:
		sys.stdout.write('1 ' + str(B) + '\n')


goals = int(input())
for distractions in range(goals):
	aim = int(input())
	(life, wife) = (0, 0)
	for j in range(aim):
		(a, b) = map(int, input().split())
		(s1, s2) = (0, 0)
		if a > 9:
			while a != 0:
				s1 += a % 10
				a //= 10
			if b > 9:
				while b != 0:
					s2 += b % 10
					b //= 10
				if s1 > s2:
					life += 1
				elif s2 > s1:
					wife += 1
				else:
					life += 1
					wife += 1
			elif s1 > b:
				life += 1
			elif b > s1:
				wife += 1
			else:
				life += 1
				wife += 1
		elif b > 9:
			while b != 0:
				s2 += b % 10
				b //= 10
			if s2 > a:
				wife += 1
			elif a > s2:
				life += 1
			else:
				life += 1
				wife += 1
		elif a > b:
			life += 1
		elif b > a:
			wife += 1
		else:
			life += 1
			wife += 1
	if life > wife:
		print(0, life)
	elif wife > life:
		print(1, wife)
	else:
		print(2, life)


def sum(s):
	sumi = 0
	for i in s:
		sumi += int(i)
	return sumi
for _ in range(int(input())):
	n = int(input())
	(chef, morty) = (0, 0)
	for i in range(n):
		(a, b) = input().split(' ')
		if sum(a) > sum(b):
			chef += 1
		elif sum(a) < sum(b):
			morty += 1
		else:
			chef += 1
			morty += 1
	if chef > morty:
		print(0, chef)
	elif chef < morty:
		print(1, morty)
	else:
		print(2, chef)


t = int(input())
for i in range(t):
	n = int(input())
	(a2, b2, c) = (0, 0, 0)
	for i in range(n):
		(a, b) = map(int, input().split())
		(a1, b1) = (0, 0)
		while a > 0:
			a1 += a % 10
			a = a // 10
		while b > 0:
			b1 += b % 10
			b = b // 10
		if a1 > b1:
			a2 += 1
		elif a1 < b1:
			b2 += 1
		else:
			c += 1
	if a2 + c > b2 + c:
		print(0, a2 + c)
	elif b2 + c > a2 + c:
		print(1, b2 + c)
	else:
		print(2, b2 + c)