from collections import defaultdict


def main():
    number = int(input())
    numcount = defaultdict(int)
    for x in input().split():
        numcount[int(x)] += 1
    queries = int(input())
    for _ in range(queries):
        before, after = [int(x) for x in input().split()]
        tmp = numcount[before]
        numcount[before] -= tmp
        numcount[after] += tmp

        print(sum(num * count for num, count in numcount.items()))


if __name__ == '__main__':
    main()
