Problem Statement
2 players, Cyborg and Geno are playing a game on a matrix. In each turn, the player choses a number from the matrix which is not selected yet and adds the number to his sum. In the end, the player with the largest sum wins the game.

Assuming both players play optimally and Cyborg starts the game, predict who will be the winner of the game. Assume that the initial sum is 0 for both the players.

------ Input section ------ 

The first line contains T, the number of test cases. The description of T test cases follows.

Each test case begin with 2 integers, N and M, denoting the number of rows and columns in the matrix. The next N lines contains M space separated integers denoting the numbers present in the matrix.

------ Output section ------ 

For each testcase, output "Cyborg", "Geno" or "Draw" based on the outcome of the game.

------ Input constraints ------ 

1 ≤ T ≤ 20
1 ≤ N, M ≤ 50
0 ≤ A[i][j] ≤ 100, where A[i][j] denotes the element of the matrix in i^{th} row and j^{th} column.

----- Sample Input 1 ------ 
3
1 1
3
2 3
4 4 4
4 4 4
2 3
4 3 4
4 4 4
----- Sample Output 1 ------ 
Cyborg
Draw
Cyborg
----- explanation 1 ------ 
In the first test case, Cyborg wins by selecting the only number present in the matrix.

In the second test case, both Cyborg and Geno will end up with a sum of 12, irrespective of how they chose the numbers. Hence, it results in a draw.

In the third test case, when with the player play optimally, Cyborg will end up with sum of 12 while Geno will end up with sum of 11. So, Cyborg wins the game.

Difficulty: EASY
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
t = int(input())
for tc in range(t):
	(x, y) = map(int, input().split())
	m = []
	m1 = []
	c = 0
	g = 0
	for j in range(x):
		l = list(map(int, input().split()))
		m.append(l)
	for p in range(x):
		for k in range(y):
			m1.append(m[p][k])
	m1.sort()
	s = m1[::-1]
	for j in range(len(s)):
		if j % 2 == 0:
			c = c + s[j]
		else:
			g = g + s[j]
	if c > g:
		print('Cyborg')
	elif c < g:
		print('Geno')
	else:
		print('Draw')


for i in range(int(input())):
	(m, n) = map(int, input().split())
	matrix = []
	r = []
	(cyborg, geno) = (0, 0)
	for i in range(m):
		l = list(map(int, input().split()))
		matrix.append(l)
	for i in range(m):
		for j in range(n):
			r.append(matrix[i][j])
	r.sort()
	f = r[::-1]
	for i in range(len(f)):
		if i % 2 == 0:
			cyborg = cyborg + f[i]
		else:
			geno = geno + f[i]
	if cyborg > geno:
		print('Cyborg')
	elif cyborg < geno:
		print('Geno')
	else:
		print('Draw')


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		a = []
		a = list(map(int, input().split()))
		matrix.append(a)
	lt = []
	cy = 0
	ge = 0
	for i in range(n):
		for j in range(m):
			lt.append(int(matrix[i][j]))
	lt.sort(reverse=True)
	for i in range(len(lt)):
		if i % 2 == 0:
			cy = cy + lt[i]
		else:
			ge = ge + lt[i]
	if ge > cy:
		print('Geno')
	elif cy > ge:
		print('Cyborg')
	else:
		print('Draw')


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = []
	for t in range(n):
		arr += [int(x) for x in input().split()]
	arr = sorted(arr, reverse=True)
	(c, g) = (0, 0)
	for i in range(len(arr)):
		if i % 2 == 0:
			c += arr[i]
		else:
			g += arr[i]
	if c > g:
		print('Cyborg')
	elif g > c:
		print('Geno')
	else:
		print('Draw')


