#include using namespace std; using ll=long long; using ld= long double; using P=pair; using V=vector; #define rep(i,n) for(ll i=0;i f(2000,V(nw)),f1(2000,V(nw)),f2(2000,V(nw)); rep(t,1000){ int n; cin >> n; if(n==-1) break; rep(i,n){ int h,p,x; cin >> h >> p >> x; f[nh-1+t][x]=f1[nh-1+t][x]=h; f2[nh-1+t][x]=p; } cout << s[t%20] << endl; int c=1; rep(i,nh) if(c==1&&f[i+t][now]>0){ c=0; f[i+t][now]-=l/100; if(f[i+t][now]<=0){ l+=f2[i+t][now]; score+=f1[i+t][now]; f[i+t][now]=f1[i+t][now]=f2[i+t][now]=0; } } /* for(int i=nh-1;0<=i;i--){ rep(j,nw) cerr << f[i+t][j] << " "; cerr << endl; } */ } //cerr << "score : " << score << endl; }