Let S be the set of all 3×3 matrices A=[aij] whose nine entries each belong to the set {0,1,2}. Let AT denote the transpose of A, and let tr(M) denote the trace of a square matrix M, that is, the sum of its diagonal entries. Find the number of matrices A in S for which tr(ATA)=5.