def run(n, seq, num, trials):
    '''
    '''
    for i in range(num):
        b, c = trials[i]
        if b not in seq:
            print(sum(seq))
            continue
        seq = [e if e != b else c for e in seq]
        print(sum(seq))


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)