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

    l = {i:0 for i in range(1,100001)}
    for num in A:
        l[num] += 1

    s = sum(A)

    for _ in range(Q):
        B, C = map(int, input().split())
        num_of_before = l[B]
        l[C] += num_of_before
        s = s + num_of_before * (C-B)
        print(s)


if __name__ == '__main__':
    main()

