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