import numpy as np

n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q):
    B, C = map(int, input().split())
    # for j in range(0, len(a)):
    #     if b == a[j]:
    #         a[j] = c
    print(sum(np.where(a == B, C, a)))