#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { int n, k, q; cin >> n >> k >> q; multiset vis; deque dq; auto add = [&](string s) { dq.push_back(s); vis.insert(s); while (dq.size() > n) { vis.erase(vis.find(dq.front())); dq.pop_front(); } }; for (; q--;) { int type; cin >> type; if (type == 1) { string s; cin >> s; add(s); } else { vector t(6); vector d(6); for (int i = 0; i < 6; i++) { cin >> t[i] >> d[i]; } int ans = 0, cur = 0; while (ans < 6) { if (vis.find(t[ans]) != vis.end()) { d[ans] = min(d[ans], k); } if (cur + d[ans] <= 60) { cur += d[ans]; add(t[ans]); ans++; } else { break; } } cout << ans << "\n"; } } }