n = int(input())
a_list = list(map(int, input().split()))
q = int(input())

for i in range(q):
    b, c = map(int, input().split())
    for j in range(n):
        if a_list[j] == b:
          a_list[j] = c
          ans = sum(a_list)
          print(ans)
          continue