An unfair coin lands on heads with a probability of $\frac{1}{4}$. When tossed $n$ times, the probability of exactly two heads is the same as the probability of exactly three heads. What is the value of $n$?

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