Read problems statements in [Hindi], [Spanish], [Mandarin chinese], [Russian], [Vietnamese] and [Bengali] as well.

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 for the first time wins.

Ada does not want to wait for the end of the game, so she asked you to determine the winner of the game if you are given the starting player. Remember that Tweedle-Dee and Tweedle-Dum are legendary grandmasters of combinatorial games, so they 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$, followed by a space and a string $S$ denoting the player that starts the game.
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 ≤ T ≤ 500$
$1 ≤ N ≤ 50$
$1 ≤ |B| ≤ 50$
each character in $B$ is either '1' or '0'
$S$ is either "Dee" or "Dum"

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

2 Dee

010

101
----- Sample Output 1 ------ 
Dee

Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Game theory

Ad-hoc

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(x, w) = input().split()
	d1 = d2 = 0
	for j in range(int(x)):
		y = input()
		if y[0] == '1' and y[-1] == '1':
			d1 += 1
		elif y[0] == '0' and y[-1] == '0':
			d2 += 1
	if d1 < d2:
		print('Dum')
	elif d2 < d1:
		print('Dee')
	else:
		print(w)


for _ in range(0, int(input())):
	(x, win) = input().split()
	dum = dee = 0
	for i in range(0, int(x)):
		y = input()
		if y[0] == '1' and y[-1] == '1':
			dum += 1
		elif y[0] == '0' and y[-1] == '0':
			dee += 1
	if dum < dee:
		print('Dum')
	elif dee < dum:
		print('Dee')
	else:
		print(win)


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


import math
try:
	t = int(input())
	while t > 0:
		t -= 1
		(n, name) = map(str, input().split())
		(zero, one) = (0, 0)
		for i in range(int(n)):
			s = input()
			if s[0] == '0' and s[-1] == '0':
				zero += 1
			elif s[0] == '0' and s[-1] == '1':
				zero += 1
				one += 1
			elif s[0] == '1' and s[-1] == '0':
				zero += 1
				one += 1
			else:
				one += 1
		if one > zero:
			print('Dee')
		elif zero > one:
			print('Dum')
		else:
			print(name)
except:
	pass


t = int(input())
for i in range(t):
	(n, s) = input().split()
	n = int(n)
	c1 = 0
	c2 = 0
	for i in range(n):
		b = list(input())
		if b[0] == '0' and b[-1] == '0':
			c1 += 1
		if b[0] == '1' and b[-1] == '1':
			c2 += 1
	if c1 > c2:
		print('Dum')
	elif c1 < c2:
		print('Dee')
	elif c1 == c2:
		print(s)


t = int(input())
for a in range(t):
	(n, s) = input().split()
	n = int(n)
	count_1 = 0
	count_0 = 0
	for i in range(n):
		arr = list(input())
		if arr[0] == '1' and arr[-1] == '1':
			count_1 += 1
		elif arr[0] == '0' and arr[-1] == '0':
			count_0 += 1
		elif arr[0] == '1' and arr[-1] == '0':
			count_0 += 1
			count_1 += 1
		elif arr[0] == '0' and arr[-1] == '1':
			count_0 += 1
			count_1 += 1
	if count_1 > count_0:
		print('Dee')
	elif count_0 > count_1:
		print('Dum')
	else:
		print(s)


t = int(input())
for t1 in range(0, t):
	(n, name) = input().split()
	c0 = 0
	c1 = 0
	for i in range(0, int(n)):
		x = input()
		if x[0] == x[-1]:
			if x[0] == '0':
				c0 += 1
			else:
				c1 += 1
	if name == 'Dee':
		if c0 <= c1:
			print('Dee')
		else:
			print('Dum')
	elif c1 <= c0:
		print('Dum')
	else:
		print('Dee')


t = int(input())
for i in range(t):
	(n, first) = input().split()
	n = int(n)
	dee_cnt = 0
	dum_cnt = 0
	for i in range(n):
		s = input()
		if s[0] == s[-1]:
			if s[0] == '0':
				dee_cnt += 1
			else:
				dum_cnt += 1
	if first == 'Dee':
		if dee_cnt <= dum_cnt:
			print('Dee')
		else:
			print('Dum')
	elif dee_cnt >= dum_cnt:
		print('Dum')
	else:
		print('Dee')


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


t = int(input())
while t > 0:
	t -= 1
	(n, first) = input().split()
	n = int(n)
	stack = []
	for i in range(n):
		stack.append(input())
	p = 0
	if 1:
		for i in range(n):
			if stack[i][0] == '0':
				if stack[i][-1] == '0':
					p += 1
			elif stack[i][-1] == '1':
				p -= 1
		if first == 'Dee':
			if p <= 0:
				print('Dee')
			else:
				print('Dum')
		elif p >= 0:
			print('Dum')
		else:
			print('Dee')


t = int(input())
for _ in range(t):
	(n, b) = map(str, input().split())
	n = int(n)
	l = []
	count1 = 0
	count2 = 0
	for i in range(n):
		a = input()
		if a[0] == '0':
			count1 += int(a[0] == a[-1])
		else:
			count2 += int(a[0] == a[-1])
	if b == 'Dee':
		if count2 >= count1:
			print('Dee')
		else:
			print('Dum')
	elif count2 <= count1:
		print('Dum')
	else:
		print('Dee')


T = int(input())
for t in range(T):
	(N, S) = input().split()
	N = int(N)
	stacks = []
	beg_w0 = 0
	beg_w1 = 0
	for n in range(N):
		s = input()
		stacks.append((s[0], s[-1]))
		if s[0] == '0':
			beg_w0 += 1
		if s[0] == '1':
			beg_w1 += 1
	stacks = sorted(stacks)
	FLAG = S == 'Dee'
	tg = False
	while any((x != 0 for x in [beg_w0, beg_w1])):
		if FLAG:
			if beg_w0 == 0:
				print('Dee')
				tg = True
				break
			else:
				beg_w0 -= 1
				for (i, (top, tail)) in enumerate(stacks):
					if top == '0':
						break
				FLAG = tail == '1'
				stacks.pop(i)
		elif beg_w1 == 0:
			print('Dum')
			tg = True
			break
		else:
			beg_w1 -= 1
			for (i, (top, tail)) in enumerate(stacks):
				if top == '1':
					break
			FLAG = tail == '1'
			stacks.pop(i)
	if not tg:
		print(['Dum', 'Dee'][FLAG])


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 += int(pile[0] == pile[-1])
		else:
			dum += int(pile[0] == pile[-1])
	if start == 'Dum':
		if dum > dee:
			print('Dee')
		else:
			print('Dum')
	elif dum < dee:
		print('Dum')
	else:
		print('Dee')


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


