n = int(input())
a = list(map(int, input().split()))
a_sum = sum(a)
q = int(input())
b = []
c = []
for i in range(q):
    b_temp, c_temp = map(int, input().split())
    b.append(b_temp)
    c.append(c_temp)
for j in range(q):
    les = c[j]-b[j]
    count = a.count(b[j])
    check_list = [i for i, x in enumerate(a) if x == b[j]]
    if check_list:
        for k in check_list:
            a[k] = c[j]
    plass_total = les * count
    a_sum += plass_total
    print(a_sum)

            
    