import numpy as np
def list_replace(lst, old, new):
    i = -1
    try:
        while 1:
            i = lst.index(old, i + 1)
            lst[i] = new
    except ValueError:
        pass
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b,c = [],[]
for i in range(q):
    bt,ct = input().split()
    b.append(int(bt))
    c.append(int(ct))
    list_replace(a,b,c)

for i in range(q):
    list_replace(a,b[i],c[i])
    print(sum(a))