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

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