#!/usr/bin/env python3
def main():
    import sys

    input = sys.stdin.readline

    _ = int(input())
    A = [int(x) for x in input().split()]
    Q = int(input())

    lst = [0 for _ in [0] * (10 ** 5 + 1)]
    sum_lst = 0
    for n in range(10 ** 5 + 1):
        lst[n] = A.count(n)
        sum_lst += n * lst[n]

    for _ in range(Q):
        B, C = map(int, input().split())

        sum_lst += (C - B) * lst[B]
        print(sum_lst)
        lst[C] += lst[B]
        lst[B] = 0


if __name__ == '__main__':
    main()
