n = int(input())
a = input().split()
a_int = [int(x) for x in a]
a_sum = sum(a_int)
a_num = []
for i in range(100001):
    a_num.append(a_int.count(i))

q = int(input())
tmp = []
for i in range(q):
    bc = input().split()
    b = int(bc[0])
    c = int(bc[1])
    tmp.append([b, c])

for j in range(len(tmp)):
    b_tmp = tmp[j][0]
    c_tmp = tmp[j][1]

    n = a_num[b_tmp]
    
    a_sum += (c_tmp - b_tmp) * n
    print(a_sum)

    a_num[b_tmp] = 0
    a_num[c_tmp] += n