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

a_sum = sum(a)
for i in range(q):
    stdins = input().split()
    b = int(stdins[0])
    c = int(stdins[1])
    for j in range(n):
        if a[j] == b:
            a[j] = c
            a_sum = a_sum - b + c
    print(a_sum)
