def run(n, seq, num, trials):
    '''
    '''
    # count_dict = {i+1 : seq.count(i+1) for i in range(100000)}
    # count_list = [seq.count(i+1) for i in range(100000)]
    count_list = [0 if i+1 not in seq else seq.count(i + 1) for i in range(100000)]

    # _sum = sum([i*v for i,v in count_dict.items()])
    # for i in range(num):
    #     b, c = trials[i]
    #     _val = count_dict.get(b)
    #     if _val == 0:
    #         print(_sum)
    #         continue
    #     _sum += (c-b)*_val
    #     print(_sum)
    #     count_dict[b] = 0
    #     count_dict[c] += _val

    _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)