import numpy as np

def run(n, seq, num, trials):
    count_list = np.zeros(100000, dtype=int)
    seq = np.array(seq)
    for i in seq:
        if count_list[i-1] > 0:
            continue
        count_list[i-1] = sum(np.where(seq == i,1,0))
    
    _sum = sum((k+1)*v for k,v in enumerate(count_list))
    for i in range(num):
        b, c = trials[i]
        _val = count_list[b-1]
        if _val == 0:
            print(_sum)
            continue
        _sum += (c-b)*_val
        print(_sum)
        count_list[b-1] = 0
        count_list[c-1] += _val

if __name__ == '__main__':
    n = int(input())
    seq = list(map(int, input().split()))
    num = int(input())
    trials = [map(int, input().split()) for _ in range(num)]
    run(n, seq, num, trials)