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