Tweedle-Dee and Tweedle-Dum are playing a fierce match of binary Nim. This novel game is played with $N$ stacks, each of them containing only $1$-s and $0$-s.
Just like in normal Nim, Tweedle-Dee and Tweedle-Dum alternate turns; in their turn, a player must choose one non-empty stack and remove a positive number of elements from the top of this stack. However, Tweedle-Dee may only choose a stack with $0$ at the top (and remove elements from it afterwards), and similarly, Tweedle-Dum may only choose a stack with $1$ at the top. the player that cannot make a move loses
Suzumo does not want to wait for the end of the game, so given the starting player he asks you to determine the winner. Remember that Tweedle-Dee and Tweedle-Dum are legendary grandmasters of combinatorial games, so both always play optimally.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains an integer $N$, a string $S$ denoting the number of stacks, the player that starts the game, respectively.
- Each of the following $N$ lines contains a single binary string $B$ representing a stack; the first character of $B$ corresponds to the top element of the stack and the last character to the bottom element.

-----Output-----
For each test case, print a single line containing the string "Dee" if Tweedle-Dee wins the match or "Dum" if Tweedle-Dum wins.

-----Constraints-----
- $1 \le T \le 500$
- $1 \le N \le 50$
- $1 \le |B| \le 50$
- each character in $B$ is either '1' or '0'
- $S$ is either "Dee" or "Dum"

-----Example Input-----
2
2 Dee
101
010
2 Dum
101
010

-----Example Output-----
Dum
Dee

Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Game theory

Ad-hoc

Starter code:

Solutions:
def binary_nim(stacks, first):
	(a, b) = (0, 0)
	for stack in stacks:
		if stack[0] == '0':
			a += stack.count('0')
		if stack[0] == '1':
			b += stack.count('1')
	if a == b:
		return 'Dum' if first == 'Dee' else 'Dee'
	else:
		return 'Dee' if a > b else 'Dum'
t = int(input())
for i in range(t):
	n = input()
	(n, s) = n.split()
	n = int(n)
	v = []
	for j in range(n):
		x = input()
		v.append(x)
	print(binary_nim(v, s))


from collections import Counter
t = int(input())
while t:
	(n, r) = map(str, input().strip().split())
	ne = 0
	nm = 0
	for k in range(int(n)):
		r1 = input()
		d = Counter(r1)
		if r1[0] == '1':
			nm = nm + d['1']
		else:
			ne = ne + d['0']
	if nm > ne:
		print('Dum')
	elif nm == ne:
		if r == 'Dee':
			print('Dum')
		else:
			print('Dee')
	else:
		print('Dee')
	t = t - 1


for i in range(int(input())):
	(n, s) = input().split(' ')
	n = int(n)
	dee = 0
	dum = 0
	for j in range(n):
		x = input()
		xl = [i for i in x]
		if x[0] == '0':
			dee += xl.count('0')
		else:
			dum += xl.count('1')
	if s == 'Dee':
		if dee == dum or dee < dum:
			print('Dum')
		else:
			print('Dee')
	elif dee == dum or dum < dee:
		print('Dee')
	else:
		print('Dum')


import math
t = int(input())
for i1 in range(t):
	(n, s) = input().split()
	n = int(n)
	a = []
	for i in range(n):
		a.append(input())
	x = 0
	y = 0
	for i in a:
		if i[0] == '1':
			x += i.count('1')
		else:
			y += i.count('0')
	if s == 'Dee':
		if x < y:
			print('Dee')
		else:
			print('Dum')
	elif x > y:
		print('Dum')
	else:
		print('Dee')


t = int(input())
names = ('Dee', 'Dum')
for _ in range(t):
	(n, s) = input().split()
	n = int(n)
	s = names.index(s)
	c = [0, 0]
	for _ in range(n):
		b = list(map(int, input()))
		c[b[0]] += b.count(b[0])
	print(names[c[0] == c[1] and s ^ 1 or c[0] < c[1]])


for _ in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	onec = 0
	zeroc = 0
	for i in range(a):
		stk = input()
		if stk[0] == '0':
			zeroc += stk.count('0')
		else:
			onec += stk.count('1')
	if b == 'Dee':
		if zeroc > onec:
			print('Dee')
		else:
			print('Dum')
	elif onec > zeroc:
		print('Dum')
	else:
		print('Dee')


t = int(input())
while t:
	(n, s) = input().split()
	n = int(n)
	Deec = 0
	Dumc = 0
	b = []
	for _ in range(n):
		x = input()
		if x[0] == '0':
			for i in x:
				if i == '0':
					Deec += 1
		if x[0] == '1':
			for i in x:
				if i == '1':
					Dumc += 1
	if s == 'Dee':
		if Deec > Dumc:
			print('Dee')
		else:
			print('Dum')
	elif Dumc > Deec:
		print('Dum')
	else:
		print('Dee')
	t -= 1


t = int(input())
for _ in range(t):
	(n, s) = input().split()
	c = [0, s == 'Dee']
	for _ in range(int(n)):
		b = input()
		c[b[0] == '1'] += b.count(b[0])
	print(('Dee', 'Dum')[c[0] < c[1]])


