#include using namespace std; using ll=long long; using pll=pair; using tll=tuple; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define all(v) v.begin(),v.end() template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a> n >> k >> q; vector a; while(q--){ ll x; cin >> x; if(x==1){ string s; cin >> s; a.push_back(s); } if(x==2){ vector t(6); vector d(6); rep(i,6) cin >> t[i] >> d[i]; ll now=0,m=a.size(); vector v; rep(i,6){ bool ok=false; rep(j,n){ if(m<=j) break; if(a[m-1-j]==t[i]) ok=true; } if(ok) chmin(d[i],k); if(60