#include "bits/stdc++.h" using namespace std; //Ω(人)かける最大限の手抜きバージョン int main() { int N; scanf("%d", &N); vector L(N); for(int i = 0; i < N; ++ i) scanf("%d", &L[i]); int T; scanf("%d", &T); const int MaxScore = 15600; struct Contestant { int totalScore; int lastTime; Contestant() : totalScore(0), lastTime(0) {} unsigned calc(int T) const { return (unsigned)(MaxScore - totalScore) * T + lastTime; } }; std::map contestants; std::vector count(N, 0); assert((long long)(MaxScore + 1) * T <= 1LL << 32); vector list; for(int i = 0; i < T; ++ i) { char name[17], P[2]; scanf("%s%s", name, P); if(*P != '?') { int p = *P - 'A'; int stars = L[p]; int rank = ++ count[p]; int score = 50 * stars + 50 * stars * 10 / (8 + 2 * rank); auto &c = contestants[name]; if(c.totalScore != 0) list.erase(find(list.begin(), list.end(), c.calc(T))); c.totalScore += score; c.lastTime = i + 1; assert(c.totalScore <= MaxScore); list.insert(lower_bound(list.begin(), list.end(), c.calc(T)), c.calc(T)); } else { auto &c = contestants[name]; int ans = (int)(lower_bound(list.begin(), list.end(), c.calc(T)) - list.begin()); printf("%d\n", ans + 1); } } return 0; }