for testc in range(int(input())):
	(n, player) = input().strip().split()
	n = int(n)
	stacks = []
	for _ in range(n):
		stacks.append(input())
	counts = {0: 0, 1: 0}
	for stack in stacks:
		if stack[0] == '1':
			counts[1] += stack.count('1')
		else:
			counts[0] += stack.count('0')
	if player == 'Dee':
		if counts[0] > counts[1]:
			print('Dee')
		else:
			print('Dum')
	elif counts[1] > counts[0]:
		print('Dum')
	else:
		print('Dee')


for _ in range(int(input())):
	s = input().split()
	n = int(s[0])
	st = s[1]
	if st == 'Dee':
		d = st
		m = 'Dum'
	else:
		d = 'Dum'
		m = 'Dee'
	c = co = 0
	mt = []
	for i in range(n):
		mt.append(input())
	for i in range(n):
		if mt[i][0] == '1':
			for j in range(0, len(mt[i])):
				if mt[i][j] == '1':
					c += 1
		else:
			for j in range(0, len(mt[i])):
				if mt[i][j] == '0':
					co += 1
	if c == co:
		print(m)
		continue
	if co > c:
		print('Dee')
	else:
		print('Dum')


t = int(input())
for isd in range(t):
	(p, s) = input().split()
	p = int(p)
	a0 = []
	a1 = []
	a = []
	for i in range(p):
		s1 = input()
		a.append(s1)
		a0.append(s1.count('0'))
		a1.append(s1.count('1'))
	if s == 'Dee':
		tem = 0
	else:
		tem = 1
	ma = 0
	while True:
		if tem == 0:
			ma = 0
			for i in range(p):
				if a[i] == '':
					continue
				if a[i][0] == '0':
					ma = max(ma, a0[i])
			if ma == 0:
				print('Dum')
				break
			for i in range(p):
				if a[i] == '':
					continue
				if a[i][0] == '0':
					if a0[i] == ma:
						mai = i
						break
			s = a[mai]
			s = s[1:]
			if '0' not in s:
				a[mai] = ''
			else:
				tt = s.find('0')
				s = s[tt:]
				a[mai] = s
			tem = 1
			a0[mai] = a[mai].count('0')
			a1[mai] = a[mai].count('1')
		else:
			ma = 0
			for i in range(p):
				if a[i] == '':
					continue
				if a[i][0] == '1':
					ma = max(ma, a1[i])
			if ma == 0:
				print('Dee')
				break
			for i in range(p):
				if a[i] == '':
					continue
				if a[i][0] == '1':
					if a1[i] == ma:
						mai = i
						break
			s = a[mai]
			s = s[1:]
			if '1' not in s:
				a[mai] = ''
			else:
				tt = s.find('1')
				s = s[tt:]
				a[mai] = s
			tem = 0
			a1[mai] = a[mai].count('1')
			a0[mai] = a[mai].count('0')


for _ in range(int(input())):
	(n, s) = map(str, input().split())
	p = ''
	x = int(n)
	if s == 'Dee':
		p = 'Dum'
	elif s == 'Dum':
		p = 'Dee'
	(c0, c1) = (0, 0)
	for i in range(x):
		a = input()
		if a[0] == '0':
			c0 += a.count('0')
		else:
			c1 += a.count('1')
	if c1 > c0:
		print('Dum')
	elif c0 > c1:
		print('Dee')
	elif c0 == c1:
		print(p)


for t in range(int(input())):
	(n, m) = input().split()
	a = int(n)
	(c, d) = (0, 0)
	while a > 0:
		s = input()
		y = s[0]
		if y == '0':
			c += 1
		else:
			d += 1
		for i in range(1, len(s)):
			if s[i] == s[0]:
				if s[i] == '0':
					c = c + 1
				if s[i] == '1':
					d = d + 1
		a = a - 1
	if c == d:
		if m == 'Dee':
			print('Dum')
		if m == 'Dum':
			print('Dee')
	if c > d:
		print('Dee')
	if d > c:
		print('Dum')


for _ in range(int(input())):
	s = input().split()
	n = int(s[0])
	s1 = s[1]
	(a, b) = (0, 0)
	for i in range(n):
		x = input()
		if x[0] == '0':
			k0 = x.count('0')
			a += k0
		else:
			k1 = x.count('1')
			b += k1
	if a == b:
		if s1 == 'Dee':
			print('Dum')
		else:
			print('Dee')
	elif a > b:
		print('Dee')
	else:
		print('Dum')


def solve():
	p = input().split()
	n = int(p[0])
	s = p[1]
	(c_0, c_1) = (0, 0)
	for i in range(n):
		l = input()
		if l[0] == '1':
			c_1 += l.count('1')
		else:
			c_0 += l.count('0')
	if c_0 < c_1:
		return 'Dum'
	elif c_1 < c_0:
		return 'Dee'
	elif s == 'Dee':
		return 'Dum'
	else:
		return 'Dee'
for _ in range(int(input())):
	print(solve())


