n = int(input())
a = list(map(int,input().split()))
q = int(input())
res = []

for i in range(q):
    a.sort()
    b,c = list(map(int,input().split()))
    for j in range(len(a)):
        if a[j] > b:
            break
        if a[j] == b:
            a[j] = c
    
    res.append(sum(a))
        
for i in res:
    
    print(i)