def calcscore(lv, tm): from math import floor return int(floor(50 * lv + 50.0 * lv / (0.8 + 0.2 * tm))) n = int(input()) level = {} acninzu = {} for i, lv in enumerate(map(int, input().split())): problem = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'[i:i+1] level[problem] = lv acninzu[problem] = 0 kakujinscore = {} t = int(input()) def sortfunc(name): scores, time = kakujinscore[name] totalscore = sum(scores.values()) return totalscore * t + (t - time - 1) def query(qname): ranking = sorted(kakujinscore, key=sortfunc, reverse=True) for i, name in enumerate(ranking): if name == qname: return i + 1 return 0 for i in range(t): name, problem = input().split() if problem == '?': print(query(name)) continue acninzu[problem] += 1 thisscore = calcscore(level[problem], acninzu[problem]) if name in kakujinscore: scores, _ = kakujinscore[name] scores[problem] = thisscore kakujinscore[name] = scores, i else: scores = {} scores[problem] = thisscore kakujinscore[name] = scores, i