for t in range(int(input())):
	inp = input().split()
	n = int(inp[0])
	name = inp[1]
	(arr0, arr1) = ([], [])
	(dee, dum) = (0, 0)
	for i in range(n):
		temp = input()
		if temp[0] == '0':
			arr0.append(temp)
			for j in range(len(temp)):
				if temp[j] == '0':
					dee += 1
		else:
			arr1.append(temp)
			for j in range(len(temp)):
				if temp[j] == '1':
					dum += 1
	if dee > dum:
		print('Dee')
	elif dee < dum:
		print('Dum')
	elif name == 'Dee':
		print('Dum')
	else:
		print('Dee')


for i in range(int(input())):
	(a, string) = input().split()
	zero = 0
	one = 0
	for j in range(0, int(a)):
		k = input()
		if k[0] == '1':
			one += k.count('1')
		else:
			zero += k.count('0')
	if string == 'Dum':
		if one > zero:
			print('Dum')
		else:
			print('Dee')
	elif zero > one:
		print('Dee')
	else:
		print('Dum')


for _ in range(int(input())):
	(n, s) = input().split()
	n = int(n)
	a = []
	for i in range(n):
		a.append(input())
	x = 0
	y = 0
	for i in a:
		if i[0] == '1':
			x += i.count('1')
		else:
			y += i.count('0')
	if s == 'Dee':
		if x < y:
			print('Dee')
		else:
			print('Dum')
	elif x > y:
		print('Dum')
	else:
		print('Dee')


t = int(input())
for _ in range(t):
	arr = input().split()
	(i1, j1) = (0, 0)
	for _ in range(int(arr[0])):
		s = str(input())
		if s[0] == '0':
			i1 += s.count('0')
		else:
			j1 += s.count('1')
	if i1 == j1:
		if arr[1] == 'Dee':
			print('Dum')
		else:
			print('Dee')
	elif i1 > j1:
		print('Dee')
	else:
		print('Dum')


for u in range(int(input())):
	p = input().split()
	n = int(p[0])
	s = p[1]
	(x, y) = (0, 0)
	for i in range(n):
		l = input()
		if l[0] == '1':
			y += l.count('1')
		else:
			x += l.count('0')
	if x < y:
		print('Dum')
	elif y < x:
		print('Dee')
	elif s == 'Dee':
		print('Dum')
	else:
		print('Dee')


t = int(input())
for _ in range(t):
	countDee = 0
	countDum = 0
	(n, s) = input().split(maxsplit=1)
	n = int(n)
	s = str(s)
	for i in range(n):
		b = str(input())
		if b[0] == '0':
			countDee += b.count('0')
		else:
			countDum += b.count('1')
	if countDee > countDum:
		print('Dee')
	elif countDee == countDum:
		if 'Dee' in s:
			print('Dum')
		else:
			print('Dee')
	else:
		print('Dum')


T = int(input())
for cases in range(T):
	(a, b) = map(str, input().split())
	a = int(a)
	count = 0
	count_ = 0
	for i in range(a):
		s = input()
		if s[0:1] == '0':
			count += s.count('0')
		else:
			count_ += s.count('1')
	if b == 'Dee':
		if count > count_:
			print('Dee')
		else:
			print('Dum')
	elif count_ > count:
		print('Dum')
	else:
		print('Dee')


a = int(input())
for _ in range(a):
	a = input().split()
	count1 = 0
	count2 = 0
	for i in range(int(a[0])):
		bb = list(map(int, list(input())))
		if bb[0] == 0:
			count1 += bb.count(0)
		else:
			count2 += bb.count(1)
	if a[1] == 'Dee':
		if count1 > count2:
			print('Dee')
		else:
			print('Dum')
	elif count2 > count1:
		print('Dum')
	else:
		print('Dee')


t = int(input())
for i in range(t):
	(a, b) = list(input().split())
	l = []
	for i in range(int(a)):
		l.append(input())
	r = 0
	r1 = 0
	for i in range(len(l)):
		if l[i][0] == '0':
			r += l[i].count('0')
		else:
			r1 += l[i].count('1')
	if b == 'Dee':
		if r > r1:
			print('Dee')
		else:
			print('Dum')
	elif r1 > r:
		print('Dum')
	else:
		print('Dee')


for _ in range(int(input())):
	(n, p) = input().split()
	dee = dum = 0
	for i in range(int(n)):
		s = input()
		if s[0] == '0':
			dee += s.count('0')
		elif s[0] == '1':
			dum += s.count('1')
	if dee > dum:
		print('Dee')
	elif dum > dee:
		print('Dum')
	elif p == 'Dee':
		print('Dum')
	else:
		print('Dee')


t = int(input())
for i in range(t):
	(n, s) = input().strip().split()
	n = int(n)
	if s == 'Dee':
		other = 'Dum'
	else:
		other = 'Dee'
	o = 0
	z = 0
	f0 = 0
	f1 = 0
	for j in range(n):
		b = input()
		if f0 == 0 or f1 == 0:
			if b[0] == '1':
				f1 = 1
			elif b[0] == '0':
				f0 = 1
		if b[0] == '1':
			for k in b:
				if k == '1':
					o = o + 1
		else:
			for k in b:
				if k == '0':
					z = z + 1
	if f0 == 0:
		print('Dum')
		continue
	if f1 == 0:
		print('Dee')
		continue
	if o == z:
		print(other)
		continue
	if z > o:
		print('Dee')
	else:
		print('Dum')


