The first sign that something was wrong appeared more than two years ago when a company grading student tests from Philadelphia noticed that erasures from wrong to right answers showed what investigators delicately called “statistical evidence of improbable results.”

Pennsylvania began an investigation, eventually instructing the school district to look into improprieties at 19 schools. Over the course of a year, the district found disturbing patterns in parts of the system that resulted in three principals being fired last week for test cheating in one of the largest such scandals in the country.

Some administrators were giving answer keys to teachers who passed them on to students. In other cases, principals took completed exams home at night and doctored the answer sheets. And in some schools, teachers and administrators gathered secretly in conference rooms with test booklets, pencils and erasers and changed wrong answers.

“Any time you’ve got cheating going on by adults, that’s egregious,” said Michael A. Davis, general counsel to the Philadelphia school district, who described some of the findings of the inquiry.