n = int(input())
a = list(map(int, input().split()))
q = int(input())
result = []
for i in range(q):
    b, q = list(map(int, input().split()))
    a = [q if x == b else x for x in a]
    result.append(sum(a))
for r in result:
    print(r)