def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline
    from collections import Counter

    N = int(input())
    A = list(map(int, input().split()))
    CA = Counter(A)
    Q = int(input())
    for i in range(Q):
        b, c = map(int, input().split())
        CA[c] += CA[b]
        CA[b] = 0
        sumA = 0
        for key, value in CA.items():
            sumA += key*value
        print(sumA)

main()