#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define sz(x) (int) x.size()
#define pb push_back
#define all(x) x.begin(), x.end()

using namespace std;
using pii = pair<ll, ll>;
using tii = tuple<ll, ll, ll>;
string printBin(ll m) { string a = ""; for(int i=63; i>=0; i--) { if(m & (1<<i)) {a += '1';} else {a += '0';} } return a; }

int main() {
    int n;
    while(cin >> n) {
        queue<int> q;
        stack<int> st;
        priority_queue<int> pq;

        bool qq = true, stt = true, pqq = true;

        for(int i=0; i<n; i++) {
            int op, x; cin >> op >> x;

            if(op == 1) {
                q.push(x);
                st.push(x);
                pq.push(x);
            } else {
                auto qi = q.front();
                q.pop();
                qq &= (qi == x);

                auto si = st.top();
                st.pop();
                stt &= (x == si);

                auto pi = pq.top();
                pq.pop();
                pqq &= (x == pi);
            }
        }

        int tot = qq + stt + pqq;
        if(tot > 1) cout << "not sure\n";
        else if(tot == 0) cout << "impossible\n";
        else if(qq) cout << "queue\n";
        else if(stt) cout << "stack\n";
        else cout << "priority queue\n";
    }
}
