#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) template bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void solve(); int main() { cin.tie(nullptr)->sync_with_stdio(false); cout << fixed << setprecision(20); int t = 1; //cin >> t; while (t--) { solve(); } } int N,Q; mapmp; void solve() { cin>>N>>Q; vector>>ans(Q); set>st; rep(t,Q){ int qt;cin>>qt; if(qt==1){ string s;int r;cin>>s>>r; mp[s]=r; st.insert({0,r,s}); } if(qt==2){ int x;cin>>x; N-=x; } if(qt==3){ string s;int x;cin>>s>>x; N+=x; st.erase({0,mp[s],s}); st.insert({1,mp[s],s}); } while(N<(int)st.size()){ auto[_,r,s]=*st.begin(); st.erase(st.begin()); ans[t].emplace_back(r,s); } } rep(t,Q){ sort(ans[t].begin(),ans[t].end()); for(auto[r,s]:ans[t])cout<