try:
	testcases = int(input())
	while testcases:
		(N, M) = map(int, input().split())
		arr = []
		for i in range(N):
			arr.extend(list(map(int, input().split())))
			arr.sort(reverse=True)
		sumC = sumG = 0
		for i in range(N * M):
			if i % 2 == 0:
				sumC += arr[i]
			else:
				sumG += arr[i]
		if sumG > sumC:
			print('Geno')
		elif sumC > sumG:
			print('Cyborg')
		else:
			print('Draw')
		testcases -= 1
except:
	pass


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for _ in range(n):
		li = list(map(int, input().split()))
		l += li
	l.sort()
	l = l[::-1]
	(a, b) = (0, 0)
	for x in range(0, len(l), 2):
		a += l[x]
		if x + 1 < len(l):
			b += l[x + 1]
	if a > b:
		print('Cyborg')
	elif b > a:
		print('Geno')
	else:
		print('Draw')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	m = []
	cyn = 0
	gen = 0
	for i in range(n):
		l = list(map(int, input().split()))
		m += l
	m.sort(reverse=True)
	for i in range(len(m)):
		if i % 2 == 0 or i == 0:
			cyn += m[i]
		else:
			gen += m[i]
	if gen == cyn:
		print('Draw')
	elif gen > cyn:
		print('Geno')
	else:
		print('Cyborg')


t = int(input())
for z in range(t):
	s1 = 0
	s2 = 0
	f = True
	(x, y) = map(int, input().split())
	l = []
	for k in range(x):
		l.extend(list(map(int, input().split())))
	l.sort()
	for i in l[::-1]:
		if f:
			s1 += i
			f = False
		else:
			s2 += i
			f = True
	if s1 == s2:
		print('Draw')
	elif s1 > s2:
		print('Cyborg')
	else:
		print('Geno')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	m = []
	for i in range(n):
		mat = list(map(int, input().split()))
		m.extend(mat)
	m.sort()
	b = 1
	c = 0
	g = 0
	for val in m[::-1]:
		if b == 1:
			c += val
			b = 0
		elif b == 0:
			g += val
			b = 1
	if c > g:
		print('Cyborg')
	elif g > c:
		print('Geno')
	else:
		print('Draw')


t = int(input())
for ni in range(t):
	(n, m) = map(int, input().split())
	l = list()
	for nj in range(n):
		a = list(map(int, input().split()))
		for i in a:
			l.append(i)
	l.sort(reverse=True)
	(sc, sg) = (0, 0)
	x = 0
	for i in l:
		if x == 0:
			x = 1
			sc = sc + i
		else:
			x = 0
			sg = sg + i
	if sc > sg:
		print('Cyborg')
	elif sg > sc:
		print('Geno')
	else:
		print('Draw')


tc = int(input().strip())
for t in range(tc):
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		matrix.extend(list(map(int, input().split())))
	matrix.sort(reverse=True)
	(cyborg, geno) = (0, 0)
	for i in range(len(matrix)):
		if i % 2 == 0:
			cyborg += matrix[i]
		else:
			geno += matrix[i]
	if cyborg == geno:
		print('Draw')
	else:
		print('Cyborg')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	M = []
	for _ in range(n):
		M.extend(list(map(int, input().split())))
	M.sort()
	flag = True
	c = 0
	g = 0
	for i in M[::-1]:
		if flag:
			c += i
			flag = False
		else:
			g += i
			flag = True
	if c > g:
		print('Cyborg')
	elif c < g:
		print('Geno')
	else:
		print('Draw')


t = int(input())
while t != 0:
	(r, c) = map(int, input().split())
	l = []
	while r != 0:
		ls = list(map(int, input().split()))
		l.extend(ls)
		r -= 1
	l.sort(reverse=True)
	cy = gn = 0
	for k in range(0, len(l)):
		if k % 2 == 0:
			cy += l[k]
		else:
			gn += l[k]
	if cy > gn:
		print('Cyborg')
	elif gn > cy:
		print('Geno')
	else:
		print('Draw')
	t -= 1


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	v = []
	for i in range(n):
		v += list(map(int, input().split()))
	v.sort(reverse=True)
	sc = sum(v[::2])
	sg = sum(v[1::2])
	if sc == sg:
		print('Draw')
	elif sc > sg:
		print('Cyborg')
	else:
		print('Geno')


