N = int(input())
A = list(map(int,input().split()))
Q = int(input())

for i in range(Q):
    B, C = map(int,input().split())
    for j in A:
        if A[A.index(j)] == B:
            A[A.index(j)] = C
    print(sum(A))