def main() -> None:
    N = int(input())
    A = [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:
                A[j] = _2

        print(sum(A))


if __name__ == '__main__':
    main()
