#include int main() { using namespace std; unsigned N, K, Q; cin >> N >> K >> Q; map counter; deque viewed(N); counter[""] = N; const auto add{[&counter, &viewed](const auto &S) { ++counter[S]; viewed.emplace_back(S); if (!--counter[viewed.front()]) counter.erase(viewed.front()); viewed.pop_front(); }}; for (unsigned i{}; i < Q; ++i) { unsigned type; cin >> type; if (type == 1) { string S; cin >> S; add(S); } else { array s{}; array v{}; for (unsigned j{}; j < 6; ++j) { cin >> s[j]; unsigned time; cin >> time; if (counter.contains(s[j])) v[j] = min(time, K); else v[j] = time; } const auto x{ [&]() -> unsigned { for (unsigned i{}, a{}; i < 6; ++i) { if (a + v[i] <= 60) a += v[i]; else return i; } return 6; }()}; cout << x << endl; for (unsigned j{}; j < x; ++j) add(s[j]); } } return 0; }