n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

for i in bc:
    sum = 0
    for j in range(len(a)):
        if i[0] == a[j]:
            a[j]= i[1]
        sum += a[j]
    print(sum)
