n = int(input())
a = [int(an) for an in input().split()]
q = int(input())

for i in range(q):
    stdins = input().split()
    for j in range(n):
        if a[j] == int(stdins[0]):
            a[j] = int(stdins[1])
    ans = sum([int(an) for an in a])
    print(ans)