for _ in range(int(input())):
	(n, first_player) = input().split()
	n = int(n)
	(dee, dum) = (0, 0)
	for i in range(n):
		stack = input()
		if stack[0] == '0' and stack[-1] == '0':
			dee += 1
		elif stack[0] == '1' and stack[-1] == '1':
			dum += 1
	if dee == dum:
		print(first_player)
	elif dee < dum:
		print('Dee')
	else:
		print('Dum')


t = int(input())
while t:
	step = 0
	(n, s) = map(str, input().split())
	n = int(n)
	dee = 0
	dum = 0
	b = []
	for i in range(n):
		b.append(input())
	for i in b:
		if i[0] == i[len(i) - 1]:
			if i[0] == '0':
				dee = dee + 1
			else:
				dum = dum + 1
	if s[1] == 'e':
		if dee <= dum:
			print('Dee')
		else:
			print('Dum')
	elif dee < dum:
		print('Dee')
	else:
		print('Dum')
	t = t - 1


t = int(input())
for _ in range(t):
	(n, st) = input().split()
	n = int(n)
	dum = 0
	dee = 0
	for i in range(n):
		b = input()
		if b[0] == b[-1]:
			if b[0] == '0':
				dum += 1
			else:
				dee += 1
	if st == 'Dee':
		if dum <= dee:
			print('Dee')
		else:
			print('Dum')
	elif dum < dee:
		print('Dee')
	else:
		print('Dum')


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


T = int(input())
for _ in range(T):
	(N, start) = input().split()
	(S, N) = ([], int(N))
	zeroc = onec = 0
	for _ in range(N):
		stack = input()
		i = 0
		while i < len(stack):
			if stack[i] == '0':
				while i < len(stack) and stack[i] == '0':
					i += 1
				zeroc += 1
			else:
				while i < len(stack) and stack[i] == '1':
					i += 1
				onec += 1
	if zeroc > onec:
		print('Dum')
	elif zeroc < onec:
		print('Dee')
	else:
		print(start)


t = int(input())
for _ in range(t):
	inp = input().split()
	n = int(inp[0])
	player = 0 if inp[1] == 'Dee' else 1
	moves = [0, 0]
	for _ in range(n):
		stack = input()
		if stack[0] != stack[-1]:
			continue
		moves[int(stack[0])] += 1
	winner = player
	if moves[player] > moves[1 - player]:
		winner = 1 - player
	print('Dee' if winner == 0 else 'Dum')


tc = int(input())
for i in range(tc):
	(n, s) = input().split()
	n = int(n)
	dee = 0
	dum = 0
	for j in range(n):
		st = input()
		l1 = len(st)
		if st[0] == '0' and st[l1 - 1] == '1':
			dee += 1
			dum += 1
		elif st[0] == '0' and st[l1 - 1] == '0':
			dee += 1
		elif st[0] == '1' and st[l1 - 1] == '0':
			dee += 1
			dum += 1
		elif st[0] == '1' and st[l1 - 1] == '1':
			dum += 1
	if s == 'Dee':
		if dee <= dum:
			print('Dee')
		else:
			print('Dum')
	elif dum <= dee:
		print('Dum')
	else:
		print('Dee')


for _ in range(int(input())):
	(n, start) = input().split()
	n = int(n)
	zeroc = 0
	onec = 0
	for _ in range(n):
		s = input()
		i = 0
		while i < len(s):
			if s[i] == '0':
				while i < len(s) and s[i] == '0':
					i += 1
				zeroc += 1
			else:
				while i < len(s) and s[i] == '1':
					i += 1
				onec += 1
	if zeroc > onec:
		print('Dum')
	elif zeroc < onec:
		print('Dee')
	else:
		print(start)


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


notc = int(input())
while notc != 0:
	i = input()
	n = int(i.split()[0])
	st = i.split()[1]
	if st == 'Dee':
		player = 0
	else:
		player = 1
	x = 0
	y = 0
	for i in range(int(n)):
		inp = list(input())
		if inp[0] == '0' and inp[-1] == '0':
			x += 1
		elif inp[0] == '1' and inp[-1] == '1':
			y += 1
	if x > y:
		print('Dum')
	elif y > x:
		print('Dee')
	else:
		print(st)
	notc -= 1


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


t = int(input())
for _ in range(t):
	(n, p) = input().strip().split(' ')
	n = int(n)
	one = 0
	zero = 0
	for i in range(n):
		v = list(input())
		if v[0] == '1':
			one = one + 1
			if v[-1] == '0':
				zero = zero + 1
		else:
			zero = zero + 1
			if v[-1] == '1':
				one = one + 1
	if one == zero:
		print(p)
	elif one > zero:
		print('Dee')
	else:
		print('Dum')


t = int(input())
for _ in range(t):
	(n, s) = input().split()
	n = int(n)
	c1 = 0
	c = 0
	for i in range(n):
		h = list(input())
		if h[0] == '1' and h[-1] == '1':
			c1 += 1
		elif h[0] == '0' and h[-1] == '0':
			c += 1
		else:
			c1 += 1
			c += 1
	if c1 > c:
		print('Dee')
	elif c > c1:
		print('Dum')
	else:
		print(s)


for _ in range(int(input())):
	(n, pl) = input().split()
	n = int(n)
	stack = []
	for i in range(n):
		stack.append(list(input()))
	if pl == 'Dee':
		st = 0
	else:
		st = 1
	while True:
		if st % 2 == 1:
			for i in range(len(stack)):
				if len(stack[i]) != 0:
					if stack[i][0] == '1':
						while len(stack[i]) != 0 and stack[i][0] != '0':
							stack[i].pop(0)
						break
			else:
				print('Dum')
				break
		else:
			for i in range(len(stack)):
				if len(stack[i]) != 0:
					if stack[i][0] == '0':
						while len(stack[i]) != 0 and stack[i][0] != '1':
							stack[i].pop(0)
						break
			else:
				print('Dee')
				break
		st += 1


t = int(input())
while t:
	t -= 1
	(n, x) = input().split()
	n = int(n)
	dee = dum = 0
	for i in range(n):
		a = input() + '2'
		for j in range(len(a) - 1):
			if a[j] != a[j + 1]:
				if a[j] == '0':
					dee += 1
				else:
					dum += 1
	if x == 'Dee':
		if dee <= dum:
			print('Dee')
		else:
			print('Dum')
	elif dee < dum:
		print('Dee')
	else:
		print('Dum')


t = int(input())
for _ in range(t):
	(n, player) = input().split()
	one = 0
	zer = 0
	for i in range(int(n)):
		stack = input()
		if stack[0] == '0':
			zer += 1
			top = '0'
		else:
			one += 1
			top = '1'
		for bit in stack[1:]:
			if top == bit:
				continue
			elif bit == '0':
				zer += 1
				top = '0'
			else:
				one += 1
				top = '1'
	if zer == one:
		print(player)
	elif zer > one:
		print('Dum')
	else:
		print('Dee')


