function f(x)x&&(f(t[x]),t[x+=j]||(t[x]=j,s.push(x))) s=[k=2] for(t=[i=0,,1];!t[2043];)f(j=s[i++]) for(o=n=m=+/\d+/(l=readline());n=t[n];)o=n+' '+o for(p='';k<=m;)p+=t[k++]+' ' print(l<'t'?o:p)