N=int(input())
a=list(map(int,input().split()))
Q=int(input())
l=[0]*Q
for i in range(Q):
    l[i]=list(map(int,input().split()))
    
for i in range(Q):    
    a = [(l[i][1] if s == l[i][0] else s) for s in a]
    print(sum(a))
