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

for i in range(Q):
    B,C = map(int,input().split())
    ai = A.count(B)
    #print(ai)

    if B in A:
        for k in range(ai):
            A.append(C)
        for l in range(ai):
            A.remove(B)

    #print(A)
    print(sum(A))
