n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for i in range(q)]
for f in bc:
    a = [f[1] if j == f[0] else j for j in a]
    print(sum(a))
