I have difficulties understanding how a TM could count number of characters. I have this problem where the input is made out of characters $\{a, b\}$ and I need to accept if there are $n$ characters of type a in the string. The formal definition for the input language is:
$$ L=\{ \{w,n\}\in\{a,b\}^*\times \mathbb{N} \mid n\neq 0, \exists \alpha,\beta\in\{a,b\} \text{ s.t. }w=\alpha a^n\beta\}. $$
What I do not understand is how could I hold the count since I need to have exactly n characters.