def run(n, seq, num, trials):
    '''
    '''
    _sum = sum(seq)
    for i in range(num):
        b, c = trials[i]
        if seq.count(b) == 0:
            print(_sum)
            continue

        _sum += (c-b)*seq.count(b)
        print(_sum)
        for i in range(seq.count(b)):
            seq.remove(b)
            seq.append(c)


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)