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

for i in range(q):
    b,c = list(map(int,input().split()))
    f = False
    for j in range(len(a)):
        if a[j] != b and f == True:
            break
        if a[j] == b:
            a[j] = c
            a_sum += c - b
            f = True           
    
    res.append(a_sum)
        
for i in res:
    
    print(i)