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