t = int(input())
while t > 0:
	(n, m) = input().split()
	dee = 0
	dum = 0
	n = int(n)
	for i in range(0, n):
		k = input()
		l1 = list(map(int, k))
		if l1[0] == 1:
			dum += l1.count(1)
		else:
			dee += l1.count(0)
	if dee > dum:
		print('Dee')
	elif dee == dum:
		if m == 'Dee':
			print('Dum')
		else:
			print('Dee')
	else:
		print('Dum')
	t -= 1


t = int(input())
for i in range(t):
	dee = 0
	dum = 0
	[n, start] = input().split(' ')
	n = int(n)
	for k in range(n):
		pile = input()
		if pile[0] == '0':
			dee += pile.count('0')
		else:
			dum += pile.count('1')
	if start == 'Dum':
		if dum > dee:
			print('Dum')
		else:
			print('Dee')
	elif dum < dee:
		print('Dee')
	else:
		print('Dum')


for _ in range(int(input())):
	(n, s) = [x for x in input().split()]
	(n, s) = (int(n), str(s))
	if n == 1:
		st = input()
		if st[0] == '1':
			print('Dum')
		elif st[0] == '0':
			print('Dee')
	else:
		(dee, dum) = (0, 0)
		for i in range(n):
			st = input()
			l = list(st)
			if st[0] == '0':
				dee += l.count('0')
			else:
				dum += l.count('1')
		if dee > dum:
			print('Dee')
		elif dee < dum:
			print('Dum')
		elif s == 'Dee':
			print('Dum')
		else:
			print('Dee')


t = int(input())
while t:
	(n, s) = input().split()
	if s == 'Dee':
		b = 0
	else:
		b = 1
	l = list()
	for i in range(int(n)):
		l.append(list(input()))
	while True:
		if b == 0:
			for i in range(int(n)):
				if l[i] != []:
					if l[i][0] == '0':
						l[i].pop(0)
						st = l[i][:]
						for j in st:
							if j == '1':
								l[i].pop(0)
							else:
								break
						break
			else:
				break
			b = 1
		else:
			for i in range(int(n)):
				if l[i] != []:
					if l[i][0] == '1':
						l[i].pop(0)
						st = l[i][:]
						for j in st:
							if j == '0':
								l[i].pop(0)
							else:
								break
						break
			else:
				break
			b = 0
	if b == 1:
		print('Dee')
	else:
		print('Dum')
	t -= 1


t = int(input())
names = ('Dee', 'Dum')
for _ in range(t):
	(n, s) = input().split()
	n = int(n)
	s = names.index(s)
	c = [0, 0]
	for _ in range(n):
		b = list(map(int, input()))
		c[b[0]] += b.count(b[0])
	if c[0] == c[1]:
		print(names[s ^ 1])
	else:
		print(names[c[0] < c[1]])


t = int(input())
while t > 0:
	ar = input().split()
	n = int(ar[0])
	start = ar[1]
	player = 0
	deeC = 0
	dumC = 0
	if start == 'Dee':
		player = 0
	else:
		player = 1
	for i in range(0, n):
		ar = input()
		if ar[0] == '0':
			for ch in ar:
				if ch == '0':
					deeC = deeC + 1
		else:
			for ch in ar:
				if ch == '1':
					dumC = dumC + 1
	if deeC > dumC:
		print('Dee')
	elif dumC > deeC:
		print('Dum')
	elif player == 0:
		print('Dum')
	else:
		print('Dee')
	t = t - 1


for _ in range(int(input())):
	(n, s) = input().split()
	zeros = 0
	ones = 0
	for _ in range(int(n)):
		temp = input()
		if temp[0] == '0':
			zeros += temp.count('0')
		else:
			ones += temp.count('1')
	if zeros > ones:
		print('Dee')
	elif ones > zeros:
		print('Dum')
	elif s == 'Dee':
		print('Dum')
	else:
		print('Dee')


T = int(input())
for t in range(T):
	(a, b) = input().split()
	a = int(a)
	countdee = 0
	countdum = 0
	for i in range(a):
		s = input()
		if s[0] == '1':
			countdum += s.count('1')
		elif s[0] == '0':
			countdee += s.count('0')
	if countdee > countdum:
		print('Dee')
	elif countdee < countdum:
		print('Dum')
	elif b == 'Dee':
		print('Dum')
	else:
		print('Dee')


for _ in range(int(input())):
	x = input().split()
	n = int(x[0])
	start = x[1]
	d = {'1': 0, '0': 0}
	for i in range(n):
		a = input()
		if a[0] == '1':
			for j in a:
				if j == '1':
					d['1'] += 1
		else:
			for j in a:
				if j == '0':
					d['0'] += 1
	if d['1'] == d['0']:
		if start == 'Dee':
			print('Dum')
		else:
			print('Dee')
	elif d['1'] > d['0']:
		print('Dum')
	else:
		print('Dee')


