Manasa loves the nim game, in which there are $n$ buckets, each having $A_i$ balls. Two players play alternately. Each turn consists of removing some non-zero number of balls from one of the bucket. A player with lack of moves looses. But, Manasa having played it so many times, she gets bored one day. So she wants to change the rules of the game. She loves prime numbers, so she makes a new rule: any player can only remove a prime number of balls from a bucket. But there are infinite number prime numbers. So to keep the game simple, a player can only remove $\boldsymbol{x}$ balls from a bucket if $\boldsymbol{x}$ belongs to the set $S=\{2,3,5,7,11,13\}.$

The whole game can now be described as follows:   

There are $n$ buckets, and the $k^{\text{th}}$ bucket contains $A_{k}$ balls. A player can choose a bucket and remove $\boldsymbol{x}$ balls from that bucket where $\boldsymbol{x}$ belongs to $\mbox{S}$. A player loses if there are no more available moves.

Manasa plays the first move against Sandy. Who will win if both of them play optimally?

Input Format

The first line contains an integer $\boldsymbol{\boldsymbol{t}}$, the number of test cases. 

Each test case consists of two lines. The first line contains a single integer $n$. The second line contain $n$ space-separated integers $A_{1},A_{2},\ldots,A_{n}$.  

Constraints

$1\leq t\leq10$  
$1\leq n\leq10^4$  
$1\leq A_k\leq10^{18}$  

Output Format

Print a single line containing the name of the winner: Manasa or Sandy.

Sample Input 0
2
2
10 10
3
2 2 3

Sample Output 0
Sandy
Manasa

Explanation 0

For the first testcase: Since both the buckets have same number of balls, Manasa can choose any one of them for her first move. If Manasa selects to remove $2,3,5$ or $7$ balls to remove from first bucket. Now, Sandy  can always counter her move by removing $7,7,5,3$ balls from first bucket if it's left with $8,7,5,3$ balls respectively. Now, there are no valid moves left for first bucket. The same thing repeats for second bucket and Sandy wins.

For the second testcase: Manasa removes $3$ balls from the third bucket. Now, if Sandy choose the remove $2$ balls from second bucket Manasa will empty the first bucket and if Sandy choose the remove $2$ balls from first bucket, Manasa will empty second one. Hence, Manasa wins.

Difficulty: MEDIUM_HARD
Tags: Game theory

Starter code:

Solutions:
def firstwins(sizes):
	nim = 0
	for size in sizes:
		nim ^= size % 9 // 2
	return nim != 0
ncases = int(input())
for _ in range(ncases):
	nbuckets = int(input())
	sizes = [int(fld) for fld in input().split()]
	print('Manasa' if firstwins(sizes) else 'Sandy')


n = int(input())

def fun(l):
	f_score = 0
	for i in l:
		f_score ^= i % 9 // 2
	return f_score != 0
while n != 0:
	a = int(input())
	s = input()
	l = [int(x) for x in s.split(' ')]
	print('Manasa' if fun(l) else 'Sandy')
	n = n - 1


def calc(a):
	return a % 9 // 2
T = int(input())
for t in range(T):
	N = int(input())
	a = map(int, input().split())
	res = 0
	a = map(calc, a)
	for value in a:
		res ^= value
	print('Manasa' if res else 'Sandy')


grundySet = {}

def firstMissing(s):
	ret = 0
	while 1:
		if ret not in s:
			return ret
		else:
			ret += 1
	return ret
primes = [2, 3, 5, 7, 11, 13]

def grundy(v):
	if v <= 2:
		return 0
	if v in grundySet:
		return grundySet[v]
	tmp = set([])
	for p in primes:
		if p >= v:
			break
		else:
			tmp.add(grundy(v - p))
	ret = firstMissing(tmp)
	grundySet[v] = ret
	return ret

def simpleGrundy(v):
	return [0, 0, 1, 1, 2, 2, 3, 3, 4][v % 9]
T = int(input())
for _ in range(T):
	N = int(input())
	A = map(int, input().split())
	sg = map(simpleGrundy, A)
	ret = 0
	for g in sg:
		ret ^= g
	print(['Sandy', 'Manasa'][ret != 0])


import functools
s = [2, 3, 5, 7, 11, 13]

def nim_sum(l):
	return functools.reduce(lambda a, b: a ^ b, l, 0)

def memo(f):
	m = {}

	def g(x):
		if x not in m:
			m[x] = f(x)
		return m[x]
	return g

@memo
def grundy(i):
	if i == 0 or i == 1:
		return 0
	else:
		return min(set(range(10)) - set([grundy(i - c) for c in s if i >= c]))

