n = int(input())
A = list(map(int, input().split()))
base=sum(A)
Q=int(input())
for i in range(Q):
    b, c = map(int, input().split())
    change_num=A.count(b)
    for i in range(change_num):
        A[A.index(b)]=c
    base+=change_num*(c-b)
    print(base)