N = int(input())
A = list(map(int,input().split()))

Q = int(input())

same = []
for i in range(10**5+1):
    same.append([])

for i in range(N):
    same[A[i]].append(i)

result = sum(A)

for i in range(Q):
    #print(i)
    B, C = map(int,input().split())
    #print(B,C)

    #print(same[B])
    #print(same[C])
    lim = len(same[B])
    result += (C-B)*lim
    print(result)


    for j in range(lim):
        same[C].append(same[B].pop())
        #print(same[B])
        #print(same[C])