This dungeon has $49$ cells. In $7$ cells ($A$ to $G$ in the diagram) there is a locked door (black bar). The keys are in cells $a$ to $g$ respectively. The other doors open only from one side, as shown. \\
\medskip
How does the prisoner in cell $O$ escape? He can pass through any door any number of times and need not unlock the doors in any special order. His aim is to get the key from cell $g$ and use it to escape through cell $G$