n = int(input())
a = [int(each) for each in input().split()]
q = int(input())
rep = [tuple(int(each) for each in input().split()) for i in range(q)]

s = [str(sum(a))]

for i in range(q):
    a = [rep[i][1] if x==rep[i][0] else x for x in a]
    s.append(str(sum(a)))
print('\n'.join(s[1:]))