N=int(input())
A=list(map(int,input().split()))
Q=int(input())
Gokei=[]

for _ in range(Q):
    B,C=map(int,input().split())
    i=0
    while B in A:
        A.remove(B)
        i+=1
    A.extend([C]*i)
    Gokei.append(sum(A))

for i in range(Q):
    print(Gokei[i])
    i+=1