The meaning of this phrase is "from beginning to end, with total knowledge", and as our colleague Felipe Lorenzo del Río explains, it seems to come from the teacher's recitation ""eme", "a", "ma!", "pe", "a", "pa!", with which the first words are taught. Although there is a version that proposes a distortion of the abbreviation "of P . a P . " ("from [initial] word to [final] word") used by medieval copyists to indicate that the transcribed book was a faithful copy. See "from end to end", "from the cross to the date".
Colloquial adverbial locution already used in the sixteenth century in the Celestina that reminds us of learning in school: the p with the a, pa; with two semantic nuances. The first and most common: from beginning to end, from end to end, exhaustively, in detail, totally, entirely, in its entirety. The second most outdated: clearly, obviously, intelligibly or obviously.