cases = int(input())
for _ in range(cases):
	(stacks, player) = input().split()
	stack_count = int(stacks)
	result = 0
	for stack in range(stack_count):
		bin_string = input()
		limit = len(bin_string) - 1
		if bin_string[0] == '0' and bin_string[limit] == '0':
			result -= 1
		elif bin_string[0] == '1' and bin_string[limit] == '1':
			result += 1
		else:
			pass
	if result > 0:
		print('Dee')
	elif result < 0:
		print('Dum')
	else:
		print(player)


t = int(input())
for i in range(t):
	(n, s) = input().split()
	n = int(n)
	countzero = 0
	countone = 0
	for j in range(n):
		a = input()
		f = len(a)
		if a[0] == a[f - 1]:
			if a[0] == '0':
				countzero = countzero + 1
			else:
				countone = countone + 1
	if s == 'Dee':
		if countzero <= countone:
			print('Dee')
		else:
			print('Dum')
	elif countone <= countzero:
		print('Dum')
	else:
		print('Dee')


t = int(input())
for i in range(0, t):
	(n, name) = input().rsplit(None, 1)
	n = int(n)
	binary = [None] * n
	for j in range(0, n):
		binary[j] = input()
	count1 = 0
	count2 = 0
	for i in range(0, len(binary)):
		if binary[i][0] == '0' and binary[i][-1] == '0':
			count1 += 1
		if binary[i][0] == '1' and binary[i][-1] == '1':
			count2 += 1
		if binary[i][0] == '0' and binary[i][-1] == '1':
			count1 += 1
			count2 += 1
		else:
			count2 += 1
			count1 += 1
	if count1 > count2:
		print('Dum')
	elif count1 == count2:
		print(name)
	else:
		print('Dee')


for _ in range(int(input())):
	(n, b) = input().strip().split()
	n = int(n)
	arr = [list(input().strip()) for i in range(n)]
	zero = 0
	one = 0
	for i in range(n):
		if arr[i][0] == '0':
			zero += 1
			last = 0
		else:
			one += 1
			last = 1
		for j in range(1, len(arr[i])):
			if int(arr[i][j]) ^ last == 1:
				if int(arr[i][j]) == 0:
					zero += 1
					last = 0
				else:
					one += 1
					last = 1
	if b == 'Dee':
		if zero <= one:
			print('Dee')
		else:
			print('Dum')
	elif zero >= one:
		print('Dum')
	else:
		print('Dee')


import sys

def testing(N, S, B):
	dee = 0
	dum = 0
	for b in B:
		if b[0] == '0' and b[len(b) - 1] == '0':
			dee += 1
		if b[0] == '1' and b[len(b) - 1] == '1':
			dum += 1
	if dee == dum:
		return S
	else:
		return 'Dum' if dee > dum else 'Dee'

def main():
	T = int(input())
	D = {}
	for j in range(T):
		(N, S) = input().split()
		N = int(N)
		B = [0] * N
		for i in range(int(N)):
			B[i] = list(input())
		D[j] = (N, S, B)
	for (k, v) in D.items():
		(N, S, B) = v
		print(testing(N, S, B))
	return 0
main()


t = int(input())
for a in range(t):
	(n, s) = input().split()
	stack = []
	n = int(n)
	if s == 'Dee':
		s1 = 'Dum'
	else:
		s1 = 'Dee'
	count_1 = 0
	count_0 = 0
	len_0 = []
	len_1 = []
	for i in range(n):
		arr = list(input())
		if arr[0] == '1' and arr[-1] == '1':
			count_1 += 1
		elif arr[0] == '0' and arr[-1] == '0':
			count_0 += 1
		elif arr[0] == '1' and arr[-1] == '0':
			count_0 += 1
			count_1 += 1
		elif arr[0] == '0' and arr[-1] == '1':
			count_0 += 1
			count_1 += 1
		stack.append(arr)
	if count_1 > count_0:
		print('Dee')
	elif count_0 > count_1:
		print('Dum')
	else:
		print(s)


def f():
	inp = list(input().split())
	n = int(inp[0])
	curr = inp[1]
	li_1_dum = []
	li_0_dee = []
	play = ['Dee', 'Dum']
	ind = play.index(curr)
	for i in range(n):
		stack = input()
		if stack[0] == '0':
			li_0_dee.append(stack[::-1])
		else:
			li_1_dum.append(stack[::-1])
	if ind == 0 and (not li_0_dee):
		return play[0]
	elif ind == 1 and (not li_1_dum):
		return play[1]
	while li_1_dum or li_0_dee:
		if ind == 0:
			if not li_0_dee:
				return play[ind]
			if li_0_dee[0][0] == '1':
				li_1_dum.append(li_0_dee[0][0])
			li_0_dee.pop(0)
			ind = 1 - ind
		if ind == 1:
			if not li_1_dum:
				return play[ind]
			if li_1_dum[0][0] == '0':
				li_0_dee.append(li_1_dum[0][0])
			li_1_dum.pop(0)
			ind = 1 - ind
	return play[ind]
test = int(input())
while test:
	print(f())
	test = test - 1


t = int(input())
for _ in range(t):
	(a, b) = input().split()
	a = int(a)
	if b == 'Dee':
		side = 0
	else:
		side = 1
	flag = 0
	winner = None
	c = [input() for __ in range(a)]
	while winner == None:
		if side == 0:
			flag = 0
			for i in range(a):
				if c[i] != '' and c[i][0] == '0':
					c[i] = c[i][c[i].rfind('0') + 1:]
					flag = 1
					break
			if flag == 1:
				side = 1
			else:
				winner = 'Dee'
				break
		else:
			flag = 0
			for i in range(a):
				if c[i] != '' and c[i][0] == '1':
					c[i] = c[i][c[i].rfind('1') + 1:]
					flag = 1
					break
			if flag == 1:
				side = 0
			else:
				winner = 'Dum'
				break
	print(winner)


for t in range(int(input())):
	(n, s) = input().split()
	n = int(n)
	stacks = []
	for i in range(n):
		stacks.append(input())
	x = 0
	y = 0
	for i in range(n):
		if stacks[i][0] == '0' and stacks[i][-1] == '0':
			x += 1
		elif stacks[i][0] == '1' and stacks[i][-1] == '1':
			y += 1
	if s == 'Dee':
		if x <= y:
			print('Dee')
		else:
			print('Dum')
	elif x < y:
		print('Dee')
	else:
		print('Dum')


for _ in range(int(input())):
	(n, s) = input().split()
	ans = 0
	for _1 in range(int(n)):
		b = input()
		if b[0] == b[-1] == '1':
			ans += 1
		elif b[0] == b[-1] == '0':
			ans -= 1
	print('Dee' if ans > 0 else 'Dum' if ans < 0 else s)


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


