// Arup Guha
// 2/10/2024
// Solution to Kattis Problem: Guess the Data Structure
// https://open.kattis.com/problems/guessthedatastructure

import java.util.*;

public class guess {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		
		while (stdin.hasNext()) {
		
			// Read in data.
			int n = stdin.nextInt();
			int[] op = new int[n];
			int[] val = new int[n];
			for (int i=0; i<n; i++) {
				op[i] = stdin.nextInt();
				val[i] = stdin.nextInt();
			}
			
			// Try each.
			boolean isStack = checkStack(op, val);
			boolean isQueue = checkQueue(op, val);
			boolean isPQ = checkPQ(op, val);
			
			// This is annoying, but no other way.
			if (!isStack && !isQueue && !isPQ)
				System.out.println("impossible");
			else if (isStack && !isQueue && !isPQ)
				System.out.println("stack");
			else if (!isStack && isQueue && !isPQ)
				System.out.println("queue");
			else if (!isStack && !isQueue && isPQ)
				System.out.println("priority queue");	
			else
				System.out.println("not sure");
		}
	}
	
	// Let's see if it's a stack...
	public static boolean checkStack(int[] op,int[] val) {
		
		// Create our stack.
		Stack<Integer> mys = new Stack<Integer>();
		
		// Simulate.
		for (int i=0; i<op.length; i++) {
			
			// This is bad.
			if (op[i] == 2 && mys.size() == 0) return false;
			
			// Add to stack.
			if (op[i] == 1) mys.push(val[i]);
			
			// Time to pop.
			else {
				int top = mys.pop();
				
				// Not a match!
				if (top != val[i])
					return false;
			}
		}
		
		// If we get here, it could be a stack.
		return true;
	}
	
	// Let's see if it's a queue.
	public static boolean checkQueue(int[] op,int[] val) {
		
		// Make my queue.
		Queue<Integer> mys = new ArrayDeque<Integer>();
		
		// Simulate.
		for (int i=0; i<op.length; i++) {
			
			// This is bad.
			if (op[i] == 2 && mys.size() == 0) return false;
			
			// Add to queue.
			if (op[i] == 1) mys.offer(val[i]);
			
			// Remove from queue.
			else {
				
				int top = mys.poll();
				
				// Not a match.
				if (top != val[i])
					return false;
			}
		}
		
		// Good if we get here.
		return true;
	}
	
	// Check if it's a PQ.
	public static boolean checkPQ(int[] op,int[] val) {
		
		// Make the PQ - but max at top.
		PriorityQueue<Integer> mys = new PriorityQueue<Integer>(Collections.reverseOrder());
		
		// Simulate.
		for (int i=0; i<op.length; i++) {
			
			// This is bad.
			if (op[i] == 2 && mys.size() == 0) return false;
			
			// Add it.
			if (op[i] == 1) mys.offer(val[i]);
			
			// Remove.
			else {
				
				int top = mys.poll();
				
				// Not a match.
				if (top != val[i])
					return false;
			}
		}
		
		// Good if we get here.
		return true;
	}
}