Starting with an empty string, we create a string by repeatedly appending one of the letters $H$, $M$, $T$ with probabilities $\frac{1}{4}$, $\frac{1}{2}$, $\frac{1}{4}$, respectively, until the letter $M$ appears twice consecutively. What is the expected value of the length of the resulting string?

Let's think step by step and output the final answer within \boxed{}.
user