t = int(input())
for cas in range(t):
	(n, turn) = input().split()
	n = int(n)
	stacks = []
	for i in range(n):
		stacks.append(list(map(int, list(input())[::-1])))
	while True:
		got = False
		if turn == 'Dee':
			for i in range(len(stacks)):
				if len(stacks[i]) > 0:
					if stacks[i][len(stacks[i]) - 1] == 0:
						got = True
						while len(stacks[i]) != 0:
							if stacks[i][len(stacks[i]) - 1] != 0:
								break
							stacks[i].pop()
						turn = 'Dum'
						break
		else:
			for i in range(len(stacks)):
				if len(stacks[i]) > 0:
					if stacks[i][len(stacks[i]) - 1] == 1:
						got = True
						while len(stacks[i]) != 0:
							if stacks[i][len(stacks[i]) - 1] != 1:
								break
							stacks[i].pop()
						turn = 'Dee'
						break
		if not got:
			print(turn)
			break


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


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

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

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

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
nb_test = read_int()
for _ in range(nb_test):
	(nb_stacks, first) = read_strs()
	nb_stacks = int(nb_stacks)
	if first == 'Dee':
		second = 'Dum'
	else:
		second = 'Dee'
	(cnt_1, cnt_0) = (0, 0)
	for _ in range(nb_stacks):
		curr = read_str()
		if curr[0] == '1':
			cnt_1 += 1
			if curr[-1] == '0':
				cnt_0 += 1
		else:
			cnt_0 += 1
			if curr[-1] == '1':
				cnt_1 += 1
	if cnt_1 > cnt_0:
		print('Dee')
	elif cnt_0 > cnt_1:
		print('Dum')
	else:
		print(first)


t = int(input())
while t > 0:
	(n, start) = input().split()
	n = int(n)
	start = str(start)
	strings = []
	for i in range(n):
		st = str(input())
		strings.append(st)
	dee = 0
	dum = 0
	for sr in strings:
		c0 = 0
		c1 = 0
		tem = [sr[0]]
		for ch in sr:
			if tem[-1] != ch:
				tem.append(ch)
		for el in tem:
			if el == '1':
				c1 = c1 + 1
			else:
				c0 = c0 + 1
		dee = dee + c0
		dum = dum + c1
	if start == 'Dee' and dee <= dum:
		print('Dee')
	elif start == 'Dee' and dee > dum:
		print('Dum')
	elif start == 'Dum' and dee >= dum:
		print('Dum')
	else:
		print('Dee')
	t = t - 1


tc = int(input())
for test in range(tc):
	(n, p) = input().split()
	n = int(n)
	dee = dum = 0
	for i in range(n):
		a = input()
		if a[0] == '0' and a[-1] == '0':
			dee += 1
		elif a[0] == '1' and a[-1] == '1':
			dum += 1
		else:
			dee += 1
			dum += 1
	if dee < dum:
		print('Dee')
	elif dum < dee:
		print('Dum')
	else:
		print(p)


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
			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('Dee')
	else:
		print('Dum')


t = int(input())
for i in range(t):
	temp = list(input().split())
	n = int(temp[0])
	s = temp[1]
	arr = []
	for j in range(n):
		arr.append(input())
	if s == 'Dee':
		ifthere = '0'
	else:
		ifthere = '1'
	while True:
		present1 = False
		present2 = False
		for j in range(len(arr)):
			if arr[j][0] == ifthere:
				present1 = True
				for k in range(len(arr[j]) - 1):
					if arr[j][k + 1] != ifthere:
						arr[j] = arr[j][k + 1:]
						present2 = True
						break
				if present2 == False:
					arr.pop(j)
				break
		if present1 == False:
			break
		if ifthere == '1':
			ifthere = '0'
		else:
			ifthere = '1'
	if ifthere == '1':
		print('Dum')
	else:
		print('Dee')


t = int(input())
for i in range(t):
	a = 0
	b = 0
	(n, s) = input().split()
	n = int(n)
	for j in range(n):
		p = input()
		if p[0] == p[-1] and p[0] == '0':
			b += 1
		elif p[0] == p[-1]:
			a += 1
	if a > b:
		print('Dee')
	elif a < b:
		print('Dum')
	else:
		print(s)


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


for _ in range(int(input())):
	(n, start) = input().split()
	if start == 'Dee':
		current = 0
	elif start == 'Dum':
		current = 1
	li = []
	first = 1
	oper = -1
	for i in range(int(n)):
		l = list(map(int, list(input())))
		li.append(l)
		if l[0] == current and first == 1:
			oper = li.index(l)
			first = 0
	seti = 0
	while oper != -1:
		if oper == -1:
			break
		seti = 0
		cur = li[oper][0]
		while cur == current and len(li[oper]) != 0:
			li[oper].pop(0)
			try:
				cur = li[oper][0]
			except:
				pass
		if current == 0:
			current = 1
		else:
			current = 0
		for i in li:
			try:
				if i[0] == current:
					oper = li.index(i)
					seti = 1
					break
			except:
				continue
		if seti != 1:
			oper = -1
	if current == 0:
		print('Dee')
	else:
		print('Dum')


t = int(input())
for tc in range(t):
	game = input().split()
	n = int(game[0])
	if game[1] == 'Dee':
		p = '0'
		p2 = '1'
	else:
		p = '1'
		p2 = '0'
	st = []
	for i in range(n):
		s = input()
		st.append(list(s))
	won = 0
	while won == 0:
		found = 0
		for x in st:
			i = st.index(x)
			if x[0] == p:
				found = 1
				while x[0] != p2:
					x.pop(0)
					if len(x) == 0:
						st.pop(i)
						break
			if found == 1:
				break
		if found == 0:
			won = 1
			break
		else:
			temp = p
			p = p2
			p2 = temp
	if p == '0':
		print('Dee')
	else:
		print('Dum')


steps = 0

def check(l, x, count):
	global steps
	count = count + 1
	steps = count
	ans = 0
	index = 0
	for k in range(0, len(l)):
		if int(l[k][len(l[k]) - 1]) != x:
			continue
		else:
			ans = 1
			index = k
			break
	if ans == 0:
		return steps
	for k in range(len(l[index]) - 1, -1, -1):
		if int(l[index][k]) == x:
			l[index] = l[index][0:-1]
		else:
			break
	if l[index] == '':
		l.pop(index)
	if x == 0:
		return check(l, 1, count)
	else:
		return check(l, 0, count)
t = int(input())
for i in range(0, t):
	s = input()
	s = s.split()
	s[0] = int(s[0])
	l = []
	for j in range(0, s[0]):
		pulp = input()
		l.append(pulp)
	x = 0
	count = 0
	if s[1] == 'Dee':
		y = check(l, 0, count)
		if y % 2 != 0:
			print('Dee')
		else:
			print('Dum')
	if s[1] == 'Dum':
		y = check(l, 1, count)
		if y % 2 == 0:
			print('Dee')
		else:
			print('Dum')


