Topological charge on the lattice: The O(3) case