for tc in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.extend(list(map(int, input().split())))
	(pick, cyborg, geno, turn) = (0, 0, 0, 1)
	while len(a) > 0:
		pick = max(a)
		a.remove(pick)
		if turn == 1:
			cyborg += pick
			turn = 0
		else:
			geno += pick
			turn = 1
	if cyborg > geno:
		print('Cyborg')
	elif geno > cyborg:
		print('Geno')
	else:
		print('Draw')


t = int(input())
for i in range(t):
	l = []
	(r, c) = map(int, input().split())
	for i in range(r):
		k = list(map(int, input().split()))
		l += k
	l.sort()
	if sum(l[-1::-2]) > sum(l[-2::-2]):
		print('Cyborg')
	elif sum(l[-1::-2]) < sum(l[-2::-2]):
		print('Geno')
	else:
		print('Draw')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for _ in range(n):
		a += list(map(int, input().split()))
	a.sort(reverse=True)
	c = 0
	g = 0
	for i in range(len(a)):
		if (i + 1) % 2 != 0:
			c += a[i]
		else:
			g += a[i]
	if c > g:
		print('Cyborg')
	elif c == g:
		print('Draw')
	else:
		print('Geno')


for t in range(int(input())):
	(n, m) = map(int, input().split())
	k = []
	for i in range(n):
		k += list(map(int, input().split()))
	k.sort(reverse=True)
	Cyborg = 0
	Geno = 0
	for i in range(len(k)):
		if (i + 1) % 2 != 0:
			Cyborg += k[i]
		else:
			Geno += k[i]
	if Cyborg > Geno:
		print('Cyborg')
	elif Cyborg == Geno:
		print('Draw')
	else:
		print('Geno')


for _ in range(int(input())):
	(N, M) = map(int, input().split())
	M = []
	for i in range(N):
		l = list(map(int, input().split()))
		M.extend(l)
	M.sort()
	b = 1
	c = 0
	g = 0
	for val in M[::-1]:
		if b == 1:
			c += val
			b = 0
		elif b == 0:
			g += val
			b = 1
	if c > g:
		print('Cyborg')
	elif c < g:
		print('Geno')
	else:
		print('Draw')


t = int(input())
for _ in range(0, t):
	(n, x) = map(int, input().split())
	m = []
	c = 0
	d = 0
	k = 0
	for i in range(0, n):
		m.extend(list(map(int, input().split())))
	m.sort(reverse=True)
	for i in m[:]:
		if k % 2 == 0:
			c = c + i
		else:
			d = d + i
		k = k + 1
	if c > d:
		print('Cyborg')
	elif c == d:
		print('Draw')
	else:
		print('Geno')


def bulk_input():
	return [int(j) for j in input().split()]

def problem():
	(n, m) = bulk_input()
	arr = []
	for it in range(n):
		a = bulk_input()
		for it2 in range(m):
			arr.append(a[it2])
	arr = sorted(arr)
	(s1, s2, f) = (0, 0, 0)
	size = n * m
	for it in range(size - 1, -1, -1):
		if f % 2 == 0:
			s1 += arr[it]
		else:
			s2 += arr[it]
		f += 1
	if s1 > s2:
		return 0
	elif s1 < s2:
		return 1
	return 2
for _ in range(int(input())):
	res = problem()
	if res == 0:
		print('Cyborg')
	elif res == 1:
		print('Geno')
	else:
		print('Draw')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l1 = list(map(int, input().split()))
		l.extend(l1)
	l = sorted(l)
	(c, g, b) = (0, 0, True)
	for i in l[::-1]:
		if b:
			c = c + i
			b = False
		else:
			g = g + i
			b = True
	if c > g:
		print('Cyborg')
	elif c == g:
		print('Draw')
	else:
		print('Geno')


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	l = []
	for row in range(r):
		l.append(list(map(int, input().split())))
	s = []
	for row1 in l:
		for col1 in row1:
			s.append(col1)
	for x in range(len(s)):
		if x != len(s) - 1:
			for y in range(x + 1, len(s)):
				if s[x] == s[y]:
					s[x] = 0
					s[y] = 0
	print('Draw' if all((v == 0 for v in s)) else 'Cyborg')


