perl -lane'for(@F){print"@F";push@F,shift@F}' file |sort