import numpy as np

def run(n, seq, num, trials):
    count_dict = {i+1 : seq.count(i+1) for i in range(100000)}
    _sum = sum(k*v for k,v in count_dict.items())

    for i in range(num):
        b, c = trials[i]
        _val = count_dict[b]
        if _val == 0:
            continue
        _sum += (c-b)*_val
        print(_sum)
        count_dict[b] = 0
        count_dict[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)