n = int(input())
a = list(map(int,input().split()))
q = int(input())
bc = [list(map(int,input().split())) for i in range(q)]

for i in range(q):
    a = [bc[i][1] if j == bc[i][0] else j for j in a]
    print(sum(a))
    