n = int(input())
arr = list(map(int,input().split()))
t = int(input())
su = sum(arr)
print(su)
while t:
    t-=1
    k,r = map(int,input().split())
    p = arr.count(k)
    su += (r-k)*p
    print(su)