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

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