import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static void initialize(String s) { // This function is called once before all queries. } static int answerQuery(int l, int r) { // Return the answer for this query modulo 1000000007. return 5; } static boolean checkPalin(String key){ int size=key.length(), i=0; if(size==1) return false; else{ while(i<=size/2){ if(key.charAt(i)!=key.charAt(size-i-1)) return false; i++; } } return true; } static void findCombination(String key){ Set set = new TreeSet(); for(int z = 0; z < key.length();z++) { Set temp = new HashSet(); char c = key.charAt(z); for(String str: set) temp.add(str + c); set.add(c+""); set.addAll(temp); } int max=0,count=0; for(String str : set) { ArrayList arr = new ArrayList(); int n = str.length(); permute(str, 0, n-1,arr); for(String i : arr) { if(max arr) { if (l == r && checkPalin(str)) arr.add(str); else { for (int i = l; i <= r; i++) { str = swap(str,l,i); permute(str, l+1, r,arr); str = swap(str,l,i); } } } static String swap(String a, int i, int j) { char temp; char[] charArray = a.toCharArray(); temp = charArray[i] ; charArray[i] = charArray[j]; charArray[j] = temp; return String.valueOf(charArray); } public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.next(); initialize(s); int q = in.nextInt(); for(int a0 = 0; a0 < q; a0++){ int l = in.nextInt(); int r = in.nextInt(); findCombination(s.substring(l-1,r)); } in.close(); } }