#include using namespace std; #define ll long long #define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++) #define rrep(i, n, a) for (int i = (int)(n); i >= (int)(a); i--) void solve(){ int n,k,q; cin >> n >> k >> q; string t[6]; int d[6]; vector seen; while(q--){ int c; cin >> c; if(c == 1){ string s; cin >> s; seen.push_back(s); } else { rep(i,0,6) cin >> t[i] >> d[i]; int ans = 0; int time = 0; rep(i,0,6){ rep(j,0,min((unsigned long)n,seen.size())){ if(seen[seen.size()-j-1] == t[i]) d[i] = min(d[i],k); } } rep(i,0,6){ if(time+d[i] <= 60){ time += d[i]; ans++; } else break; } cout << ans << '\n'; } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); solve(); return 0; }