// Arup Guha
// 3/16/2017
// Solution to 2017 UCF HS Contest Problem: Knights, Pirates, Ninjas

import java.util.*;

public class knights {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();
		
		// Process each case - store as a string and make use of contains...
		for (int loop=0; loop<numCases; loop++) {
			String nStr = stdin.next();
			System.out.print(nStr);
			
			// Check for a 1 by being lazy.
			if (nStr.contains("1"))
				System.out.print(" knights");
				
			// Really bad, but what I'd do in a contest.
			if (nStr.contains("5") || nStr.contains("6") || nStr.contains("7") || nStr.contains("8") || nStr.contains("9"))
				System.out.print(" pirates");
			
			// Check for a 0 the same way.
			if (nStr.contains("0"))
				System.out.print(" ninjas");
			
			// Advance to the next line.
			System.out.println();
		}
	}
}