def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    q = int(input())

    for _ in range(q):
        b, c = map(int, input().split())
        A = [c if a == b else a for a in A]
        print(sum(A))

resolve()