def win(l):
	return nim_sum([grundy(c % 9) for c in l]) != 0
for i in range(int(input())):
	input()
	print('Manasa' if win(map(int, input().split())) else 'Sandy')


def firstMissing(s):
	ret = 0
	while 1:
		if ret not in s:
			break
		else:
			ret += 1
	return ret
primes = [2, 3, 5, 7, 11, 13]

def grundy(v):
	if v <= 2:
		return 0
	tmp = set([])
	for p in primes:
		if p >= v:
			break
		else:
			tmp.add(grundy(v - p))
	ret = firstMissing(tmp)
	grundySet[v] = ret
	return ret

def simpleGrundy(v):
	return [0, 0, 1, 1, 2, 2, 3, 3, 4][v % 9]
T = int(input())
for _ in range(T):
	N = int(input())
	A = map(int, input().split())
	sg = map(simpleGrundy, A)
	ret = 0
	for g in sg:
		ret ^= g
	print(['Sandy', 'Manasa'][ret != 0])


rep = [0, 0, 1, 1, 2, 2, 3, 3, 4]
for x in range(int(input())):
	n = int(input())
	xorSum = 0
	ar = list(map(int, input().split()))
	for y in range(n):
		xorSum ^= rep[ar[y] % len(rep)]
	if xorSum == 0:
		print('Sandy')
	else:
		print('Manasa')


tests = int(input())
primes = [2, 3, 5, 7, 11, 13]
for _ in range(tests):
	count = int(input())
	piles = [int(p) for p in input().strip().split(' ')]
	result = 0
	for p in piles:
		result ^= p % 9 // 2
	print('Sandy' if result == 0 else 'Manasa')


def firstMissing(s):
	ret = 0
	while 1:
		if ret not in s:
			break
		else:
			ret += 1
	return ret
primes = [2, 3, 5, 7, 11, 13]

def grundy(v):
	if v <= 2:
		return 0
	tmp = set([])
	for p in primes:
		if p >= v:
			break
		else:
			tmp.add(grundy(v - p))
	ret = firstMissing(tmp)
	grundySet[v] = ret
	return ret

def simpleGrundy(v):
	return [0, 0, 1, 1, 2, 2, 3, 3, 4][v % 9]
T = int(input())
for _ in range(T):
	N = int(input())
	A = map(int, input().split())
	sg = map(simpleGrundy, A)
	ret = 0
	for g in sg:
		ret ^= g
	print(['Sandy', 'Manasa'][ret != 0])


def firstMissing(s):
	ret = 0
	while 1:
		if ret not in s:
			break
		else:
			ret += 1
	return ret
primes = [2, 3, 5, 7, 11, 13]

def grundy(v):
	if v <= 2:
		return 0
	tmp = set([])
	for p in primes:
		if p >= v:
			break
		else:
			tmp.add(grundy(v - p))
	ret = firstMissing(tmp)
	grundySet[v] = ret
	return ret

def simpleGrundy(v):
	return [0, 0, 1, 1, 2, 2, 3, 3, 4][v % 9]
T = int(input())
for _ in range(T):
	N = int(input())
	A = map(int, input().split())
	sg = map(simpleGrundy, A)
	ret = 0
	for g in sg:
		ret ^= g
	print(['Sandy', 'Manasa'][ret != 0])


S = [2, 3, 5, 7, 11, 13]
from functools import reduce
grundy = [0, 0, 1, 1, 2, 2, 3, 3, 4]
for _ in range(int(input())):
	_ = input()
	A = [0] + [int(x) for x in input().split(' ')]
	g = reduce(lambda x, y: x ^ grundy[y % 9], A)
	print('Manasa' if g else 'Sandy')


def firstMissing(s):
	ret = 0
	while 1:
		if ret not in s:
			break
		else:
			ret += 1
	return ret
primes = [2, 3, 5, 7, 11, 13]

def grundy(v):
	if v <= 2:
		return 0
	tmp = set([])
	for p in primes:
		if p >= v:
			break
		else:
			tmp.add(grundy(v - p))
	ret = firstMissing(tmp)
	grundySet[v] = ret
	return ret

def simpleGrundy(v):
	return [0, 0, 1, 1, 2, 2, 3, 3, 4][v % 9]
T = int(input())
for _ in range(T):
	N = int(input())
	A = map(int, input().split())
	sg = map(simpleGrundy, A)
	ret = 0
	for g in sg:
		ret ^= g
	print(['Sandy', 'Manasa'][ret != 0])


