Cohomology classes responsible for Brauer-Manin obstructions, with applications to rational and K3 surfaces