import numpy as np
#import random
from numba import jit

@jit
def main():
    #N = 100000
    #A = random.choices(range(1, N), k=N)
    N = int(input())
    A = np.array(list(map(int, input().split())), dtype=np.uintc)
    MAX = 10**5
    X = np.zeros(MAX, dtype=np.uintc)
    Y = np.array(range(MAX), dtype=np.uintc)
    
    for i in range(len(A)): X[A[i]] += 1
    
    Q = int(input())
    #Q = MAX
    OUT = np.zeros(Q, dtype=np.uintc)
    for i in range(Q):
        [b, c] = list(map(int, input().split()))
        #b, c = random.choice(range(1, N)), random.choice(range(1, N))
        X[c] += X[b]
        X[b] = 0
        OUT[i] = int(np.sum(X*Y))
    return OUT

OUT = main()
print("\n".join(map(str, list(OUT))))

