n = int(input())
a = list(map(int, input().split()))
q = int(input())
l = {}

for i in range(q):
    b, c = map(int,input().split())
    l[b] = c

for i, j in l.items():
    for x, k in enumerate(a):
        if i == k:
           a[x] = j
    print(sum(a))