for I in range(int(input())):
	a = []
	(n, m) = map(int, input().split())
	while n:
		a += map(int, input().split())
		n -= 1
	a.sort(reverse=True)
	sumofcyborg = 0
	sumofgeno = 0
	for index in range(len(a)):
		if index % 2 == 0:
			sumofcyborg += int(a[index])
		else:
			sumofgeno += int(a[index])
	if sumofcyborg > sumofgeno:
		print('Cyborg')
	elif sumofgeno == sumofcyborg:
		print('Draw')
	else:
		print('Geno')


t = int(input())
for i in range(0, t):
	input1 = input().split()
	n = int(input1[0])
	m = int(input1[1])
	list1 = []
	for j in range(0, n):
		input2 = input().split()
		list1 += input2
	for k in range(0, len(list1)):
		list1[k] = int(list1[k])
	list1.sort(reverse=True)
	sumcyborg = 0
	sumgeno = 0
	l = 0
	for m in list1:
		if l % 2 == 0:
			sumcyborg += m
		else:
			sumgeno += m
		l += 1
	if sumcyborg == sumgeno:
		print('Draw')
	elif sumcyborg > sumgeno:
		print('Cyborg')
	else:
		print('Geno')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	nums = []
	for i in range(n):
		nums += list(map(int, input().split()))
	c = g = 0
	i = 1
	while nums != []:
		if i % 2 != 0:
			c += max(nums)
		else:
			g += max(nums)
		nums.remove(max(nums))
		i += 1
	if c > g:
		print('Cyborg')
	elif g > c:
		print('Geno')
	else:
		print('Draw')


for _ in range(int(input())):
	(N, M) = map(int, input().split())
	S = []
	for __ in range(N):
		S.extend(list(map(int, input().split())))
	S.sort()
	(Cyborg, Geno) = (0, 0)
	for __ in range(0, N * M, 2):
		Cyborg += S.pop()
		if S != []:
			Geno += S.pop()
	if Cyborg > Geno:
		print('Cyborg')
	elif Cyborg < Geno:
		print('Geno')
	else:
		print('Draw')


vishnesh = int(input())
for i in range(vishnesh):
	(n, m) = list(map(int, input().split()))
	arr = []
	for i in range(n):
		ar1 = list(map(int, input().split()))
		arr = arr + ar1
	arr.sort()
	s1 = 0
	s2 = 0
	for i in range(n * m):
		if i % 2 == 0:
			p = max(arr)
			s1 = s1 + p
			arr.remove(p)
		else:
			p = max(arr)
			s2 = s2 + p
			arr.remove(p)
	if s1 > s2:
		print('Cyborg')
	elif s2 > s1:
		print('Geno')
	else:
		print('Draw')


t = int(input())
for i in range(0, t):
	li = []
	cy = 0
	ge = 0
	(a, b) = map(int, input().split())
	for i in range(0, a):
		s = list(map(int, input().split()))
		li = li + s
	li.sort(reverse=True)
	for i in range(0, len(li)):
		if (i + 1) % 2 != 0:
			cy += li[i]
		else:
			ge += li[i]
	if cy > ge:
		print('Cyborg')
	elif cy == ge:
		print('Draw')
	else:
		print('Geno')


t = input()
for c in range(0, int(t)):
	(n, m) = input().split()
	arr = []
	for x in range(0, int(n)):
		a = input().split()
		for y in a:
			arr.append(int(y))
	arr.sort()
	cy = 0
	ge = 0
	flip = 0
	for z in range(len(arr) - 1, -1, -1):
		if flip == 0:
			cy = cy + arr[z]
			flip = 1
		else:
			ge = ge + arr[z]
			flip = 0
	if cy > ge:
		print('Cyborg')
	else:
		print('Draw')


