#include <bits/stdc++.h>
#define int long long
#define il inline
using namespace std;
int stk[100005];
int Q[100005];
int top, head, tail;
priority_queue<int>PQ;
signed main() {
int n;
while (scanf("%lld", &n) != EOF) {
top = 0;
while (!PQ.empty())PQ.pop();
head = 1, tail = 0;
bool f1 = 1, f2 = 1, f3 = 1;
int op, k;
while (n --) {
scanf("%lld %lld", &op, &k);
if (op & 1) {
if (f1)stk[++ top] = k;
if (f2)Q[++ tail] = k;
if (f3)PQ.push(k);
} else {
if (top){
f1 = (f1 && stk[top --] == k);
f2 = (f2 && Q[head ++] == k);
f3 = (f3 && PQ.top() == k);
PQ.pop();
}
}
}
int cnt = f1 + f2 + f3;
if (!cnt)puts("impossible");
else if (cnt >= 2)puts("not sure");
else if (f1) puts("stack");
else if (f2) puts("queue");
else if (f3) puts("priority queue");
}
return 0;
}