def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    a = sum(A)
    Q = int(input())
    for _ in range(Q):
        b, c = map(int, input().split())
        a += (A.count(b))*(c-b)
        print(a)
        while b in A:
            A.remove(b)
            A.append(c)
resolve()