import sys
import numpy as np

if __name__ == '__main__':
    n = int(sys.stdin.readline().rstrip())
    A = list(map(lambda x: int(x), sys.stdin.readline().split()))
    q = int(sys.stdin.readline().rstrip())
    dic = {}
    for a in A:
        dic[a] = dic.get(a, 0) + 1

    for i in range(q):
        b, c = list(map(lambda x: int(x), sys.stdin.readline().split()))

        dic[c] = dic.get(c, 0) + dic.get(b, 0)
        dic[b] = 0

        summ = 0
        keys = list(dic.keys())
        values = list(dic.values())
        print(np.array(keys).dot(np.array(values)))