#include #include #include #include #include using namespace std; long long MOD=1000000007; long long gcdExtended(long long a, long long b,long long *x,long long *y) { // Base Case if (a == 0) { *x = 0, *y = 1; return b; } long long x1, y1; // To store results of recursive call long long gcd = gcdExtended(b%a, a, &x1, &y1); // Update x and y using results of recursive // call *x = y1 - (b/a) * x1; *y = x1; return gcd; } long long modInverse(long long a,long long m) { long long x=0, y=0; long long g = gcdExtended(a, m, &x, &y); long long res = (x%m + m) % m; return res; } int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ string s; cin>>s; long long fact[100005]={0},i,j; fact[0]=1; fact[1]=1; for(i=2;i<100005;i++) { fact[i]=(i*fact[i-1])%MOD; } long long len=s.length(); long long a[len][26]; for(i=0;i>t; while(t--) { long long me[26],temp1,temp2; cin>>temp1>>temp2; temp1--; temp2--; for(i=0;i<26;i++) me[i]=a[temp2][i]; if(temp1>=1) { temp1--; for(i=0;i<26;i++) me[i]-=a[temp1][i]; } long long odd=0; long long count=0; long long div=1,me1=1; for(i=0;i<26;i++) { if(me[i]%2==1) odd++; me[i]/=2; count+=me[i]; if(me[i]>0) div=modInverse(fact[me[i]],MOD); else div=1; me1=(me1*div)%MOD; } me1= (me1*fact[count])%MOD; if(odd>0) me1=(me1*odd)%MOD; cout<