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


def change(list,before,after):
    for j in range(n):
        if list[j] == before:
            list[j] = after
    print(sum(list))
    return list


for i in range(q):
    b,c = list(map(int,input().split()))
    a = change(a,b,c)