Rack and cog driven locomotives