The $a=2$ test passes because the last table entry is 1 (first statement holds). The $a=3$ test passes because when $r=3$ the second statement holds, that is, the $4$th list element is $267648 = -1 \mod 267649$. When $a=5$, the second statement when $r=4$ holds, that is the $5$th list element is $267648$.