#include #include #include using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 int main(){ int n,k,q; cin>>n>>k>>q; vector s; rep(_,q){ int t; cin>>t; if(s.size()>n){ s.erase(s.begin()); } if(t==1){ string ss; cin>>ss; s.push_back(ss); } else{ vector ans; int remain = 60; rep(i,6){ string T; int d; cin>>T>>d; rep(j,s.size()){ if(s[j]==T){ d = min(d,k); } } if(remain>=d){ remain -= d; ans.push_back(T); } else remain = 0; } cout<