n = int(input())

a = list(map(int,input().split()))

q = int(input())

bc = [list(map(int,input().split())) for _ in range(q)]


def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

for i in range(q):
    if a.count(bc[i][0]) == 0 :
        print(sum(a))
    else :
        idx = func1(a,bc[i][0])
        for j in idx :
            a[j]=bc[i][1]
        print(sum(a))
