import sys
#sys.exit()
#sorted( ,reverse=True)
N = int(input())
#S,T = map(int, input().split())
A = list(map(int, input().split()))
#A = [int(input()) for _ in range(N)]
Q = int(input())
#cnt = 0
#cnt += 1

ans = sum(A)

for _ in range(Q):
    B,C = map(int, input().split())
    for i in range(N):
        if A[i] == B:
            A[i] = C
            ans += C-B
    #print(A)
    #cnt = A.count(B)
    #print(cnt)
    #ans += cnt*(C-B)
    print(ans)
    

