q=[[?A,?E],[?B],[?C],[?D]] gets.to_i.times{|i| c=q[i%4].shift q[(i+1)%4].push c } puts q.map &:join