for _ in range(int(input())):
	temp = list(input().split())
	n = int(temp[0])
	s = temp[1]
	(du, de) = (0, 0)
	for _ in range(n):
		mc = input()
		if mc[0] == '1':
			du += mc.count('1')
		else:
			de += mc.count('0')
	if de > du:
		print('Dee')
	elif de < du:
		print('Dum')
	elif s == 'Dee':
		print('Dum')
	else:
		print('Dee')


t = int(input())
while t:
	t -= 1
	deeCount = 0
	dooCount = 0
	[n, starter] = input().split(' ')
	n = int(n)
	while n:
		n -= 1
		stack = input()
		if stack[0] == '0':
			deeCount += stack.count('0')
		else:
			dooCount += stack.count('1')
	if starter == 'Dum':
		if dooCount > deeCount:
			print('Dum')
		else:
			print('Dee')
	elif dooCount < deeCount:
		print('Dee')
	else:
		print('Dum')


t = int(input())
while t > 0:
	(n, s) = map(str, input().split())
	n = int(n)
	c0 = 0
	c1 = 0
	for i in range(n):
		temp = str(input())
		if temp[0] == '0':
			c0 += temp.count('0')
		else:
			c1 += temp.count('1')
	if s == 'Dee':
		c0 -= 1
	else:
		c1 -= 1
	if c0 > c1:
		print('Dee')
	elif c0 < c1:
		print('Dum')
	else:
		print(s)
	t -= 1


t = int(input())
for i in range(t):
	str = input()
	str = str.split(' ')
	n = int(str[0])
	name = str[1]
	(count1, count0) = (0, 0)
	for j in range(n):
		tmp = input()
		if int(tmp[0]) is 1:
			for digit in tmp:
				if int(digit) is 1:
					count1 += 1
		else:
			for digit in tmp:
				if int(digit) is 0:
					count0 += 1
	if count0 < count1:
		print('Dum')
	elif count0 > count1:
		print('Dee')
	else:
		if name == 'Dee':
			print('Dum')
		if name == 'Dum':
			print('Dee')


for _ in range(int(input())):
	(N, S) = input().split()
	N = int(N)
	d0 = d1 = 0
	stacks = [0 for i in range(N)]
	for i in range(N):
		stacks[i] = input()
		if stacks[i][0] == '0':
			d0 += stacks[i].count('0')
		else:
			d1 += stacks[i].count('1')
	if S == 'Dee':
		if d0 <= d1:
			print('Dum')
		else:
			print('Dee')
	elif d1 <= d0:
		print('Dee')
	else:
		print('Dum')


for _ in range(int(input())):
	(n, per) = input().split()
	n = int(n)
	(z, o) = (0, 0)
	for i in range(n):
		s = input()
		if s[0] == '0':
			z += s.count('0')
		else:
			o += s.count('1')
	if per == 'Dee':
		if z > o:
			print('Dee')
		else:
			print('Dum')
	elif o > z:
		print('Dum')
	else:
		print('Dee')


t = int(input())
for _ in range(t):
	(n, s) = map(str, input().split())
	stacks = []
	for _ in range(int(n)):
		b = str(input())
		stacks.append(b)
	ones = 0
	zeros = 0
	for nim in stacks:
		if nim[0] == '0':
			zeros += nim.count('0')
		elif nim[0] == '1':
			ones += nim.count('1')
	if ones > zeros:
		print('Dum')
	elif zeros > ones:
		print('Dee')
	elif ones == zeros:
		if s == 'Dum':
			print('Dee')
		elif s == 'Dee':
			print('Dum')


t = int(input())
while t != 0:
	t -= 1
	temp = input().split()
	p1 = 'Dee'
	p2 = 'Dum'
	start = temp[1]
	if start == p1:
		start = 0
	else:
		start = 1
	n = int(temp[0])
	l = []
	for i in range(n):
		s = input()
		s = list(s)[::-1]
		s = [int(x) for x in s]
		l.append(s)
	while True:
		finished = False
		for s in l:
			done = False
			if s:
				if s[-1] == start:
					s.pop()
					done = True
					finished = True
				else:
					continue
			while s:
				if s[-1] != start:
					s.pop()
					done = True
					finished = True
				else:
					break
			if done:
				break
		if not finished:
			break
		start = 1 - start
	if start == 0:
		print('Dum')
	else:
		print('Dee')


from collections import Counter
for t in range(int(input())):
	(n, s) = input().split(' ')
	n = int(n)
	stacks = []
	count0s = 0
	count1s = 0
	for i in range(n):
		temp = input()
		if temp[0] == '0':
			count = Counter(temp)
			count0s += count['0']
		else:
			count = Counter(temp)
			count1s += count['1']
	if s == 'Dee':
		if count0s > count1s:
			print('Dee')
		else:
			print('Dum')
	elif count1s > count0s:
		print('Dum')
	else:
		print('Dee')


def main():
	t = int(input())
	for _ in range(t):
		(n, start) = input().split()
		win = ''
		if start == 'Dee':
			win = 'Dum'
		else:
			win = 'Dee'
		count = [0, 0]
		n = int(n)
		for __ in range(n):
			stck = input()
			top = int(stck[0])
			for c in stck:
				if int(c) == top:
					count[top] += 1
		if count[0] == count[1]:
			print(win)
		else:
			print('Dee') if count[0] > count[1] else print('Dum')