_ = int(input())
for i in range(_):
	(x, y) = list(map(int, input().split()))
	arr = []
	for i in range(x):
		ar1 = list(map(int, input().split()))
		arr = arr + ar1
	arr.sort()
	arr.reverse()
	p1 = 0
	p2 = 0
	for i in range(x * y):
		if i % 2 == 0:
			p1 = p1 + arr[i]
		else:
			p2 = p2 + arr[i]
	if p1 > p2:
		print('Cyborg')
	elif p2 > p1:
		print('Geno')
	else:
		print('Draw')


T = int(input())
for tc in range(T):
	(N, M) = list(map(int, input().split(' ')))
	C = 0
	G = 0
	matrix = []
	for i in range(N):
		L = list(map(int, input().split(' ')))
		matrix.extend(L)
	matrix = sorted(matrix)
	matrix = matrix[::-1]
	for i in range(0, len(matrix), 2):
		C += matrix[i]
		if i < len(matrix) - 1:
			G += matrix[i + 1]
	if C > G:
		print('Cyborg')
	elif C < G:
		print('Geno')
	else:
		print('Draw')


_ = int(input())
for i in range(_):
	(n, m) = list(map(int, input().split()))
	arr = []
	for i in range(n):
		ar1 = list(map(int, input().split()))
		arr = arr + ar1
	arr.sort()
	arr.reverse()
	s1 = 0
	s2 = 0
	for i in range(n * m):
		if i % 2 == 0:
			s1 = s1 + arr[i]
		else:
			s2 = s2 + arr[i]
	if s1 > s2:
		print('Cyborg')
	elif s2 > s1:
		print('Geno')
	else:
		print('Draw')


for vishnesh in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		st = input().split()
		for j in range(m):
			val = int(st[j])
			arr.append(val)
	arr.sort()
	arr.reverse()
	cy = 0
	ge = 0
	for i in range(n * m):
		if i % 2 == 0:
			cy += arr[i]
		else:
			ge += arr[i]
	if cy == ge:
		print('Draw')
	elif cy > ge:
		print('Cyborg')
	else:
		print('Geno')


for _ in range(int(input())):
	(m, n) = map(int, input().split())
	l = [[int(j) for j in input().split()] for i in range(m)]
	g = 0
	c = 0
	s = []
	for i in range(m):
		for j in range(n):
			s.append(l[i][j])
	s.sort(reverse=True)
	for i in range(len(s)):
		if (i + 1) % 2 == 0:
			g += s[i]
		else:
			c += s[i]
	if c == g:
		print('Draw')
	elif c > g:
		print('Cyborg')
	else:
		print('Geno')


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = []
	for j in range(n):
		l1 = list(map(int, input().split()))
		l += l1
	l.sort(reverse=True)
	c = sum(l[0::2])
	g = sum(l[1::2])
	if c > g:
		print('Cyborg')
	elif c == g:
		print('Draw')
	else:
		print('Geno')


tests = int(input())
for i in range(tests):
	(rows, cols) = map(int, input().split())
	last_user = ''
	nums_dict = {}
	for j in range(rows):
		row = list(map(int, input().split()))
		for x in row:
			if x in nums_dict:
				nums_dict[x] += 1
			else:
				nums_dict[x] = 1
	cyborg = 0
	geno = 0
	nums_arr = sorted([*nums_dict.keys()], reverse=True)
	for j in nums_arr:
		if nums_dict[j] & 1:
			if last_user == '' or last_user == 'geno':
				cyborg += j
				last_user == 'cyborg'
			else:
				geno += j
				last_user == 'geno'
	if cyborg > geno:
		print('Cyborg')
	elif geno > cyborg:
		print('Geno')
	else:
		print('Draw')


