Biologists are studying a certain, interesting kind of worm. Each worm can be seen as a line of cells of different types. When a worm is born, it only consists of a single cell. Every day, exactly 1 cell of the entire worm will grow and change into 2 cells. It is rather easy to determine the age of any such worm, since it's simply one less than the number of cells the worm has.
During a worm's growth, a cell does not change into any 2 arbitrary cells; each worm has a set of ``growth rules" (encoded in its DNA) that it obeys. A growth rule can be expressed as A --> BC , where A , B and C are uppercase letters (with letters A-T), representing different types of the worm's cells. The rule A --> BC means that in one day, any single cell A can be grown into the 2 adjacent cells BC , in that order. Note that the rule I --> JK is different from the rule I --> KJ . Different worms may have a different set of growth rules.
The worms have now thrown the scientists for a loop. Due to some unknown reason, some worms have mutated into a new kind of specimen. This new kind of worm has the exact same properties, except that during its growth, multiple parts of its body can grow at the same time. That is, every day any (at least one, at most all) of its cells can grow; each cell that grows will grow into exactly 2 cells (obeying growth rules similar to their older cousins).
As a result of the mutation, it is no longer trivial to determine the age of a worm. In fact, the exact age of some worms cannot be determined. As a simple example, if a worm has growth rules: A --> BC , B --> AC , C --> AB , and the worm's current cell structure is ACAB , the worm can be either 2 or 3 days old ( A --> BC --> ACAB , or A --> BC --> ACC --> ACAB ). Your task is to find out the youngest possible age of any given mutated worm.