n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = []

for _ in range(q):
    b, c = map(int, input().split())
    a = [c if e == b else e for e in a]
    l.append(a)

for a in l:
    print(sum(a))