n = int(input())
a = list(map(int, input().split()))
q = int(input())
ans = 0
b = [0] * q
c = [0] * q

for i in range(q):
    b[i], c[i] = map(int, input().split())
    
for i in range(q):
    ans = 0
    for j in range(n):
        if a[j] == b[i]:
            a[j] = c[i]
            
    for k in range(n):
        ans = ans + a[k]
    print(ans)