n = int(input())
al = list(map(int, input().split()))
q = int(input())
bl = []
cl = []
for i in range(q):
    b,c = map(int, input().split())
    bl.append(b)
    cl.append(c)

shoki = sum(al)
for i in range(q):
    b = bl[i]
    c = cl[i]
    kaisu = al.count(b)
    al = [c if i == b else i for i in al]
    tasu = kaisu * (c - b)
    shoki += tasu
    print(shoki)
