import numpy as np
n = map(int,input().split())
a = list(map(int,input().split()))
Q = int(input())

list_a = np.array(a)
#print(list_a)

for q in range(Q):
    num = list(map(int,input().split()))
    list_a = np.where(list_a == num[0] ,num[1],list_a)

    print((sum(list_a))  )