n = int(input())
A = list(map(int,input().split()))
s = sum(A)
Q = int(input())
for _ in range(Q):
    B,C = map(int,input().split())
    if B in A:
        c = A.count(B)
        A = [C if i == B else i for i in A]
        s = s-((B-C)*c)

    print (s)
