#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N,K,Q; cin >> N >> K >> Q; vectorS; while(Q--) { int f; cin >> f; if(f == 1) { string s; cin >> s; S.push_back(s); } else { setst; for(int i = max(0,(int)(S.size())-N); i < S.size(); i++) { st.insert(S[i]); } int cnt = 0,sum = 0; for(int i = 0; i < 6; i++) { string t; int d; cin >> t >> d; if(st.count(t)) { d = min(d,K); } sum += d; if(sum <= 60) { cnt++; S.push_back(t); } } cout << cnt << "\n"; } } }