def main():
	(n, name) = input().split()
	n = int(n)
	l1 = []
	l2 = []
	count = 0
	for i in range(n):
		x = input()
		if x[0] == '0':
			l1.append(x[::-1])
		else:
			l2.append(x[::-1])
	if name == 'Dee' and (not l1):
		print('Dee')
		return
	elif name == 'Dum' and (not l2):
		print('Dum')
		return
	while l1 or l2:
		if name == 'Dee' or not name:
			name = ''
			if not l1:
				print('Dee')
				return
			if l1[0][0] == '1':
				l2.append(l1[0][0])
			l1.pop(0)
		if name == 'Dum' or not name:
			name = ''
			if not l2:
				print('Dum')
				return
			if l2[0][0] == '0':
				l1.append(l2[0][0])
			l2.pop(0)
	print('Dee')
	return
t = int(input())
for i in range(t):
	main()


class Stack:
	stack = list()

	def __init__(self, stack):
		self.stack = stack

	def push(self, x):
		self.stack.append(x)

	def pop(self):
		if len(self.stack) != 0:
			return self.stack.pop()
		else:
			return '-1'

	def peek(self):
		if len(self.stack) != 0:
			return self.stack[-1]
		else:
			return '-1'

	def max_remove(self, s):
		count = 0
		stack_copy = self.stack[:]
		stack_copy.reverse()
		if s == 'Dee':
			for i in stack_copy:
				if i == '0':
					count += 1
				else:
					break
		elif s == 'Dum':
			for i in stack_copy:
				if i == '1':
					count += 1
				else:
					break
		return count

def main():
	for _ in range(int(input())):
		(n, s) = input().strip().split()
		stacks = list()
		for _ in range(int(n)):
			inp = list(input().strip())
			inp.reverse()
			stack = Stack(inp)
			stacks.append(stack)
		cannot = False
		while not cannot:
			cannot = True
			if s == 'Dee':
				m = 0
				choice = None
				for stack in stacks:
					rem = stack.max_remove(s)
					if rem > m:
						m = rem
						choice = stack
				for _ in range(m):
					cannot = False
					choice.pop()
				s = 'Dum'
			elif s == 'Dum':
				m = 0
				choice = None
				for stack in stacks:
					rem = stack.max_remove(s)
					if rem > m:
						m = rem
						choice = stack
				for _ in range(m):
					cannot = False
					choice.pop()
				s = 'Dee'
		if s == 'Dee':
			print('Dum')
		elif s == 'Dum':
			print('Dee')
main()


t = int(input())
for i in range(t):
	q = input()
	Q = q.split()
	n = int(Q[0])
	start = Q[1]
	stack = []
	var = 0
	for j in range(n):
		stack = stack + [input()]
		turn = start
	while var == 0:
		var = 1
		tempvar = 0
		if turn == 'Dee':
			for x in range(len(stack)):
				if len(stack[x]) != 0:
					if stack[x][0] == '0':
						var = 0
						ind = len(stack[x])
						for y in range(1, len(stack[x])):
							if stack[x][y] == '1':
								ind = y
								break
						stack[x] = stack[x][ind:]
						tempvar = 1
				if tempvar == 1:
					break
		else:
			for x in range(len(stack)):
				if len(stack[x]) != 0:
					if stack[x][0] == '1':
						var = 0
						ind = len(stack[x])
						for y in range(1, len(stack[x])):
							if stack[x][y] == '0':
								ind = y
								break
						stack[x] = stack[x][ind:]
						tempvar = 1
				if tempvar == 1:
					break
		if turn == 'Dee':
			turn = 'Dum'
		else:
			turn = 'Dee'
	if turn == 'Dee':
		turn = 'Dum'
	else:
		turn = 'Dee'
	print(turn)


for _ in range(int(input())):
	(a, b) = input().split()
	a = int(a)
	arr = [input() for __ in range(a)]
	winner = None
	if b == 'Dee':
		last = 'Dum'
	else:
		last = 'Dee'
	while winner == None:
		if last == 'Dum':
			flag = 0
			for i in range(a):
				if arr[i] != '' and arr[i][0] == '0':
					arr[i] = arr[i][arr[i].rfind('0') + 1:]
					flag = 1
					break
			if flag == 1:
				last = 'Dee'
			else:
				winner = 'Dee'
				break
		else:
			flag = 0
			for i in range(a):
				if arr[i] != '' and arr[i][0] == '1':
					arr[i] = arr[i][arr[i].rfind('1') + 1:]
					flag = 1
					break
			if flag == 1:
				last = 'Dum'
			else:
				winner = 'Dum'
				break
	print(winner)


for t in range(int(input())):
	(n, m) = input().split()
	a = int(n)
	(dee, dum) = (0, 0)
	for i in range(a):
		b = input()
		if b[0] == '0':
			dee += 1
		else:
			dum += 1
		for j in range(1, len(b)):
			if b[j] == '0':
				if b[j - 1] == '0':
					continue
				else:
					dee += 1
			elif b[j - 1] == '1':
				continue
			else:
				dum += 1
	if dee < dum:
		print('Dee')
	elif dee > dum:
		print('Dum')
	elif m == 'Dee':
		print('Dee')
	else:
		print('Dum')


t = int(input())
for i in range(t):
	s = input()
	s = s.split()
	n = int(s[0])
	s = s[1]
	c0 = c1 = 0
	for j in range(n):
		l = input()
		if l[0] == '0' and l[-1] == '0':
			c0 += 1
		elif l[0] == '1' and l[-1] == '1':
			c1 += 1
	if c0 == c1:
		print(s)
	elif c0 > c1:
		print('Dum')
	else:
		print('Dee')


t = int(input())
for cas in range(t):
	a = input().split(' ')
	(n, stp) = (int(a[0]), a[1])
	if stp == 'Dee':
		flag = 0
	else:
		flag = 1
	(zstack, ostack) = ([], [])
	for i in range(n):
		s = input()
		if s[0] == '0':
			zstack.append(s)
		else:
			ostack.append(s)
	while True:
		if flag == 0:
			if len(zstack) == 0:
				break
			foundo = False
			index = 0
			for i in range(len(zstack)):
				if '1' in zstack[i]:
					foundo = True
					index = i
					break
			if foundo:
				change = zstack[i]
				zstack.pop(i)
				trim = 0
				for i in range(len(change)):
					if change[i] == '1':
						trim = i
						break
				nchange = change[trim:]
				ostack.append(nchange)
			else:
				zstack = zstack[1:]
			flag = 1
		else:
			if len(ostack) == 0:
				break
			foundz = False
			index = 0
			for i in range(len(ostack)):
				if '0' in ostack[i]:
					foundz = True
					index = i
					break
			if foundz:
				change = ostack[i]
				ostack.pop(i)
				trim = 0
				for i in range(len(change)):
					if change[i] == '0':
						trim = i
						break
				nchange = change[trim:]
				zstack.append(nchange)
			else:
				ostack = ostack[1:]
			flag = 0
	if flag == 0:
		print('Dee')
	else:
		print('Dum')


