Start from a source state and get all possible next states as per question 2 in the same order. Print the first state that from the list that has never been visited before. Using this state as the source, repeat the same operation. Loop for k times.
Sample Input
1
3 3 7
IIT1 IIT2 IIT3 IIT4 IIT5 IIT6 IIT7 IIT8 IIT9
Sample Output
IIT1 IIT2 IIT3 IIT4 IIT5 IIT6 IIT7 IIT9 IIT8
IIT1 IIT2 IIT3 IIT4 IIT5 IIT6 IIT9 IIT7 IIT8
IIT1 IIT2 IIT3 IIT4 IIT5 IIT6 IIT9 IIT8 IIT7
IIT1 IIT2 IIT3 IIT4 IIT5 IIT6 IIT8 IIT9 IIT7
IIT1 IIT2 IIT3 IIT4 IIT5 IIT6 IIT8 IIT7 IIT9
IIT1 IIT2 IIT3 IIT4 IIT5 IIT9 IIT8 IIT7 IIT6
IIT1 IIT2 IIT3 IIT4 IIT5 IIT9 IIT7 IIT8 IIT6