n = int(input())
li = list(map(int, input().split()))
q = int(input())
gokei = []

for i in li:
    b, c = map(int, input().split())
    li = [c if i == b else i for i in li]
    gokei.append(sum(li))
    q -= 1
    if q == 0:
        [print(i) for i in gokei]
        break