import numpy as np


def main():
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    MAX = 10 ** 5 + 10
    k = [0] * MAX
    # v = [0] * MAX

    for a in A:
        k[a] += 1

    num = np.arange(MAX)

    arr_k = np.array(k)

    for i in range(Q):
        b, c = map(int, input().split())
        if arr_k[b] > 0:
            arr_k[c] += arr_k[b]
            arr_k[b] = 0
        ans = np.sum(arr_k * num)
        print(ans)

    # print(k[:10])

    # for i in range(Q):
    #     ans = 0
    #     b, c = map(int, input().split())
    #     if k[b] > 0:
    #         k[c] += k[b]
    #         k[b] = 0
    #     for i in range(MAX):
    #         ans += i * k[i]
    #     print(ans)


if __name__ == "__main__":
    main()
