N = int(input())
A = [int(i) for i in input().split()]
num = 0
for i in range(N):
    num += A[i]
Q = int(input())
for _ in range(Q):
    B,C = [int(i) for i in input().split()]
    for i in range(N):
        if A[i] == B:
            A[i] = C
            num += C-B
    print(num)