Optimality and hierarchical representation in emergent neural Turing machines and their visual navigation