for _ in range(int(input())):
	st = [x for x in input().split()]
	n = int(st[0])
	ns = st[1]
	dee = 0
	dum = 0
	for i in range(n):
		b = input()
		j = 1
		lb = len(b)
		if b[0] == '0':
			sk = '0'
		else:
			sk = '1'
		while j < lb:
			if sk == '0':
				if sk != b[j]:
					sk = '1'
					dee += 1
			elif sk != b[j]:
				sk = '0'
				dum += 1
			j += 1
		if sk == '0':
			dee += 1
		else:
			dum += 1
	if dee < dum:
		print('Dee')
	elif dum < dee:
		print('Dum')
	elif ns == 'Dee':
		print('Dee')
	else:
		print('Dum')


T = int(input())
for t in range(T):
	(N, S) = input().split()
	N = int(N)
	b = []
	for n in range(N):
		b.append(input())
	noofzeroes = 0
	noofones = 0
	for i in range(N):
		if b[i][0] == '0' and b[i][len(b[i]) - 1] == '0':
			noofzeroes += 1
		elif b[i][0] == '1' and b[i][len(b[i]) - 1] == '1':
			noofones += 1
	if S == 'Dee':
		if noofzeroes <= noofones:
			win = 'Dee'
		else:
			win = 'Dum'
	elif noofones <= noofzeroes:
		win = 'Dum'
	else:
		win = 'Dee'
	print(win)


def solve(N, dee, B):
	while True:
		move_i = -1
		nb = -1
		if dee:
			for (i, w) in enumerate(B):
				if len(w) == 0:
					continue
				count = 0
				while count < len(w) and w[count] == '0':
					count += 1
				if count != 0 and count > nb:
					nb = count
					move_i = i
			if move_i == -1:
				return 'Dee'
			B[move_i] = B[move_i][nb:]
			dee = not dee
		else:
			for (i, w) in enumerate(B):
				if len(w) == 0:
					continue
				count = 0
				while count < len(w) and w[count] == '1':
					count += 1
				if count != 0 and count > nb:
					nb = count
					move_i = i
			if move_i == -1:
				return 'Dum'
			B[move_i] = B[move_i][nb:]
			dee = not dee
T = int(input())
for i in range(0, T):
	(N, S) = input().split(' ')
	N = int(N)
	B = []
	for i in range(0, N):
		B.append(input())
	print(solve(N, S == 'Dee', B))


from collections import Counter
for i in range(int(input())):
	(n, s) = input().split()
	n = int(n)
	c = {'00': 0, '11': 0}
	for j in range(n):
		b = input()
		l = len(b)
		if l == 1:
			if b == '0':
				c['00'] = c['00'] + 1
			else:
				c['11'] = c['11'] + 1
		else:
			st = b[0] + b[l - 1]
			if st == '00':
				c['00'] = c['00'] + 1
			elif st == '11':
				c['11'] = c['11'] + 1
	if s == 'Dee':
		if c['00'] > c['11']:
			print('Dum')
		else:
			print('Dee')
	elif c['11'] > c['00']:
		print('Dee')
	else:
		print('Dum')


t = int(input())
for z in range(t):
	(n, s) = [x for x in input().split()]
	n = int(n)
	if s == 'Dee':
		j = 1
	else:
		j = 0
	a = []
	for i in range(n):
		l = input()
		a.append(l)
	while len(a) != 0:
		p = 0
		if j == 1:
			j = 0
			flag = 0
			for i in range(len(a)):
				if a[i][0] == '0':
					flag = 1
					st = a[i]
					for l in range(len(st)):
						if st[l] == '1':
							break
					if st.count('0') == len(st):
						del a[i]
					else:
						a[i] = st[l:]
					break
			if flag == 0:
				p = 1
		else:
			j = 1
			flag = 0
			for i in range(len(a)):
				if a[i][0] == '1':
					flag = 1
					st = a[i]
					for l in range(len(st)):
						if st[l] == '0':
							break
					if st.count('1') == len(st):
						del a[i]
					else:
						a[i] = st[l:]
					break
			if flag == 0:
				p = 1
		if p == 1:
			if j == 0:
				print('Dee')
			else:
				print('Dum')
			break
	if len(a) == 0:
		if j == 1:
			print('Dee')
		else:
			print('Dum')


tc = int(input())
while tc > 0:
	(n, s) = map(str, input().split())
	n = int(n)
	c0 = 0
	c1 = 0
	stack = []
	for i in range(n):
		temp = list(map(int, input()))
		stack.append(temp)
	t = str(s)
	while True:
		if t == 'Dee':
			for i in range(n):
				if len(stack[i]) == 0:
					continue
				else:
					while stack[i][0] == 0:
						del stack[i][0]
						t = 'Dum'
						if len(stack[i]) == 0:
							break
				if t == 'Dum':
					break
			if t == 'Dee':
				break
		else:
			for i in range(n):
				if len(stack[i]) == 0:
					continue
				else:
					while stack[i][0] == 1:
						del stack[i][0]
						t = 'Dee'
						if len(stack[i]) == 0:
							break
				if t == 'Dee':
					break
			if t == 'Dum':
				break
	print(t)
	tc -= 1


def fun():
	i = input()
	i = i.split(' ')
	n = int(i[0])
	if i[1] == 'Dee':
		first = 0
	else:
		first = 1
	l = []
	for j in range(n):
		s = str(input())
		l.append([int(s[0]), int(s[-1])])
	flag = 0
	u = 1
	while u <= n:
		try:
			for j in range(n):
				if l[j][0] == first:
					first = abs(l[j][1] - 1)
					flag = 1
					break
			if flag == 0:
				break
			else:
				l.pop(j)
				flag = 0
		except IndexError:
			if l == []:
				break
			pass
		u += 1
	if first == 1:
		print('Dum')
	else:
		print('Dee')
t = int(input())
for i in range(t):
	fun()


test_cases = int(input())
while test_cases > 0:
	(n, user) = input().split(' ')
	n = int(n)
	n_stack = []
	while n > 0:
		n_stack.append(list(input()))
		n -= 1
	while 1:
		found = False
		if user == 'Dee':
			i = 0
			while i < len(n_stack):
				j = 0
				while j < len(n_stack[i]):
					if n_stack[i][j] == '0':
						found = True
						del n_stack[i][j]
					else:
						break
				if found:
					break
				else:
					i += 1
			if not found:
				print(user)
				break
			user = 'Dum'
		else:
			i = 0
			while i < len(n_stack):
				j = 0
				while j < len(n_stack[i]):
					if n_stack[i][j] == '1':
						found = True
						del n_stack[i][j]
					else:
						break
				if found:
					break
				else:
					i += 1
			if not found:
				print(user)
				break
			user = 'Dee'
	test_cases -= 1


