n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(q):
    bi, ci = map(int, input().split())
    b.append(bi)
    c.append(ci)

for i in range(q):
    a = [(c[i] if j == b[i] else j) for j in a]
    print(sum(a))
