N = int(input())
A = list(map(int,input().split()))
Q = int(input())
b = []
c = []
for i in range(Q):
    B,C = map(int,input().split())
    b.append(B)
    c.append(C)

for i in range(Q):
    for j in range(N):
        if A[j] == b[i]:
            A[j] = c[i]
    print(sum(A))