n = int(input())
a_list = list(map(int,input().split()))
q = int(input())
list = []
for i in range(q):
    sum = 0
    b , c = map(int,input().split())
    for i in range(n) :
        if a_list[i] == b :
          a_list[i] = c
    for l in a_list :
      sum += l
    print(sum)

