#include #include using namespace std; using namespace atcoder; #define rep(i, n) for(int i=0;i<(n);++i) #define rep1(i, n) for(int i=1;i<=(n);i++) #define ll long long using mint = modint998244353; using P = pair; using lb = long double; using T = tuple; #ifdef LOCAL # include # define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define dbg(...) (static_cast(0)) #endif int main() { int n, k, q; cin >> n >> k >> q; deque dq; multiset st; while(q--){ int t; cin >> t; if(t==1){ string a; cin >> a; dq.push_back(a); st.insert(a); } else{ vector s(7); vector d(7); rep(i,6) cin >> s[i] >> d[i]; d[6] = 100; while(dq.size()>n) { string f = dq.front(); dq.pop_front(); st.erase(st.find(f)); } int sum = 60; int last = 0; rep(i,7) { dbg(sum); if(st.count(s[i])) sum -= min(k, d[i]); else sum -= d[i]; if(sum<0) { cout<