#include using namespace std; typedef long long ll; int main() { ll N, K, Q; cin >> N >> K >> Q; setS; queueA; while (Q--) { int t; cin >> t; if (t == 1) { string T; cin >> T; if (S.find(T) == S.end()) { S.insert(T); A.push(T); if (S.size() > N) { T = A.front(); A.pop(); S.erase(T); } } } else { string T; ll time; ll ans = 0, sum = 0; queueB; for (int i = 0; i < 6; i++) { cin >> T >> time; if (S.find(T) == S.end()) { sum += time; } else sum += min(time, K); if (sum <= 60) { B.push(T); ans++; } } cout << ans << endl; while (!B.empty()) { if (S.find(B.front()) == S.end()) { A.push(B.front()); S.insert(B.front()); if (A.size() > N) { S.erase(A.front()); A.pop(); } } B.pop(); } } } }