Learning undirected models via query training