values = [0, 0, 1, 1, 2, 2, 3, 3, 4]
t = int(input())
for test_case in range(t):
	n = int(input())
	data = [values[int(x) % 9] for x in input().split()]
	res = 0
	for elem in data:
		res ^= elem
	if res == 0:
		print('Sandy')
	else:
		print('Manasa')


def firstMissing(s):
	ret = 0
	while 1:
		if ret not in s:
			break
		else:
			ret += 1
	return ret
primes = [2, 3, 5, 7, 11, 13]

def grundy(v):
	if v <= 2:
		return 0
	tmp = set([])
	for p in primes:
		if p >= v:
			break
		else:
			tmp.add(grundy(v - p))
	ret = firstMissing(tmp)
	grundySet[v] = ret
	return ret

def simpleGrundy(v):
	return [0, 0, 1, 1, 2, 2, 3, 3, 4][v % 9]
T = int(input())
for _ in range(T):
	N = int(input())
	A = map(int, input().split())
	sg = map(simpleGrundy, A)
	ret = 0
	for g in sg:
		ret ^= g
	print(['Sandy', 'Manasa'][ret != 0])


from functools import reduce
g = [0, 0, 1, 1, 2, 2, 3, 3, 4]
t = int(input())
for _ in range(t):
	n = int(input())
	l = [g[int(i) % 9] for i in input().split()]
	temp = reduce(lambda x, y: x ^ y, l)
	if temp == 0:
		print('Sandy')
	else:
		print('Manasa')


import operator
import functools
t = int(input())
nimber = [0, 0, 1, 1, 2, 2, 3, 3, 4]
for t_ in range(t):
	n = int(input())
	buckets = [int(x) for x in input().split()]
	nimbers = [nimber[x % len(nimber)] for x in buckets]
	res = functools.reduce(operator.xor, nimbers, 0)
	print('Manasa' if res != 0 else 'Sandy')


s = [2, 3, 5, 7, 11, 13]
g = [0, 0]
for k in range(2, 99):
	g.append(min(set(range(10)) - set([g[k - x] for x in s if k - x >= 0])))
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	w = 0
	for x in a:
		w ^= g[x % 9]
	print('Sandy' if w == 0 else 'Manasa')


def firstMissing(s):
	ret = 0
	while 1:
		if ret not in s:
			break
		else:
			ret += 1
	return ret
primes = [2, 3, 5, 7, 11, 13]

def grundy(v):
	if v <= 2:
		return 0
	tmp = set([])
	for p in primes:
		if p >= v:
			break
		else:
			tmp.add(grundy(v - p))
	ret = firstMissing(tmp)
	grundySet[v] = ret
	return ret

def simpleGrundy(v):
	return [0, 0, 1, 1, 2, 2, 3, 3, 4][v % 9]
T = int(input())
for _ in range(T):
	N = int(input())
	A = map(int, input().split())
	sg = map(simpleGrundy, A)
	ret = 0
	for g in sg:
		ret ^= g
	print(['Sandy', 'Manasa'][ret != 0])


s = [0, 0, 1, 1, 2, 2, 3, 3, 4]
t = int(input())
for ti in range(t):
	n = int(input())
	a = [int(ai) for ai in input().strip().split(' ')]
	ans = 0
	for i in range(n):
		ans = ans ^ s[int(a[i] % len(s))]
	if ans > 0:
		print('Manasa')
	else:
		print('Sandy')


class Calculator:

	def __init__(self, Set):
		self.alreadyCalculated = {}
		self.set = Set

	def findGrundy(self, n):
		if n in self.alreadyCalculated:
			return self.alreadyCalculated.get(n)
		if n == 0:
			self.alreadyCalculated[n] = 0
			return 0
		S = []
		for s in self.set:
			if n - s >= 0:
				S.append(self.findGrundy(n - s))
		res = 0
		for i in range(len(S)):
			if res in S:
				res += 1
			else:
				break
		self.alreadyCalculated[n] = res
		return res

def findGrundy(n):
	if n % 9 == 0 or n % 9 == 1:
		return 0
	if n % 9 == 2 or n % 9 == 3:
		return 1
	if n % 9 == 4 or n % 9 == 5:
		return 2
	if n % 9 == 6 or n % 9 == 7:
		return 3
	if n % 9 == 8:
		return 4
Set = [2, 3, 5, 7, 11, 13]
calc = Calculator(Set)
T = int(input())
for i in range(T):
	N = int(input())
	res = 0
	array = [int(x) for x in input().split()]
	for c in array:
		res ^= findGrundy(c)
	if res == 0:
		print('Sandy')
	else:
		print('Manasa')


