separate the last digit, detect the quantity in each of the 4 patterns

Top