'''
Brian Crabtree
7/23/13
palindromes.py
Solution to the "Anya's Palindromes" problem
'''

#Function to determine if a word is a palindrome
def isPalindrome(word):

    #Catch the case where the word is less than 3 letters
    if len(word) < 3:
        return False

    #Check word if long enough
    else:

        #Iterate through to the middle of the word
        for i in range(int(len(word) / 2)):

            #Compare the letter in the current index
            #to its negative index counterpart and
            #return false once a mismatch is found
            if word[i] != word [-1 * (i + 1)]:
                return False

        #No mismatches found, return true
        return True
    
################################################

#Open the input file
file = open("anya.in", "r")

#Read in the number of sentences
sentences = int(file.readline())

#Iterate through each of the inputted sentences
for i in range(sentences):

    #Read in the sentence
    sentence = file.readline()

    #Split the sentence into individual words
    words = sentence.split()

    #Remove the new line character and all spaces
    #from the original sentence
    sentence = sentence.strip()
    sentence = sentence.replace(" ", "")

    #Boolean to track whether or not the sentence
    #meets requirements
    winner = False

    #Check if the whole sentence is a palindrome
    if isPalindrome(sentence):
        winner = True

    #If the whole sentence isn't a palindrome, look
    #at individual words
    else:

        #Count the number of palindromes in the sentence
        palCount = 0

        #Iterate through each word in the sentence and
        #check if it is a palindrome or not
        for j in range(len(words)):
            if isPalindrome(words[j]):
                palCount += 1

        #Update if the sentence meets palindrome requirements
        if palCount >= 2:
            winner = True

    #Print the result
    if winner:
        print("Ay")
    else:
        print("Nap")

# Close the file.
file.close()
