Integrability conditions for Heisenberg and Grushin-type distributions