from typing import List


def main() -> None:
    N = int(input())
    A = sorted([int(_) for _ in input().split(' ')])
    Q = int(input())

    for i in range(Q):
        _1, _2 = map(int, input().split(' '))
        for j in range(N):
            if A[j] < _1:
                continue
            if A[j] == _1:
                A[j] = _2
            else:  # A[j] > _1
                A = sorted(A)
                break

        print(sum(A))


if __name__ == '__main__':
    main()