def firstMissing(s):
	ret = 0
	while 1:
		if ret not in s:
			break
		else:
			ret += 1
	return ret
primes = [2, 3, 5, 7, 11, 13]

def grundy(v):
	if v <= 2:
		return 0
	tmp = set([])
	for p in primes:
		if p >= v:
			break
		else:
			tmp.add(grundy(v - p))
	ret = firstMissing(tmp)
	grundySet[v] = ret
	return ret

def simpleGrundy(v):
	return [0, 0, 1, 1, 2, 2, 3, 3, 4][v % 9]
T = int(input())
for _ in range(T):
	N = int(input())
	A = map(int, input().split())
	sg = map(simpleGrundy, A)
	ret = 0
	for g in sg:
		ret ^= g
	print(['Sandy', 'Manasa'][ret != 0])


g = [0, 0, 1, 1, 2, 2, 3, 3, 4]
size = len(g)
primes = [2, 3, 5, 7, 11, 13]

def mex(s):
	m = 0
	while m in s:
		m += 1
	return m
for t in range(int(input())):
	N = int(input())
	piles = list(map(int, input().split()))
	g_val = 0
	for pil in piles:
		g_val ^= g[pil % size]
	print('Manasa' if g_val else 'Sandy')


import functools
import operator
import sys

def winner(A):
	if functools.reduce(operator.xor, (a % 9 // 2 for a in A), 0):
		return 'Manasa'
	else:
		return 'Sandy'
t = int(input().strip())
for a0 in range(t):
	n = int(input().strip())
	A = list(map(int, input().strip().split(' ')))
	result = winner(A)
	print(result)


import functools
for _ in range(int(input())):
	input()
	print('Manasa' if functools.reduce(lambda s, c: s ^ int(c) % 9 >> 1, input().split(' '), 0) else 'Sandy')


import sys

def winner(A):
	moves = 0
	mex = [0, 0, 1, 1, 2, 2, 3, 3, 4]
	for k in range(len(A)):
		r = A[k] % 9
		moves ^= mex[r]
	return 'Manasa' if moves > 0 else 'Sandy'
t = int(input().strip())
for a0 in range(t):
	n = int(input().strip())
	A = list(map(int, input().strip().split(' ')))
	result = winner(A)
	print(result)


t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	values = [0, 0, 1, 1, 2, 2, 3, 3, 4]
	nimber = 0
	for i in range(n):
		nimber ^= values[ar[i] % len(values)]
	if nimber > 0:
		print('Manasa')
	else:
		print('Sandy')


import functools

def nim(array, n):
	answer = 0
	for x in range(len(array)):
		answer = answer ^ array[x] % 9 // 2
	if answer == 0:
		return 'Sandy'
	return 'Manasa'

def main():
	trials = int(input())
	for trial in range(trials):
		n = int(input())
		array = [int(x) for x in input().split()]
		print(nim(array, n))
main()


def wins(sizes):
	nim = 0
	for size in sizes:
		nim ^= size % 9 // 2
	return nim != 0
ncases = int(input())
for _ in range(ncases):
	nbuckets = int(input())
	sizes = [int(i) for i in input().split()]
	print('Manasa' if wins(sizes) else 'Sandy')


import math
import os
import random
import re
import sys

def winner(A):
	(values, mod, nimber) = ([0, 0, 1, 1, 2, 2, 3, 3, 4], 9, 0)
	for i in range(len(A)):
		nimber = nimber ^ values[A[i] % mod]
	return 'Sandy' if nimber is 0 else 'Manasa'
t = int(input())
for t_itr in range(t):
	n = int(input())
	a = list(map(int, input().rstrip().split()))
	result = winner(a)
	print(result)


from functools import reduce
pat = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def g(x):
	return pat[x % len(pat)]
for _ in range(int(input())):
	n = int(input())
	a = map(int, input().split())
	a = map(lambda x: g(x), a)
	r = reduce(lambda x, y: x ^ y, a)
	if r:
		print('Manasa')
	else:
		print('Sandy')


import functools
import operator
import sys

def rl(proc=None):
	if proc is not None:
		return proc(sys.stdin.readline())
	else:
		return sys.stdin.readline().rstrip()

def srl(proc=None):
	if proc is not None:
		return list(map(proc, rl().split()))
	else:
		return rl().split()

def nimber(s):
	return s % 9 // 2

def main():
	T = rl(int)
	for _ in range(1, T + 1):
		rl()
		A = srl(int)
		print('Manasa' if functools.reduce(operator.xor, map(nimber, A)) else 'Sandy')
main()


import functools
s = [2, 3, 5, 7, 11, 13]

def nim_sum(l):
	return functools.reduce(lambda a, b: a ^ b, l, 0)

def memo(f):
	m = {}

	def g(x):
		if x not in m:
			m[x] = f(x)
		return m[x]
	return g

@memo
def grundy(i):
	if i == 0 or i == 1:
		return 0
	else:
		return min(set(range(10)) - set([grundy(i - c) for c in s if i >= c]))

def win(l):
	return nim_sum([grundy(c % 9) for c in l]) != 0
for i in range(int(input())):
	input()
	print('Manasa' if win(map(int, input().split())) else 'Sandy')


for _ in range(int(input())):
	n = input()
	t = 0
	for i in list(map(int, input().split())):
		t ^= i % 9 // 2
	print('Sandy' if t == 0 else 'Manasa')


n = int(input())

def fun(l):
	f_score = 0
	for i in l:
		f_score ^= i % 9 // 2
	return f_score != 0
while n != 0:
	a = int(input())
	s = input()
	l = [int(x) for x in s.split(' ')]
	print('Manasa' if fun(l) else 'Sandy')
	n = n - 1


n = int(input())

def fun(l):
	f_score = 0
	for i in l:
		f_score ^= i % 9 // 2
	return f_score != 0
while n != 0:
	a = int(input())
	s = input()
	l = [int(x) for x in s.split(' ')]
	print('Manasa' if fun(l) else 'Sandy')
	n = n - 1


small_s = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def s(k):
	return small_s[k % 9]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	for i in a:
		ans ^= s(i)
	if ans == 0:
		print('Sandy')
	else:
		print('Manasa')


def calc(a):
	return a % 9 // 2
T = int(input())
for t in range(T):
	n = int(input())
	a = map(int, input().split())
	cal = 0
	a = map(calc, a)
	for value in a:
		cal ^= value
	if cal:
		print('Manasa')
	else:
		print('Sandy')


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys

def winner(a):
	pim = 0
	for i in a:
		pim ^= i % 9 // 2
	return pim != 0
n = int(input())
for j in range(n):
	nb = int(input())
	a = [int(fld) for fld in input().split()]
	print('Manasa' if winner(a) else 'Sandy')


import math
import os
import random
import re
import sys

def winner(A):
	pim = 0
	for i in A:
		pim ^= i % 9 // 2
	return pim != 0
n = int(input())
for j in range(n):
	nb = int(input())
	a = [int(fld) for fld in input().split()]
	print('Manasa' if winner(a) else 'Sandy')


import math
import os
import random
import re
import sys

def winner(a):
	pim = 0
	for i in a:
		pim ^= i % 9 // 2
	return pim != 0
n = int(input())
for j in range(n):
	nb = int(input())
	a = [int(fld) for fld in input().split()]
	print('Manasa' if winner(a) else 'Sandy')


import math
import os
import random
import re
import sys

def firstwins(sizes):
	nim = 0
	for size in sizes:
		nim ^= size % 9 // 2
	return nim != 0
ncases = int(input())
for _ in range(ncases):
	nbuckets = int(input())
	sizes = [int(fld) for fld in input().split()]
	print('Manasa' if firstwins(sizes) else 'Sandy')


def fun(l):
	f_score = 0
	for i in l:
		f_score ^= i % 9 // 2
	return f_score != 0
n = int(input())
while n != 0:
	a = int(input())
	s = input()
	l = [int(x) for x in s.split(' ')]
	print('Manasa' if fun(l) else 'Sandy')
	n = n - 1


import math
import os
import random
import re
import sys

def winner(A):
	pim = 0
	for i in A:
		pim ^= i % 9 // 2
	return pim != 0
n = int(input())
for j in range(n):
	nb = int(input())
	a = [int(fld) for fld in input().split()]
	print('Manasa' if winner(a) else 'Sandy')


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys

def winner(A):
	pim = 0
	for i in A:
		pim ^= i % 9 // 2
	return pim != 0
n = int(input())
for j in range(n):
	nb = int(input())
	a = [int(fld) for fld in input().split()]
	print('Manasa' if winner(a) else 'Sandy')


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))


import math
import os
import random
import re
import sys
values = [0, 0, 1, 1, 2, 2, 3, 3, 4]

def winner(A):
	nimber = 0
	for ak in A:
		nimber ^= values[ak % len(values)]
	return 'Manasa' if nimber > 0 else 'Sandy'
for _ in range(int(input())):
	(input(), print(winner(list(map(int, input().split())))))