n = int(input())
a_list = list(map(int, input().strip().split()))
q = int(input())
q_list = [list(map(int, input().strip().split())) for i in range(q)]

for i in range(q):
    b = q_list[i][0]
    c = q_list[i][1]
    out = 0
    for j in range(n):
        a_list[j] = c if a_list[j] == b else a_list[j]
    print(sum(a_list))
