Near-Optimal Degree Testing for Bayes Nets