main=interact$unlines.f f(n:_:s)=g(\a->a%a)%g(%' ')where a%b=a:[b|x<-['3'..n]]++[a];g=(init s>>=)