import numpy as np
s = list(map(int, input().split()))
n=s[0]
a = np.array(list(map(int, input().split())))
s = list(map(int, input().split()))
q=s[0]
ans={}
for i in range(q):
    s = list(map(int, input().split()))
    if not (s[0],s[1]) in ans:
        a=np.where(a==s[0],s[1],a)
        ans[(s[0],s[1])]=np.sum(a)
        print(ans[(s[0],s[1])])
    else:
        print(ans[s[0],s[1]])