main()


T = int(input())
for _ in range(T):
	(N, S) = input().split()
	N = int(N)
	dee = 0
	dum = 0
	for _ in range(N):
		s = input()
		if s[0] == '0':
			dee += s.count('0')
		else:
			dum += s.count('1')
	m = min(dee, dum)
	dee -= m
	dum -= m
	if dee == 0 and dum == 0:
		if S == 'Dee':
			print('Dum')
		else:
			print('Dee')
	elif dee == 0:
		print('Dum')
	else:
		print('Dee')


for _ in range(int(input())):
	(n, s) = input().split()
	n = int(n)
	b = []
	for i in range(n):
		b.append(input())
	zero = 0
	one = 0
	for i in range(n):
		if b[i][0] == '0':
			zero += b[i].count('0')
		else:
			one += b[i].count('1')
	if s == 'Dee':
		if zero > one:
			print('Dee')
		else:
			print('Dum')
	elif one > zero:
		print('Dum')
	else:
		print('Dee')


T = int(input())
for i in range(T):
	(N, S) = input().split()
	Blist = []
	count0 = 0
	count1 = 0
	N = int(N)
	for j in range(N):
		B = list(input())
		if B[0] == '0':
			count0 += B.count('0')
		else:
			count1 += B.count('1')
	if S == 'Dee':
		if count0 > count1:
			print('Dee')
		else:
			print('Dum')
	elif count1 > count0:
		print('Dum')
	else:
		print('Dee')


def main():
	t = int(input())
	for _ in range(t):
		[n, s] = list(input().split())
		n = int(n)
		(one, zero) = (0, 0)
		for i in range(n):
			s1 = input()
			if s1[0] == '0':
				zero += s1.count('0')
			else:
				one += s1.count('1')
		if zero > one:
			print('Dee')
		elif zero < one:
			print('Dum')
		elif s == 'Dee':
			print('Dum')
		else:
			print('Dee')
main()


t = int(input())
while t > 0:
	ip = input().split()
	n = int(ip[0])
	name = ip[1]
	stack = []
	dee = 0
	dum = 0
	for i in range(n):
		l = list(input())
		if l[0] == '1':
			dum += l.count('1')
		else:
			dee += l.count('0')
	if dum > dee:
		print('Dum')
	elif dee > dum:
		print('Dee')
	elif name == 'Dee':
		print('Dum')
	else:
		print('Dee')
	t -= 1


tc = int(input())
for i in range(tc):
	(n, s) = input().split()
	n = int(n)
	t = 0
	d = 0
	for j in range(n):
		st = input()
		if st[0] == '0':
			t += st.count('0')
		else:
			d += st.count('1')
	if s == 'Dee':
		if t > d:
			print('Dee')
		else:
			print('Dum')
	elif d > t:
		print('Dum')
	else:
		print('Dee')


for _ in range(int(input())):
	(n, s) = input().split()
	n = int(n)
	c0 = 0
	c1 = 0
	for i in range(n):
		a = input()
		if a[0] == '0':
			c0 += a.count('0')
			continue
		c1 += a.count('1')
	if s == 'Dee':
		c0 -= 1
	else:
		c1 -= 1
	if c0 > c1:
		print('Dee')
	elif c0 < c1:
		print('Dum')
	else:
		print(s)


for t in range(int(input())):
	(n, s) = input().split()
	u = v = 0
	for i in range(0, int(n)):
		x = input()
		if x[0] == '1':
			u = u + x.count('1')
		else:
			v = v + x.count('0')
	if s == 'Dee' and u > v:
		print('Dum')
	elif s == 'Dee' and u == v:
		print('Dum')
	elif s == 'Dee' and u < v:
		print('Dee')
	elif s == 'Dum' and v > u:
		print('Dee')
	elif s == 'Dum' and u == v:
		print('Dee')
	elif s == 'Dum' and u > v:
		print('Dum')


t = int(input())
for j in range(t):
	(n, s) = input().split()
	(n, har, d1, d2, jan) = (int(n), [], [], [], 0)
	for i in range(n):
		har.append(input())
		if har[-1][0] == '0':
			d1.append(i)
		else:
			d2.append(i)
	ro = 1 if s == 'Dum' else 0
	while True:
		if ro == 1:
			if len(d2) == 0:
				jan = 0
				break
			z = har[d2[0]].find('1', 1)
			if z == -1:
				d2.pop(0)
			else:
				hv = har[d2[0]][z:]
				har[d2[0]] = hv
			ro = 0
		else:
			if len(d1) == 0:
				jan = 1
				break
			z = har[d1[0]].find('0', 1)
			if z == -1:
				d1.pop(0)
			else:
				hv = har[d1[0]][z:]
				har[d1[0]] = hv
			ro = 1
	if jan == 0:
		print('Dee')
	else:
		print('Dum')


