N = int(input())  # Read N Number of integers
A = list(map(int, input().split(' ')))  # read the sequence of A
Q = int(input())   # read Q from user
def myindex(num1, num2, default=False):  # create the Function myindex 
    if num2 in num1:
        return num1.index(num2)
    else:
        return default
 
list1 = []  # create a list 
for a in range(0, Q): # for loop to get B and C
  c = list(map(int, input().split(' ')))
  t = myindex(A, c[0], -1)
  while t != -1:
    A[t] = c[1]
    t = myindex(A, c[0], -1)
  F = sum(A)
  list1.append(F) # add to the list1 
for s in list1:
  print(s) 