for(;r=parseInt(readline(s=""),18)-39;print(s.trim()))for(i=506478097;i;i>>=4)178<(r+=i%16||31)&r<314&r++%18<8?s+=r.toString(18)+" ":0