#define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(v) v.begin(), v.end() typedef long long ll; #include using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int n,k,q; cin>>n>>k>>q; deque deq; map mp; while(q--){ int c; cin>>c; if(c==1){ string s; cin>>s; deq.push_back(s); mp[s]++; if((int)deq.size()>n){ auto a=deq.front(); deq.pop_front(); mp[a]--; } } else{ vector T(6); vector D(6); rep(i,6) cin>>T[i]>>D[i]; int cnt=0; int res=60; rep(i,6){ if(mp[T[i]]>0){ if(res-min(k,D[i])>=0){ cnt++; res-=min(k,D[i]); } else break; } else{ if(res-D[i]>=0){ cnt++; res-=D[i]; } else break; } } cout<n){ auto a=deq.front(); deq.pop_front(); mp[a]--; } } } return 0; }