A Lindenmayer system (L-system) is a parallel rewriting system and a type of formal grammar. Some uses of L-systems include creating visual representations of vegetation, flowers, trees, and grasses.

An L-system consists of an axiom and a set of rules.

- The axiom () is a string that represents the starting state of the L-system.
- The set of rules defines what happens to each letter in an iteration of the system.

Given the axiom, set of rules, and the number of iterations for which to run the system, you are tasked with generating a two-letter code followed by the length of the final state. The two-letter code will be the concatenation of the first letter and last letter of the final state.

#### Input Specification

The input will contain 10 datasets. Each dataset begins with three terms , the number of rules, the number of iterations, and the axiom. The next lines each contain a character followed by a string which represents a rule stating that each occurrence of should be replaced with the string . It is guaranteed that each letter in the system will have a corresponding rule.

For the first 4 cases, . For the first 7 cases, .

#### Output Specification

For each dataset, output a concatenation of first and last letter of the state and the length of the state after iterations.

#### Sample Input (Two Datasets Shown)

```
3 5 AC
A CAB
B CB
C ACB
4 5 AD
A AC
B ACA
C BD
D B
```

#### Sample Output

```
CB 288
AB 60
```

#### Explanation of Sample Datasets

In the first dataset, the first iteration is AC > CABACB.

In the second dataset, the first two iterations are AD > ACB > ACBDACA.

Educational Computing Organization of Ontario - statements, test data and other materials can be found at ecoocs.org

## Comments

How do you fix an RTE?

The string is becoming too big, that is why you get the RTE. You need to find a better solution that only keeps track of the first letter, last letter and the length, and does not store the full string.

Thx

It may be helpful to know that the the initial string and the rules only consist of uppercase letters of the alphabet, as implied by the constraints.