#include using namespace std; int main() { int n, k, q;cin >> n >> k >> q; vector a; while (q--) { int type;cin >> type; if (type == 1) { string s;cin >> s; a.emplace_back(s); } else { vector t(6); vector d(6); for (int i = 0; i < 6; i++) { cin >> t[i] >> d[i]; int m = a.size(); int j = max(0, m - n); for (int l = j; l < m; l++) { if (t[i] == a[l])d[i] = min(d[i], k); } } int total_time = 0; for(int i = 0; i < 7; i++){ if((i == 6) || total_time + d[i] > 60){ for(int j = 0; j < i; j++)a.emplace_back(t[j]); cout << i << endl; break; } total_time += d[i]; } } } }