def perform():
	(num_stacks, choice_n) = input().split()
	num_stacks = int(num_stacks)
	choice = 0
	if choice_n == 'Dee':
		choice = 1
	num_dee = 0
	num_dum = 0
	for i in range(num_stacks):
		prev = -1
		for each in [int(i) for i in list(input())]:
			if each != prev:
				if each == 0:
					num_dee += 1
				else:
					num_dum += 1
			prev = each
	if num_dee == num_dum:
		print(choice_n)
		return
	if num_dee > num_dum:
		print('Dum')
		return
	print('Dee')
	return
for _ in range(int(input())):
	perform()


def main():
	t = int(input())
	for q in range(t):
		(n, s) = map(str, input().strip().split())
		n = int(n)
		vec = []
		for i in range(n):
			st = input()
			c_0 = 0
			c_1 = 0
			for j in range(len(st)):
				if st[j] == '0':
					c_0 += 1
				else:
					break
			for j in range(len(st)):
				if st[j] == '1':
					c_1 += 1
				else:
					break
			vec.append([st, c_0, c_1, 0])
		flag = 0
		if s == 'Dee':
			flag = 0
		else:
			flag = 1
		while 1:
			if flag == 0:
				m_v = 0
				ind = 0
				for i in range(n):
					if m_v < vec[i][1]:
						m_v = vec[i][1]
						ind = i
				if vec[ind][1] == 0:
					print('Dee')
					break
				vec[ind][3] += vec[ind][1]
				vec[ind][1] = 0
				vec[ind][2] = 0
				for i in range(vec[ind][3], len(vec[ind][0])):
					if vec[ind][0][i] == '0':
						vec[ind][1] += 1
					else:
						break
				for i in range(vec[ind][3], len(vec[ind][0])):
					if vec[ind][0][i] == '1':
						vec[ind][2] += 1
					else:
						break
				flag = 1
			else:
				m_v = -1
				ind = 0
				for i in range(n):
					if m_v < vec[i][2]:
						m_v = vec[i][2]
						ind = i
				if vec[ind][2] == 0:
					print('Dum')
					break
				vec[ind][3] += vec[ind][2]
				vec[ind][1] = 0
				vec[ind][2] = 0
				for i in range(vec[ind][3], len(vec[ind][0])):
					if vec[ind][0][i] == '0':
						vec[ind][1] += 1
					else:
						break
				for i in range(vec[ind][3], len(vec[ind][0])):
					if vec[ind][0][i] == '1':
						vec[ind][2] += 1
					else:
						break
				flag = 0
main()


for _ in range(int(input())):
	(n, s) = input().split()
	n = int(n)
	one = False
	zero = False
	co = 0
	cz = 0
	for i in range(n):
		t = input()
		k = t[0]
		l = t[0]
		for j in range(1, len(t)):
			if t[j] != l:
				if t[j] == '1':
					co += 1
				else:
					cz += 1
				k += t[j]
				l = t[j]
		if k[0] == '0':
			zero = True
			cz += 1
		else:
			one = True
			co += 1
	if s == 'Dee':
		if not zero or co >= cz:
			print(s)
		else:
			print('Dum')
	elif not one or cz >= co:
		print(s)
	else:
		print('Dee')


t = int(input())
for _ in range(t):
	(n, turn) = map(str, input().split())
	(n, dee, dum) = (int(n), [], [])
	for _ in range(n):
		tmp = input()
		if tmp[0] == '1':
			dum.append(tmp)
		else:
			dee.append(tmp)
	if turn == 'Dee':
		if len(dee) == 0:
			print('Dee')
			continue
		hold = dee.pop(0)
		if '1' in hold:
			dum.append(hold[hold.index('1'):])
		turn = 'Dum'
	else:
		if len(dum) == 0:
			print('Dum')
			continue
		hold = dum.pop(0)
		if '0' in hold:
			dee.append(hold[hold.index('0'):])
		turn = 'Dee'
	while len(dee) != 0 or len(dum) != 0:
		if turn == 'Dee':
			if len(dee) == 0:
				break
			hold = dee.pop(0)
			if '1' in hold:
				dum.append(hold[hold.index('1'):])
			turn = 'Dum'
		else:
			if len(dum) == 0:
				break
			hold = dum.pop(0)
			if '0' in hold:
				dee.append(hold[hold.index('0'):])
			turn = 'Dee'
	print(turn)


t = int(input())
for i in range(t):
	(a, b) = input().split()
	a = int(a)
	l = []
	count1 = 0
	count2 = 0
	for j in range(a):
		s = input()
		x = s[0]
		for k in range(1, len(s)):
			if s[k] != s[k - 1]:
				x = x + s[k]
		l.append(x)
	for j in range(a):
		count1 += l[j].count('1')
		count2 += l[j].count('0')
	if count1 > count2:
		print('Dee')
	elif count2 > count1:
		print('Dum')
	elif count1 == count2 and b == 'Dee':
		print('Dee')
	else:
		print('Dum')


for _ in range(int(input().strip())):
	(n, first_turn) = input().strip().split()
	n = int(n)
	stacks = []
	num_just_0 = 0
	num_just_1 = 0
	num_01 = 0
	num_10 = 0
	for i in range(n):
		string = input().strip()
		final_string = string[0] + string[-1] if len(string) > 1 else string[0] + string[0]
		if final_string[0] == final_string[1]:
			if final_string[0] == '0':
				num_just_0 += 1
			else:
				num_just_1 += 1
		else:
			if final_string[0] == '0':
				num_01 += 1
			else:
				num_10 += 1
			stacks.append(final_string)
	if num_just_0 > num_just_1:
		num_just_0 -= num_just_1
		num_just_1 = 0
	else:
		num_just_1 -= num_just_0
		num_just_0 = 0
	if first_turn == 'Dee':
		if num_just_0 > 0:
			print('Dum')
		else:
			print('Dee')
	elif num_just_1 > 0:
		print('Dee')
	else:
		print('Dum')


