N = int(input())
A = list(map(int, input().split()))
C = sum(A)
D = [0]*(10**5)
for n in range(N):
    D[A[n]] += 1
Q = int(input())
Z = []
for q in range(Q):
    x, y = map(int, input().split())
    if D[x]:
        C = C - x*D[x]
        C = C + y*D[x]
        Z.append(C)
        if D[y]:
            D[y] += 1*D[x]
        else:
            D[y] = D[x]
        D[x] = 0
    else:
        Z.append(C)
for z in Z:
    print(z)