from collections import Counter

import sys

readline = sys.stdin.buffer.readline

def solver(int N, list A, int Q, list BC):
    d = Counter(A)

    sub_s = sum(A)

    for b, c in BC:
        sub_s += d[b] * (c - b)
        d[c] += d[b]
        d[b] = 0

        print(sub_s)


def run():
    N = int(readline())
    A = list(map(int, readline().split()))

    Q = int(readline())
    BC = [list(map(int, readline().split())) for _ in range(Q)]

    solver(N, A, Q, BC)

run()
