import numpy as np
def solve():
    N = int(input())
    A = np.array(list(map(int, input().split())),dtype=np.int64)
    Q = int(input())
    BC = np.array([list(map(int, input().split())) for _ in range(Q)])

    nums = np.zeros(max(A.max(), BC.max())+1)
    sm = A.sum(dtype=np.int64)
    for i in A:
        nums[i]+=1

    for b,c in BC:
        sm += nums[b]*(c-b)
        nums[c] +=nums[b]
        nums[b] = 0
        print(sm)








if __name__ == "__main__":
    solve()