for t in range(int(input())):
	[n, m] = [int(i) for i in input().split(' ')]
	a = []
	for i in range(n):
		a += [int(i) for i in input().split(' ')]
	(c, g) = (0, 0)
	a.sort(reverse=True)
	for i in range(n * m):
		if i % 2 == 0:
			c += a[i]
		else:
			g += a[i]
	if c > g:
		print('Cyborg')
	elif g > c:
		print('Geno')
	else:
		print('Draw')


from itertools import chain
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		M = list(map(int, input().split()))
		l += [M]
	flat_list = list(chain(*l))
	flat_list.sort()
	sumc = 0
	sumg = 0
	for i in range(n * m):
		if i % 2 == 0:
			sumc += flat_list[-1]
			flat_list.pop()
		else:
			sumg += flat_list[-1]
			flat_list.pop()
	if sumc > sumg:
		print('Cyborg')
	elif sumg > sumc:
		print('Geno')
	else:
		print('Draw')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for _ in range(n):
		s = list(map(int, input().split()))
		for k in s:
			l.append(k)
	l.sort(reverse=True)
	s = sum(l[::2])
	if s > sum(l) - s:
		print('Cyborg')
	elif s < sum(l) - s:
		print('Geno')
	else:
		print('Draw')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		a = list(map(int, input().split()))
		for j in a:
			l.append(j)
	l.sort(reverse=True)
	c = 0
	g = 0
	for i in range(m * n):
		if i % 2 == 0:
			c += l[i]
		else:
			g += l[i]
	if c == g:
		print('Draw')
	else:
		print('Cyborg')


for i in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		s = input().split()
		for j in range(m):
			r = int(s[j])
			arr.append(r)
	arr.sort(reverse=True)
	u = 0
	a = 0
	for i in range(n * m):
		if i in range(n * m):
			if i % 2 == 0:
				u += arr[i]
			else:
				a += arr[i]
	if u == a:
		print('Draw')
	elif u > a:
		print('Cyborg')
	else:
		print('Geno')


n = int(input())
for i in range(n):
	(m, k) = map(int, input().split())
	s = []
	for i in range(m):
		a = list(map(int, input().split()))
		s.extend(a)
	s.sort()
	c = []
	g = []
	for i in range(len(s)):
		if i % 2 == 0:
			c.append(s[-1 - i])
		else:
			g.append(s[-1 - i])
	if sum(c) > sum(g):
		print('Cyborg')
	elif sum(c) == sum(g):
		print('Draw')
	else:
		print('Geno')


for _ in range(int(input())):
	(t, q) = map(int, input().split(' '))
	inp = []
	for i in range(t):
		s = list(map(int, input().split(' ')))
		inp.extend(s)
	inp.sort()
	cy = []
	gen = []
	for i in range(len(inp)):
		if i % 2 == 0:
			cy.append(inp[-1 - i])
		else:
			gen.append(inp[-1 - i])
	if sum(cy) > sum(gen):
		print('Cyborg')
	elif sum(cy) < sum(gen):
		print('Geno')
	else:
		print('Draw')


t = int(input())
for i in range(t):
	(N, M) = map(int, input().split())
	c = []
	l = []
	for j in range(N):
		k = list(map(int, input().split()))
		c.append(k)
	for j in range(len(c)):
		for o in range(M):
			l.append(c[j][o])
	ans = 0
	l.sort(reverse=True)
	for j in range(0, len(l), 2):
		ans += l[j]
	if ans == sum(l) - ans:
		print('Draw')
	elif ans > sum(l) - ans:
		print('Cyborg')
	else:
		print('Geno')


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a += list(map(int, input().split()))
	a.sort(reverse=True)
	c = 0
	g = 0
	for i in range(len(a)):
		if i % 2 == 0:
			c += a[i]
		else:
			g += a[i]
	if c > g:
		print('Cyborg')
	else:
		print('Draw')