using System; using System.Linq; namespace Algorithms { class Program { static int max = 1000000007; static string sequence; static void initialize(string s) { sequence = s; } static int answerQuery(int l, int r) { int[] alphabeth = new int[25]; l -= 1; r -= 1; var s = sequence.Substring(l, r - l + 1); for (int i = 0; i < s.Length; i++) { alphabeth[s[i] - 'a']++; } var singleCharacters = alphabeth.Any(x => x % 2 == 1) ? 1 : 0; var pairsOfCharacters = alphabeth.Where(x => x > 0 && x % 2 == 0); var total = pairsOfCharacters.Sum() / 2; var distinct = pairsOfCharacters.Count(); var result = factorial(total) / (factorial(total - distinct)); result += singleCharacters; return result; } static int factorial(int n) { var product = 1; for (int i = 1; i <= n; i++) { product *= i; product %= max; } return product; } static void Main(String[] args) { string s = Console.ReadLine(); initialize(s); int q = Convert.ToInt32(Console.ReadLine()); for (int a0 = 0; a0 < q; a0++) { string[] tokens_l = Console.ReadLine().Split(' '); int l = Convert.ToInt32(tokens_l[0]); int r = Convert.ToInt32(tokens_l[1]); int result = answerQuery(l, r); Console.WriteLine(result); } } } }