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