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,String s) { String s1=s.substring(l,r); StringBuffer s2=new StringBuffer(s1); s2.reverse(); String s3=s1.toString(); int n=r-l; if(n%2==0) return (int)Math.pow(2,n/2)%(int)(Math.pow(10,9)+7); else return (int)Math.pow(2,n+1/2)%(int)(Math.pow(10,9)+7); // Return the answer for this query modulo 1000000007. } 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(); int result = answerQuery(l, r,s); System.out.println(result); } in.close(); } }