def run(n, seq, num, trials):

    count_list = [0] * 100000
    for i in set(seq):
        count_list[i] = seq.count(i)
    _sum = sum(i*v for i,v in enumerate(count_list))
    for i in range(num):
        b, c = trials[i]
        _val = count_list[b]
        if _val == 0:
            print(_sum)
            continue
        _sum += (c-b)*_val
        print(_sum)
        count_list[b] = 0
        count_list[c] += _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)