n = int(input())
a = list(map(int, input().split()))
q = int(input())
ans = 0
for i in range(q):
    b, c = map(int, input().split())
    if b in a:
        l = [i for i, x in enumerate(a) if x == b]
        for j in l:
            a[j] = c
    print(sum(a))
