N = int(input())
A = list(map(int, input().split()))
Q = int(input())
change_rule = {}
for i in range(Q):
    B, C = map(int, input().split())
    change_rule[B] = C

for Bi in change_rule.keys():
    for j in range(N):
        if A[j] == Bi:
            A[j] = change_rule[Bi]
    print(sum(A))
