Generate all cyclic permutations of a number
Basic Accuracy: 23.2% Submissions: 696 Points: 1

Given a number N, generate all the possible cyclic permutations of the number.

Input :  123
Output : 123
         312
         231

Input :  5674
Output : 5674
         4567
         7456
         6745

Input:
The first line consists of an integer T i.e number of test cases.Each testcase follows single line input i.e, integer n. 

Output:
Print all cyclic permutations with spaces in between.

Constraints: 
1 <= T <= 100
1 <= n <= 109

Example:
Input:

2
123
5674

Output:
123 312 231
5674 4567 7456 6745

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.