N = int(input())
h = list(map(int,input().split()))
Q = int(input())
a = [[int(i) for i in input().split()] for _ in range(Q)]
c = 0
ans = []
for i in range(0, Q):
    h = [a[i][1] if j == a[i][0] else j for j in h] 
    c = sum(h)
    ans.append(c)
for i in range(0, Q):
     print(ans[i])