// 嘘解法 (WA) // 60 分を 59 分で判定している #include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int N, K, Q; cin >> N >> K >> Q; vector A; for (int i = 0; i < Q; i++) { int q; cin >> q; if (q == 1) { string s; cin >> s; A.push_back(s); } else { int M = A.size(); int j = max(0, (M - 1) - N + 1); vector solved; int ans = 0; int sum_d = 0; for (int k = 0; k < 6; k++) { string t; int d; cin >> t >> d; for (int l = j; l < M; l++) { if (A[l] == t) { d = min(d, K); break; } } sum_d += d; if (sum_d <= 59) { ans++; solved.push_back(t); } } for (auto t : solved) { A.push_back(t); } cout << ans << '\n'; } } return 0; }