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

