n = gets.to_i l = gets.split.map(&:to_i) s = Hash.new([0,1]) n.times do |i| s[(i+65).chr] = [l[i],1] end score = Hash.new{|k, v| k[v]=[0]*n} total = Hash.new([0, 0]) t = gets.to_i t.times do |m| name, pro = gets.split score[name][pro.ord-65] = (50 * s[pro][0] + 50 * s[pro][0] / (0.8 + 0.2 * s[pro][1])).floor total[name] = [total[name][0]-score[name][pro.ord-65], m] s[pro][1] += 1 end total.sort_by{|k1, v1| v1}.each_with_index do |(k2, v2), i| ans = (i+1).to_s + " " + k2 + " " tt = "" s.each_key do |k| tt = tt + score[k2][k.ord-65].to_s + " " end tt = tt + (-total[k2][0]).to_s puts ans + tt end