One way to think of this is LLL#### --> LL | L# | ### where L={A...Z} and #={0...9} since the range of LL is AA to ZZ == 26*26 values == 676 and the range of L# is A0 to Z9 == 26*10 values == 260 and the range of ### is 000 to 999 == 10*10*10 == 1000 values, and all of those are less than or equal to n. Another way to think of this is the slight less efficient but probably easier to code LLL#### --> L | LL | ## | ## where L={A...Z} and #={0...9} You could also think of this as the also less efficient but also probably easier to code CCCCCCC --> C | CC | CC | CC where C={0...9A...Z} since the range of CC is 36*36 values == 1296 which is less than or equal to n. The ABSOLUTELY WRONG way to think of it would be LLL#### --> L | L | L | # | # | # | #