string-puzzle

rishi loves to solve string puzzles. His friend kartheek gave him a task on string. which comprises of a string that has to be manipulated accordingly to the query of kartheek.
for every query there will be the starting and ending index of the string and rishi has to generate all non repeating arrangements of the string in between the specified indices.

INPUT :
first line consists of a string S.
Next line consists of an integer representing no. of queries Q.
Next q lines consists of starting and ending indices S and E respectively.

OUTPUT :
Output should consists of all arrangements of string for all queries. After completion of every query leave one line and print output of next query.

SAMPLE INPUT
abcd
2
1 3
2 3

SAMPLE OUTPUT
abcd
abdc
acbd
acdb
adcb
adbc

abcd
abdc

Source: hackerearth | Difficulty: UNKNOWN_DIFFICULTY


Solutions: