#include using namespace std; using ll=long long; using ld=long double; ld pie=3.141592653589793; ll mod=998244353; ld inf=10000999999999900; int main(){ ll n,k,q; cin >> n >> k >> q; mapmemo; queueque; vectorans; for (ll i = 0; i < q; i++) { ll t; cin >> t; if (t==1) { string s; cin >> s; memo[s]++; que.push(s); while (que.size()>n) { string t=que.front(); que.pop(); memo[t]--; } }else{ vectort(6); vectord(6); for (ll j = 0; j < 6; j++) { cin >> t[j] >> d[j]; } ll a=0,x=0; bool ok=true; for (ll j = 0; j < 6; j++) { x++; if (memo[t[j]]>=1) { a+=min(k,d[j]); if (a>60) { a-=min(k,d[j]); x--; ok=false; break; } }else{ a+=d[j]; if (a>60) { a-=d[j]; x--; ok=false; break; } } if (!ok) { break; } } for (ll j = 0; j < x; j++) { memo[t[j]]++; que.push(t[j]); } while (que.size()>n) { string s=que.front(); que.pop(); memo[s]--; } ans.push_back(x); } } for (ll i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } }