import sys
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
bc = []
for q in range(Q):
    b, c = map(int, input().split())
    A = [c if b == a else a for a in A]
    print(sum(A))