N = int(input())
suretu = list(map(int, input().split()))
Q = int(input())
ans = [0 for i in range(Q)]
for i in range(Q):
    x, y = map(int, input().split())
    for j in range(len(suretu)):
        if x == suretu[j]:
            suretu[j] = y
    ans[i] = sum(suretu)
for i in ans:
    print(i)
