N = int(input())
A = list(map(int, input().split()))
B = [0]*(N+1)
for n in range(N):
    B[n+1] = B[n] + A[n]
C = B.pop()

Z = {}
for n in range(N):
    Z[A[n]] = 0
for n in range(N):
    Z[A[n]] += 1

D = []
Q = int(input())
for q in range(Q):
    x, y = map(int, input().split())
    if x in Z:
        C = C - x*Z[x]
        C = C + y*Z[x]
        D.append(C)
        if x == y:
            continue
        if y in Z:
            Z[y] += 1
        else:
            Z[y] = Z[x]
        Z.pop(x)
    else:
        D.append(C)
for d in D:
    print(d)