n = int(input())
A_list = list(map(int, input().split()))
q = int(input())

s = [0]*q

for i in range(0, q):
    b, c = map(int, input().split())
    for j in range(0, n):
        if A_list[j] == b:
            A_list[j] = c
        s[i] = s[i] + A_list[j]
    print(s[i])