def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    for _ in range(Q):
        b, c = map(int, input().split())
        while b in A:
            A.remove(b)
            A.append(c)
        print(sum(A))
resolve()