#include using namespace std; #define pb push_back #define mp make_pair #define ft first #define sd second #define mem(a, v) memset(a, v, sizeof(a)) typedef long long ll; typedef pair PII; typedef vector VI; typedef vector matrix; const ll MOD = 1000000007LL; ll power(ll a, ll n, ll mod = 1000000007LL) { if(n == 0) return 1; ll tmp = power(a, n/2); tmp = (tmp * tmp) % mod; if(n & 1) return (a * tmp) % mod; return tmp; } ll even[30], odd[30], all[30]; ll solve(ll *tmp) { ll ans = 0; mem(odd, 0), mem(even, 0), mem(all, 0); for(int i=0; i<26; i++) { if(tmp[i]) { odd[i] = power(2, tmp[i] - 1); all[i] = power(2, tmp[i]); even[i] = all[i] - odd[i]; even[i] = (even[i] + MOD) % MOD; } } for(int i=0; i<26; i++) { ans = (ans + all[i]) % MOD; for(int j=0; j<26; j++) { if(i == j && !even[j]) continue; all[i] = (all[i] * even[j]) % MOD; } ans = (ans + all[i]) % MOD; } return (ans - 1 + MOD) % MOD; } ll cnt[100100][30]; ll tmp[26]; ll query(int l, int r) { for(int i=0; i<26; i++) { tmp[i] = cnt[r][i]; } for(int i=0; i<26; i++) { tmp[i] -= cnt[l-1][i]; } return solve(tmp); } int main() { int n, q; cin>>n>>q; string str; cin>>str; for(int i=0; str[i]; i++) { for(int j=0; j<26; j++) { cnt[i+1][j] = cnt[i][j]; } cnt[i+1][str[i] - 'a']++; } while(q--) { int l, r; cin>>l>>r; l++, r++; ll ans = query(l, r); cout<