Query-Specific Learning and Inference for Probabilistic Graphical Models