Here is my code-
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t,i,n;
cin>>t;
while(t–)
{
string s;
cin>>s;
n = s.size();
ll dp[n+2]={};
map <char,int> mp;
dp[0]=1;
for(i=0;i<n;i++)
{
dp[i+1]=(2*dp[i])%1000000007;
if(mp.count(s[i])>0)
{
dp[i+1]-=(dp[mp[s[i]]]);
}
mp[s[i]]=i;
dp[i+1]%=1000000007;
}
cout<<dp[n]<<endl;
}
return 0;
}