t = int(input())
for _ in range(t):
	(n, s) = list(map(str, input().split()))
	n = int(n)
	(count1, count2) = (0, 0)
	for i in range(n):
		k = input()
		if k[0] == '0':
			count1 += k.count('0')
		elif k[0] == '1':
			count2 += k.count('1')
	if count1 == count2:
		if s == 'Dee':
			print('Dum')
		else:
			print('Dee')
	elif count1 > count2:
		print('Dee')
	else:
		print('Dum')


test_cases = int(input())
for i in range(test_cases):
	(n, s) = input().split()
	n = int(n)
	Dee = 0
	Dum = 0
	for j in range(n):
		st = input()
		if st[0] == '0':
			Dee += st.count('0')
		else:
			Dum += st.count('1')
	if s == 'Dee':
		if Dee > Dum:
			print('Dee')
		else:
			print('Dum')
	elif Dum > Dee:
		print('Dum')
	else:
		print('Dee')


for i in range(int(input())):
	a = list(input().split())
	(c1, c2) = (0, 0)
	for _ in range(int(a[0])):
		x = input().strip()
		if x.startswith('0'):
			c1 += x.count('0')
		else:
			c2 += x.count('1')
	if a[1] == 'Dee':
		if c1 > c2:
			print('Dee')
		else:
			print('Dum')
	elif c2 > c1:
		print('Dum')
	else:
		print('Dee')


for _ in range(int(input())):
	(n, bari) = input().split()
	my_arr = []
	for j in range(int(n)):
		my_arr.append(list(map(int, list(input()))))
	my_arr = sorted(my_arr)
	if bari == 'Dum':
		win = 'Dee'
	else:
		win = 'Dum'
	while my_arr:
		if win == 'Dum':
			if my_arr[0][0] == 0:
				del my_arr[0][0]
				win = 'Dee'
				try:
					a = my_arr[0].index(0)
					my_arr[0] = my_arr[0][a:]
				except ValueError:
					del my_arr[0]
			else:
				print(win)
				break
		if win == 'Dee' and my_arr:
			if my_arr[-1][0] == 1:
				del my_arr[-1][0]
				win = 'Dum'
				try:
					a = my_arr[-1].index(1)
					my_arr[-1] = my_arr[-1][a:]
				except ValueError:
					del my_arr[-1]
			else:
				print(win)
				break
		if not my_arr:
			print(win)


for z in range(int(input())):
	(n, p) = input().split()
	n = int(n)
	dee = 0
	dum = 0
	for j in range(n):
		a = list(input())
		if int(a[0]):
			for i in a:
				if i == '1':
					dum += 1
		else:
			for i in a:
				if i == '0':
					dee += 1
	if p == 'Dee':
		if dee > dum:
			print('Dee')
		else:
			print('Dum')
	elif dum > dee:
		print('Dum')
	else:
		print('Dee')


for t in range(int(input())):
	(n, m) = [x for x in input().split()]
	a = int(n)
	(n0, n1) = (0, 0)
	for i in range(a):
		s = input()
		z = s[0]
		if z == '0':
			n0 += 1
		else:
			n1 += 1
		for i in range(1, len(s)):
			if s[i] == s[0]:
				if s[i] == '0':
					n0 += 1
				if s[i] == '1':
					n1 += 1
	if n0 == n1:
		if m == 'Dee':
			print('Dum')
		if m == 'Dum':
			print('Dee')
	if n0 > n1:
		print('Dee')
	if n1 > n0:
		print('Dum')


t = int(input())
for i in range(t):
	(n, start_player) = input().strip().split(' ')
	n = int(n)
	stacks = [0] * n
	Deemoves = 0
	Dummoves = 0
	for j in range(n):
		stacks[j] = input()
		if stacks[j][0] == '0':
			Deemoves += stacks[j].count('0')
		else:
			Dummoves += stacks[j].count('1')
	winner = 'Dee'
	if Deemoves > Dummoves:
		winner = 'Dee'
	elif Deemoves < Dummoves:
		winner = 'Dum'
	elif start_player == 'Dee':
		winner = 'Dum'
	print(winner)


t = int(input())
for _ in range(t):
	(n, s) = map(str, input().split())
	n = int(n)
	(dee, dum) = (0, 0)
	for i in range(n):
		k = input()
		if k[0] == '1':
			dum += k.count('1')
		else:
			dee += k.count('0')
	if dum > dee:
		print('Dum')
	elif dee > dum:
		print('Dee')
	elif s == 'Dee':
		print('Dum')
	else:
		print('Dee')


T = [int(i) for i in input().split()]
for i in range(0, T[0]):
	L = []
	q = str(input())
	de = 0
	du = 0
	L = q.split(' ')
	for k in range(0, int(L[0])):
		m = str(input())
		if m[0] == '0':
			for n in m:
				if n == '0':
					de = de + 1
		else:
			for n in m:
				if n == '1':
					du = du + 1
	if L[1] == 'Dee':
		if de > du:
			print('Dee')
		else:
			print('Dum')
	elif du > de:
		print('Dum')
	else:
		print('Dee')


