n = int(input())
a = list(map(int, input().split()))
q = int(input())

for i in range(q):
    o = list(map(int, input().split()))
    for j in range(n):
        if a[j] == o[0]:
            a[j] = o[1]
    print(sum(a))