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

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

for a in l:
    print(a)