t = int(input())
for k in range(t):
	(n, s) = map(str, input().split())
	n = int(n)
	movedee = 0
	movedum = 0
	for i in range(n):
		x = input()
		a = len(x)
		if x[0] == '0':
			for i in range(a):
				if x[i] == '0':
					movedee += 1
		else:
			for i in range(a):
				if x[i] == '1':
					movedum += 1
	if movedee > movedum:
		print('Dee')
	elif movedum > movedee:
		print('Dum')
	elif s == 'Dee':
		print('Dum')
	else:
		print('Dee')


t = int(input())
for _ in range(t):
	(n, start) = input().split()
	n = int(n)
	(cdee, cdum) = (0, 0)
	for i in range(n):
		s = input()
		if s.startswith('1'):
			cdum += s.count('1')
		else:
			cdee += s.count('0')
	if start == 'Dee':
		if cdee > cdum:
			print('Dee')
		else:
			print('Dum')
	elif cdum > cdee:
		print('Dum')
	else:
		print('Dee')


for t in range(int(input())):
	(n, play) = input().split()
	n = int(n)
	flag_dee = False
	flag_dum = False
	if play == 'Dee':
		flag_dee = True
	else:
		flag_dum = True
	z = 0
	on = 0
	temp = ''
	for i in range(n):
		temp = input()
		m = len(temp)
		if temp[0] == '0':
			z += 1
			for j in range(1, m):
				if temp[j] == '1':
					continue
				else:
					z += 1
		else:
			on += 1
			for j in range(1, m):
				if temp[j] == '0':
					continue
				else:
					on += 1
	if z > on:
		print('Dee')
	elif z < on:
		print('Dum')
	elif flag_dee:
		print('Dum')
	else:
		print('Dee')


t = int(input())
for j in range(t):
	(n, s) = input().split()
	n = int(n)
	one = 0
	zero = 0
	for i in range(n):
		x = input()
		if x[0] == '1':
			one += x.count('1')
		else:
			zero += x.count('0')
	if s == 'Dee':
		if zero > one:
			print('Dee')
		else:
			print('Dum')
	elif one > zero:
		print('Dum')
	else:
		print('Dee')


t = int(input())
while t:
	t = t - 1
	(n, k) = input().split()
	n = int(n)
	if k == 'Dee':
		w = 'Dum'
	if k == 'Dum':
		w = 'Dee'
	dum = 0
	dee = 0
	while n != 0:
		x = input()
		if x[0] == '1':
			for i in x:
				if i == '1':
					dum = dum + 1
		if x[0] == '0':
			for i in x:
				if i == '0':
					dee = dee + 1
		n = n - 1
	if dum > dee:
		print('Dum')
	if dee > dum:
		print('Dee')
	if dee == dum:
		print(w)


for _ in range(int(input())):
	(n, d) = input().split()
	s = []
	for i in range(int(n)):
		s.append(input())
	cDee = 0
	cDum = 0
	for i in s:
		if i[0] == '1':
			cDum += i.count('1')
		else:
			cDee += i.count('0')
	if cDee == cDum:
		if d == 'Dee':
			print('Dum')
		else:
			print('Dee')
	elif cDum > cDee:
		print('Dum')
	else:
		print('Dee')


for _ in range(int(input())):
	(n, k) = [str(x) for x in input().split()]
	a = []
	dee_pos = 0
	dum_pos = 0
	for i in range(int(n)):
		a1 = input()
		a.append(a1)
		if a[i][0] == '0':
			for j in range(len(a[i])):
				if a[i][j] == '0':
					dee_pos += 1
		else:
			for j in range(len(a[i])):
				if a[i][j] == '1':
					dum_pos += 1
	if k == 'Dee':
		if dee_pos > dum_pos:
			print('Dee')
		else:
			print('Dum')
	elif dee_pos < dum_pos:
		print('Dum')
	else:
		print('Dee')


for i in range(int(input())):
	(n, p) = input().split()
	n = int(n)
	p = p.strip()
	l = []
	(dee, dum) = (0, 0)
	for i in range(n):
		l.append(input())
	for i in l:
		if i[0] == '0':
			dee += i.count('0')
		else:
			dum += i.count('1')
	if dee > dum:
		print('Dee')
	elif dee < dum:
		print('Dum')
	elif p == 'Dee':
		print('Dum')
	else:
		print('Dee')


for test in range(int(input())):
	(n, first) = map(str, input().split())
	n = int(n)
	ones = []
	zeros = []
	for i in range(n):
		s = input()
		if s[0] == '0':
			zeros.append(s.count('0'))
		else:
			ones.append(s.count('1'))
	ones = sum(ones)
	zeros = sum(zeros)
	if ones == zeros:
		if first == 'Dee':
			print('Dum')
		else:
			print('Dee')
	elif ones > zeros:
		print('Dum')
	else:
		print('Dee')


for _ in range(int(input())):
	(N, p1) = input().split()
	players = ['Dee', 'Dum']
	c0c1 = [0, 0]
	for i in range(int(N)):
		A = input()
		c0c1[int(A[0])] += A.count(A[0])
	st = players.index(p1)
	if c0c1[0] == c0c1[1]:
		print(players[int(not st)])
	else:
		s = c0c1.index(max(c0c1))
		print(players[s])