n = int(input())
arr = list(map(int, input().split()))
q = int(input())
b = []
c = []
for i in range(0,q):
  bi, ci = list(map(int, input().split()))
  b.append(bi)
  c.append(ci)
for i in b:
  if i in arr:
    ind1 = arr.index(i)
    ind2 = b.index(i)
    arr[ind1] = c[ind2]
    print(sum(arr))
    
