n = int(input())
li1 = list(map(int, input().split()))
q = int(input())
li2 = list(input().split() for x in range(q))
for i in li2:
    if int(i[0]) in li1:
        li3 = [index for index, value in enumerate(li1) if value == int(i[0])]
        for j in li3:
            li1[j] = int(i[1])
        print(sum(li1))
    else:
        print(sum(li1))
