class="code_img_closed" id="code_img_closed_442a077a-ca70-45af-8b01-d3a6e3487f4e"
class="code_img_opened" id="code_img_opened_442a077a-ca70-45af-8b01-d3a6e3487f4e"
#include
#include<string.h>
#include
using namespace std;
int main()
{
int xin,t,i,j,n,ans,id,xiabiao[200010],shunxu;
char ch[200010];
scanf("%d",&t);
while(t--)
{
memset(xiabiao,0,sizeof(xiabiao));
scanf("%d",&n);
scanf("%s",ch);
id=0;shunxu=0;
ans=0;
for(j=0;j)
{
if(ch[j]==ch[shunxu])
xiabiao[id++]=j;
}
ans+=id;
ans=ans%10007;
do
{
shunxu++;
xin=0;
for(i=0;i)
{
if(xiabiao[i]+1<n)
{
if(ch[xiabiao[i]+1]==ch[shunxu])
{
xiabiao[xin++]=xiabiao[i]+1;
}
}
}
ans+=xin;
ans=ans%10007;
id=xin;
}while(shunxu1);
printf("%d\n",ans);
}
return 0;
}