#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- int N; int L[30]; int T; string S[101010]; int ID[101010],Q[101010]; unordered_map U; ll sc[101010]; vector V; template class BIT { public: V bit[1< bt; int num[30]; int score(int A) { int B=++num[A]; return (A*50+(50*A)*10/(8+2*B)); } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; FOR(i,N) cin>>L[i]; cin>>T; FOR(i,T) { cin>>S[i]>>s; if(s[0]=='?') Q[i]=-1; else Q[i]=s[0]-'A'; if(U.count(S[i])==0) U[S[i]]=U.size()-1; ID[i]=U[S[i]]; } FOR(i,T) { if(Q[i]>=0) { sc[ID[i]]+=score(Q[i]); V.push_back(sc[ID[i]]); } } ZERO(num); ZERO(sc); V.push_back(0); sort(ALL(V)); V.erase(unique(ALL(V)),V.end()); bt.add(0,U.size()); FOR(i,T) { x = lower_bound(ALL(V),sc[ID[i]])-V.begin(); if(Q[i]>=0) { bt.add(x,-1); sc[ID[i]]+=score(Q[i]); x = lower_bound(ALL(V),sc[ID[i]])-V.begin();; bt.add(x,1); } else { cout << bt(1<<19)-bt(x)+1<