# 入力
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]


def replacement(orig, b, c):
    if orig == b:
        return c
    else:
        return orig


for bc in BC:
    b, c = bc
    A = [replacement(a, b, c) for a in A]
    print(sum(A))
