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

ans = 0

for i in range(q):
    before = b_c[i][0]
    after = b_c[i][1]
    for j in range(n):
        if a[j] == before:
            a[j] = after
    ans = sum(a)
    print(ans)
