n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [map(int, input().split()) for _ in range(q)]
b,c = [list(i) for i in zip(*bc)]

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