import copy
for i in range(int(input())):
	A = list(input().split())
	N = int(A[0])
	S = A[1]
	Stack0 = []
	Stack1 = []
	if S == 'Dee':
		chance = 0
	else:
		chance = 1
	for j in range(N):
		B = list(input())
		if B[0] == '0':
			Stack0.append(B)
		else:
			Stack1.append(B)
	flag = True
	while flag:
		if chance == 0:
			if len(Stack0) == 0:
				print('Dee')
				flag = False
			else:
				j = 0
				while j < len(Stack0):
					try:
						k = Stack0[j].index('1')
						Stack0[j] = Stack0[j][k:]
						Y = copy.deepcopy(Stack0[j])
						Stack0.pop(j)
						Stack1.append(Y)
						j = len(Stack0) + 1
					except:
						j += 1
				if j == len(Stack0):
					Stack0.pop(0)
		elif chance == 1:
			if len(Stack1) == 0:
				print('Dum')
				flag = False
			else:
				j = 0
				while j < len(Stack1):
					try:
						k = Stack1[j].index('0')
						Stack1[j] = Stack1[j][k:]
						Y = copy.deepcopy(Stack1[j])
						Stack1.pop(j)
						Stack0.append(Y)
						j = len(Stack1) + 1
					except:
						j += 1
				if j == len(Stack1):
					Stack1.pop(0)
		chance = 1 - chance


import math
for _ in range(int(input())):
	(n, s) = map(str, input().split())
	x = 0
	y = 0
	for i in range(int(n)):
		p = input()
		if p[0] == '0':
			x += 1
		else:
			y += 1
		for i in range(1, len(p)):
			if p[i] != p[i - 1]:
				if p[i] == '0':
					x += 1
				else:
					y += 1
	if x != y:
		if x > y:
			print('Dum')
		else:
			print('Dee')
	else:
		print(s)


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


for _ in range(int(input())):
	(n, player) = input().split()
	n = int(n)
	a = [input() for i in range(n)]
	p0 = 0
	p1 = 0
	for e in a:
		if e[0] == e[-1]:
			if e[0] == '0':
				p0 += 1
			else:
				p1 += 1
	if p0 > p1:
		print('Dum')
	elif p1 > p0:
		print('Dee')
	else:
		print(player)


def readInt():
	return int(input())

def readInts():
	return [int(x) for x in input().split()]
players = ['Dee', 'Dum']

def cases():
	numCases = readInt()
	for _ in range(numCases):
		(n, s) = input().split()
		n = int(n)
		s = players.index(s)
		stacks = [input().rstrip() for _ in range(n)]
		yield (n, s, stacks)

def solve(n, s, stacks):
	options = [[], []]
	for stack in stacks:
		initPlayer = int(stack[0])
		options[initPlayer].append(stack[0] == stack[-1])
	while True:
		if len(options[s]) == 0:
			return s
		swap = options[s].pop()
		if swap:
			s = 1 - s
for data in cases():
	print(players[solve(*data)])


def get_the_stack_index_to_start(stack_matrix, is_stack_empty, N, curr_player):
	if curr_player == 0:
		for i in range(N):
			if is_stack_empty[i] == False and stack_matrix[i][0] == 0:
				return i
		return -1
	else:
		for i in range(N):
			if is_stack_empty[i] == False and stack_matrix[i][0] == 1:
				return i
		return -1
T = int(input())
while T:
	(N, init_player) = input().split()
	N = int(N)
	curr_player = 0 if init_player == 'Dee' else 1
	stack_matrix = []
	i = 0
	while i < N:
		stack = [int(c) for c in input()]
		stack_matrix.append(stack)
		i += 1
	is_stack_empty = [False for _ in range(N)]
	while False in is_stack_empty:
		i = get_the_stack_index_to_start(stack_matrix, is_stack_empty, N, curr_player)
		if i == -1:
			break
		else:
			j = 0
			curr_value = curr_player
			while j < len(stack_matrix[i]):
				while j < len(stack_matrix[i]) and stack_matrix[i][j] == curr_value:
					j += 1
				curr_value = 1 - curr_value
				curr_player = 1 - curr_player
			is_stack_empty[i] = True
	if curr_player == 0:
		print('Dee')
	else:
		print('Dum')
	T -= 1


def playDee(a, nq):
	b = []
	for i in range(nq):
		if a[i][0] == '0':
			b.append(i)
	if b == []:
		return -1
	n = len(b)
	for i in range(n):
		n1 = len(a[b[i]])
		for j in range(n1 - 1, 0, -1):
			if a[b[i]][j] == '1':
				a[b[i]] = a[b[i]][j:]
				return nq
	a.pop(b[0])
	nq -= 1
	return nq

def playDum(a, nq):
	b = []
	for i in range(nq):
		if a[i][0] == '1':
			b.append(i)
	if b == []:
		return -1
	n = len(b)
	for i in range(n):
		n1 = len(a[b[i]])
		for j in range(n1 - 1, 0, -1):
			if a[b[i]][j] == '0':
				a[b[i]] = a[b[i]][j:]
				return nq
	a.pop(b[0])
	nq -= 1
	return nq
for _ in range(int(input())):
	(n, s) = input().split()
	n = int(n)
	a = []
	for i in range(n):
		a.append(input())
	while True:
		if s == 'Dee':
			n = playDee(a, n)
			s = 'Dum'
			if n == -1:
				print('Dee')
				break
		else:
			n = playDum(a, n)
			s = 'Dee'
			if n == -1:
				print('Dum')
				break


t = int(input())
for i in range(t):
	inp = input().split()
	n = int(inp[0])
	s = inp[1]
	dp = [[0, 0], [0, 0]]
	for j in range(n):
		a = input()
		dp[int(a[0])][int(a[-1])] += 1
	c = 1
	if s == 'Dee':
		c = 0
	while dp[c][0] != 0 or dp[c][1] != 0:
		c1 = (c + 1) % 2
		if dp[c][c1] > 0:
			dp[c][c1] -= 1
			dp[c1][c1] += 1
		else:
			dp[c][c] -= 1
		c = c1
	if c == 0:
		print('Dee')
	else:
		print('Dum')


for test in range(int(input())):
	(n, first) = input().split()
	n = int(n)
	(z, o) = (0, 0)
	for i in range(n):
		s = input()
		if s[0] != s[-1]:
			z += 1
			o += 1
		elif s[0] == '0':
			z += 1
		else:
			o += 1
	if z == o:
		print(first)
	elif z < o:
		print('Dee')
	else:
		print('Dum')


t = int(input())
for hell in range(t):
	(n, start) = list(input().split())
	n = int(n)
	key = []
	for k in range(n):
		stack = input()
		key.append(stack)
	if start == 'Dee':
		turn = 0
	else:
		turn = 1
	flag = 0
	while flag == 0:
		performed = 0
		for z in range(len(key)):
			if key[z] == '':
				pass
			else:
				trying = 0
				if int(key[z][0]) == turn:
					for w in range(1, len(key[z])):
						if int(key[z][w]) == turn:
							trying = trying + 1
						if int(key[z][w]) != turn:
							break
					key[z] = key[z][trying + 1:len(key[z])]
					performed = 1
					if turn == 0:
						turn = 1
					else:
						turn = 0
			if performed == 1:
				break
		if performed == 0:
			winner = turn
			flag = 1
			break
	if winner == 0:
		print('Dee')
	else:
		print('Dum')