n = int(input())
a = list(map(int,input().split()))
q = int(input())
b = []
c = []
l = [list(map(int, input().split())) for i in range(q)]
for i in range(len(l)):
    b.append(l[i][0])
    c.append(l[i][1])
for i in range(q):
    if b[i] in a:
        for j in range(len(a)):
            if a[j] == b[i]:
                a[j] = c[i]
        print(sum(a))
    else:
        print(sum(a)) 
        