#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll ssize=s.size();
	string s1;
	string s3;
	ll flag=0;
	ll next1=s[cnt]-'0';
	while(cnt!=x){

		num1=s[cnt]-'0';
		s3+=s[cnt];

		//cout<<num1<<endl;
		cnt++;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=cnt;
		ssize=(ssize+((tod%mod)*(num1%mod))%mod)%mod;
		ll cur=s.size();
		if(num1!=1 && flag==0){
			for(int i=0;i<num1;i++){
				for(int j=cnt;j<cur;j++){
				 s1+=s[j];
				 if(s1.size()+s3.size()>100006){
				 	flag=1;
				 	break;
				 }
				}
				if(flag)break;
			}
			s.clear();
			s+=s3+s1;
		}
		s1.clear();
		//s3.clear();
		//cout<<ssize<<endl;

		//cout<<s<<endl;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,0,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll num2=0;
	ll ssize=s.size();
	string s1;
	string s3;
	ll flag=0;
	ll next1=s[cnt]-'0';
	while(cnt<x){

		num1=s[cnt]-'0';
		num1--;
		cnt++;
		//cout<<num1<<endl;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=cnt;
		ssize=(ssize+((tod%mod)*((num1+1)%mod))%mod)%mod;
		ll cur=s.size();
		//cnt++;

			while(s.size()<x && num1--){
				for(int i=cnt;i<cur,s.size()<x;i++){
					s+=s[i];
				}
			}

		//cout<<ssize<<endl;

		//cout<<s<<endl;
		//cnt++;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,0,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll num2=0;
	ll ssize=s.size();
	string s1;
	string s3;
	ll flag=0;
	ll next1=s[cnt]-'0';
	while(cnt!=x){

		num1=s[cnt]-'0';
		s3+=s[cnt];

		//cout<<num1<<endl;
		cnt++;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=cnt;
		ssize=(ssize+((tod%mod)*(num1%mod))%mod)%mod;
		ll cur=s.size();
		if(num1!=1 && flag==0){
			for(int i=0;i<num1;i++){
				for(int j=cnt;j<cur;j++){
				 s1+=s[j];
				 num2=s[cnt]-'0';
				 if(num2*(s1.size()+s3.size())>100006){
				 	flag=1;
				 	break;
				 }
				}
				if(flag)break;
			}
			s.clear();
			s+=s3+s1;
		}
		s1.clear();
		//s3.clear();
		//cout<<ssize<<endl;

		//cout<<s<<endl;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,0,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll num2=0;
	ll ssize=s.size();
	string s1;
	string s3;
	ll flag=0;
	ll next1=s[cnt]-'0';
	while(cnt<=x){

		num1=s[cnt-1]-'0';
		num1--;

		//cout<<num1<<endl;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=(ssize+((tod%mod)*((num1)%mod))%mod)%mod;
		ll cur=s.size();
		cnt++;

			while(s.size()<x && num1--){
				for(int i=cnt-1;i<cur;i++){
					s+=s[i];
				}
			}

		//cout<<ssize<<endl;

		//cout<<s<<endl;
		//cnt++;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,1,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll num2=0;
	ll ssize=s.size();
	string s1;
	string s3;
	ll flag=0;
	ll next1=s[cnt]-'0';
	while(cnt<=x){

		num1=s[cnt-1]-'0';
		num1--;

		//cout<<num1<<endl;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=cnt;
		ssize=(ssize+((tod%mod)*((num1+1)%mod))%mod)%mod;
		ll cur=s.size();
		cnt++;

			while(s.size()<x && num1--){
				for(int i=cnt-1;i<cur,s.size()<x;i++){
					s+=s[i];
				}
			}

		//cout<<ssize<<endl;

		//cout<<s<<endl;
		//cnt++;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,1,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll num2=0;
	ll ssize=s.size();
	string s1;
	string s3;
	ll flag=0;
	ll next1=s[cnt]-'0';
	while(cnt<x){

		num1=s[cnt-1]-'0';
		num1--;

		//cout<<num1<<endl;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=cnt;
		ssize=(ssize+((tod%mod)*((num1+1)%mod))%mod)%mod;
		ll cur=s.size();
		cnt++;

			while(s.size()<x && num1--){
				for(int i=cnt-1;i<cur,s.size()<x;i++){
					s+=s[i];
				}
			}

		//cout<<ssize<<endl;

		//cout<<s<<endl;
		//cnt++;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,1,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll ssize=s.size();
	string s1;
	string s3;
	ll flag=0;
	ll next1=s[cnt]-'0';
	while(cnt!=x){

		num1=s[cnt]-'0';
		s3+=s[cnt];

		//cout<<num1<<endl;
		cnt++;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=cnt;
		ssize=(ssize+((tod%mod)*(num1%mod))%mod)%mod;
		ll cur=s.size();
		if(num1!=1 && flag==0){
			for(int i=0;i<num1;i++){
				for(int j=cnt;j<cur;j++){
				 s1+=s[j];
				 if(s1.size()+s3.size()>1000006){
				 	flag=1;
				 	break;
				 }
				}
				if(flag)break;
			}
			s.clear();
			s+=s3+s1;
		}
		s1.clear();
		//s3.clear();
		//cout<<ssize<<endl;

		//cout<<s<<endl;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,0,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll ssize=s.size();
	string s1;
	string s3;

	ll next1=s[cnt]-'0';
	while(cnt!=x){

		num1=s[cnt]-'0';
		s3+=s[cnt];

		//cout<<num1<<endl;
		cnt++;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=cnt;
		ssize=(ssize+((tod%mod)*(num1%mod))%mod)%mod;
		ll cur=s.size();
		if(num1!=1){
		if(cur<1000007){
			for(int i=cnt;i<cur;i++){
				s1+=s[i];
			}
			//s3+=s[cnt-1];
			s.clear();
			s=s3;
		 for(ll i=0;i<num1;i++){
			s+=s1;
			if(s.size()>1000006)break;
			}
			//cout<<s.size()<<endl;
		}
		}
		s1.clear();
		//s3.clear();
		//cout<<ssize<<endl;

		//cout<<s<<endl;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,0,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll num2=0;
	ll ssize=s.size();
	string s1;
	string s3;
	ll flag=0;
	ll next1=s[cnt]-'0';
	while(cnt!=x){

		num1=s[cnt]-'0';
		s3+=s[cnt];

		//cout<<num1<<endl;
		cnt++;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=cnt;
		ssize=(ssize+((tod%mod)*(num1%mod))%mod)%mod;
		ll cur=s.size();
		if(num1!=1 && flag==0){
			for(int i=0;i<num1;i++){
				for(int j=cnt;j<cur;j++){
				 s1+=s[j];
				 num2=s[cnt]-'0';
				 if((s1.size()+s3.size())>x){
				 	flag=1;
				 	break;
				 }
				}
				if(flag)break;
			}
			s.clear();
			s+=s3+s1;
		}
		s1.clear();
		//s3.clear();
		//cout<<ssize<<endl;

		//cout<<s<<endl;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,0,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll num2=0;
	ll ssize=s.size();
	string s1;
	string s3;
	ll flag=0;
	ll next1=s[cnt]-'0';
	while(cnt!=x){

		num1=s[cnt]-'0';
		s3+=s[cnt];

		//cout<<num1<<endl;
		cnt++;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=cnt;
		ssize=(ssize+((tod%mod)*(num1%mod))%mod)%mod;
		ll cur=s.size();
		if(num1!=1 && flag==0){
			for(int i=0;i<num1;i++){
				for(int j=cnt;j<cur;j++){
				 s1+=s[j];
				 num2=s[cnt]-'0';
				 if((s1.size()+s3.size())>=x){
				 	flag=1;
				 	break;
				 }
				}
				if(flag)break;
			}
			s.clear();
			s+=s3+s1;
		}
		s1.clear();
		//s3.clear();
		//cout<<ssize<<endl;

		//cout<<s<<endl;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,0,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define cin1(x) cin>>x
#define cin2(x,y) cin>>x>>y
#define cin3(x,y,z) cin>>x>>y>>z
#define ll long long
#define mp make_pair
#define pb push_back
#define nl printf("\n")
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)
const int todx[] = { -2, -2, -1, -1,  1,  1,  2,  2 };
const int tody[] = { -1,  1, -2,  2, -2,  2, -1,  1 };
bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}

ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}

void adder(string s,ll num,ll x){

}
ll chalok(string s,ll cnt,ll sz,ll x){
	ll num1=0;
	ll num2=0;
	ll ssize=s.size();
	string s1;
	string s3;
	ll flag=0;
	ll next1=s[cnt]-'0';
	while(cnt!=x){

		num1=s[cnt]-'0';
		s3+=s[cnt];

		//cout<<num1<<endl;
		cnt++;

		ll tod=((ssize-cnt)%mod+mod)%mod;
		ssize=cnt;
		ssize=(ssize+((tod%mod)*(num1%mod))%mod)%mod;
		ll cur=s.size();
		if(num1!=1 && flag==0){
			for(int i=0;i<num1;i++){
				for(int j=cnt;j<cur;j++){
				 s1+=s[j];
				 num2=s[cnt]-'0';
				 if(num2*(s1.size()+s3.size())>1000006){
				 	flag=1;
				 	break;
				 }
				}
				if(flag)break;
			}
			s.clear();
			s+=s3+s1;
		}
		s1.clear();
		//s3.clear();
		//cout<<ssize<<endl;

		//cout<<s<<endl;

	}
	return ssize;

}

int main(){
 ll T;
 cin>>T;
 //flash;
 tc(t,T){
 	ll x;
 	cin>>x;
 	string s;
 	cin>>s;
 	ll cnt=0;
 	ll sz=0;
 	ll ans=chalok(s,0,0,x);
 	cout<<ans<<endl;
 }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int x;
		scanf("%d",&x);
		string s;
		cin>>s;
		ll L=0,ans=s.size();
		while(L<x){
			L++;
			if(s.size()<x){
				string c=s.substr(L);
				for(int i=0;i<s[L-1]-'0'-1;i++)
					s+=c;
			}
			ans=(ans+(ans-L)*(s[L-1]-'0'-1)%mod+mod)%mod;
		}
		printf("%lld\n",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int z=0;z<t;z++)
	{
		long long int x,l=0,k,m;
		long long int e;
		cin>>x;
		string s,c;
		cin>>s;
		long long int n=s.length();
		while(l!=x)
		{
			l++;
			c=s.substr(l);
			m=s[l-1]-48;
			while(--m)
			{
				s+=c;
			}
			e=s.length();
			if(e>=x)
				break;
		}
		while(l!=x)
		{

			l++;
			m=s[l-1]-48;
			long long int y=m*(e-l);
			e=(y%(1000000007)+l%(1000000007))%1000000007;
		}
		cout<<e<<"\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int z=0;z<t;z++)
	{
		long long int x,l=0,k,m;
		long long int e;
		cin>>x;
		string s,c;
		cin>>s;
		long long int n=s.length();
		while(l!=x)
		{
			l++;
			c=s.substr(l);
			m=s[l-1]-48;
			while(--m)
			{
				s+=c;
			}
			e=s.length();
			if(e>=x)
				break;
		}
		while(l!=x)
		{

			l++;
			m=s[l-1]-48;
			long long int y=(m*(e-l)%1000000007)%1000000007;
			e=(y%(1000000007)+l%(1000000007))%1000000007;
		}
		cout<<e<<"\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int z=0;z<t;z++)
	{
		long long int x,l=0,k,m;
		long long int e;
		cin>>x;
		string s,c;
		cin>>s;
		e=s.length();
		while(l!=x)
		{
			l++;
			if(s.length()<x)
			{
			c=s.substr(l);
			m=s[l-1]-48;
			while(--m)
			{
				s+=c;
			}
			}
			e=(e+(e-l)*(s[l-1]-'0'-1)%1000000007+1000000007)%1000000007;
		}
		cout<<e<<"\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int z=0;z<t;z++)
	{
		long long int x,l=0,k,m;
		long long int e;
		cin>>x;
		string s,c;
		cin>>s;
		long long int n=s.length();
		while(l!=x)
		{
			l++;
			c=s.substr(l);
			m=s[l-1]-48;
			while(--m)
			{
				s+=c;
			}
			e=s.length()%1000000007;
			if(e>=x)
				break;
		}
		while(l!=x)
		{

			l++;
			m=s[l-1]-48;
			long long int y=(m*(e-l)%1000000007)%1000000007;
			e=(y%(1000000007)+l%(1000000007))%1000000007;
		}
		cout<<e<<"\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int z=0;z<t;z++)
	{
		int x,l=0,k,m;
		long long int e;
		cin>>x;
		string s,c;
		cin>>s;
		int n=s.length();
		while(l!=x)
		{
			l++;
			c=s.substr(l);
			m=s[l-1]-48;
			while(--m)
			{
				s+=c;
			}
			e=s.length();
			if(e>=x)
				break;
		}
		while(l!=x)
		{

			l++;
			m=s[l-1]-48;
			long long int y=m*(e-l);
			e=(y%(1000000007)+l%(1000000007))%1000000007;
		}
		cout<<e<<"\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	for(int z=0;z<t;z++)
	{
		long long int x,l=0,k,m;
		long long int e;
		cin>>x;
		string s,c;
		cin>>s;
		e=s.size();
		while(l!=x)
		{
			l++;
			if(s.size()<x)
			{
			c=s.substr(l);
			for(int i=0;i<s[l-1]-'0'-1;i++)
					s+=c;
			}
			e=(e+(e-l)*(s[l-1]-'0'-1)%1000000007+1000000007)%1000000007;
		}
		printf("%lld\n",e);
	}
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#define ll long long
#define maxn 1000005
#define re register
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll x,cnt,f,f2;
ll len;
char s2[maxn];
const ll modc=1e9+7;

int main()
{
	ll T=read();
	while(T--)
	{
		x=read(); scanf("%s",s2);
		len=strlen(s2); f2=0;
		ll nlen=len;
		for(int i=0;i<x;i++)
		{
			if(i>len) {cout<<strlen(s2)<<endl; f2=1; break;}
			if(s2[i]=='1') continue;
			if(f2==0)
			{
				char tmp[maxn]; int cnt=0;
				for(int j=i+1;j<len;j++) tmp[++cnt]=s2[j];
				for(int j=1;j<=s2[i]-'0'-1&&len<=x;j++) for(int k=1;k<=cnt&&len<=x;k++) s2[len++]=tmp[k];
				if(len>x) f2=1;
				ll tmp1=(nlen-i-1+modc)%modc;
				nlen=(nlen+(tmp1*(s2[i]-'0'-1)))%modc;
			}
			else
			{
				ll tmp1=(nlen-i-1+modc)%modc;
				nlen=(nlen+(tmp1*(s2[i]-'0'-1)))%modc;
			}
		}
		cout<<nlen<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#define ll long long
#define maxn 1000005
#define re register
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll x,cnt,f,f2;
ll len;
char s2[maxn];
const ll modc=1e9+7;

int main()
{
	ll T=read();
	while(T--)
	{
		x=read(); scanf("%s",s2);
		len=strlen(s2); f=0;
		ll nlen=len;
		for(int i=0;i<x;i++)
		{
			if(i>len) {cout<<strlen(s2)<<endl; f2=1; break;}
			if(s2[i]=='1') continue;
			char tmp[maxn]; int cnt=0;
			for(int j=i+1;j<len;j++) tmp[++cnt]=s2[j];
			for(int j=1;j<=s2[i]-'0'-1&&len<=x;j++) for(int k=1;k<=cnt&&len<=x;k++) s2[len++]=tmp[k];
			ll tmp1=(nlen-i-1+modc)%modc;
			nlen=(nlen+(tmp1*(s2[i]-'0'-1)))%modc;
		}
		cout<<nlen<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#define ll long long
#define maxn 1000005
#define re register
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll x,cnt,f,f2;
ll len;
string s2;
const ll modc=1e9+7;

int main()
{
	ll T=read();
	while(T--)
	{
		x=read(); cin>>s2; f2=0;
		ll nlen=len; nlen=s2.length();
		for(int i=0;i<x;i++)
		{
			if(i>s2.length()) {cout<<s2.length()<<endl; f2=1; break;}
			if(s2[i]=='1') continue;
			ll tmp1=(nlen-i-1+modc)%modc;
			nlen=(nlen+(tmp1*(s2[i]-'0'-1)))%modc;
			if(f2==0)
			{
				string tmp; tmp.clear();
				for(int j=i+1;j<s2.length();j++) tmp.push_back(s2[j]);
				for(int j=1;s2.length()<=x&&j<=s2[i]-'0'-1;j++) s2=s2+tmp;
				if(s2.length()>x) f2=1;
			}
		}
		cout<<nlen<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#define ll long long
#define maxn 1000005
#define re register
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll x,cnt,f,f2;
ll len;
char s2[maxn];
const ll modc=1e9+7;

int main()
{
	ll T=read();
	while(T--)
	{
		x=read(); scanf("%s",s2);
		len=strlen(s2); f2=0;
		ll nlen=len;
		for(int i=0;i<x;i++)
		{
			if(i>len) {cout<<strlen(s2)<<endl; f2=1; break;}
			if(s2[i]=='1') continue;
			if(f2==0)
			{
				char tmp[maxn]; int cnt=0;
				for(int j=i+1;j<len;j++) tmp[++cnt]=s2[j];
				for(int j=1;j<=s2[i]-'0'-1&&len<=x;j++) for(int k=1;k<=cnt&&len<=x;k++) s2[len++]=tmp[k];
				if(len>x) f2=1;
			}
			else
			{
				ll tmp1=(nlen-i-1+modc)%modc;
				nlen=(nlen+(tmp1*(s2[i]-'0'-1)))%modc;
			}
		}
		cout<<nlen<<endl;
	}
	return 0;
}


#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#define ll long long
#define maxn 1000005
#define re register
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll x,cnt,f,f2;
ll len;
string s2;
const ll modc=1e9+7;

int main()
{
	ll T=read();
	while(T--)
	{
		x=read(); cin>>s2; f2=0;
		ll nlen=len; nlen=s2.length();
		for(int i=0;i<x;i++)
		{
			if(i>s2.length()) {cout<<s2.length()<<endl; f2=1; break;}
			if(s2[i]=='1') continue;
			ll tmp1=(nlen-i-1+modc)%modc;
			nlen=(nlen+(tmp1*(s2[i]-'0'-1)))%modc;
			if(f2==0)
			{
				string tmp; tmp.clear();
				for(int j=i+1;j<s2.length();j++) tmp.push_back(s2[j]);
				for(int j=1;s2.length()<=x&&j<=s2[i]-'0'-1;j++) s2=s2+tmp;
				if(s2.length()>x) f2=1;
			}
		}
		cout<<nlen<<endl;
	}
	return 0;
}


#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#define ll long long
#define maxn 1000005
#define re register
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll x,cnt,f,f2;
ll len;
string s2;
char s[maxn];
const ll modc=1e9+7;

int main()
{
	ll T=read();
	while(T--)
	{
		x=read(); scanf("%s",s);
		for(int i=0;i<strlen(s);i++) s2.push_back(s[i]); f2=0;
		ll nlen=len; nlen=s2.length();
		for(int i=0;i<x;i++)
		{
			if(i>s2.length()) {cout<<s2.length()<<endl; f2=1; break;}
			if(s2[i]=='1') continue;
			ll tmp1=(nlen-i-1+modc)%modc;
			nlen=(nlen+(tmp1*(s2[i]-'0'-1)))%modc;
			if(f2==0)
			{
				string tmp; tmp.clear();
				for(int j=i+1;j<s2.length();j++) tmp.push_back(s2[j]);
				for(int j=1;s2.length()<=x&&j<=s2[i]-'0'-1;j++) s2=s2+tmp;
				if(s2.length()>x) f2=1;
			}
		}
		cout<<nlen<<endl; s2.clear();
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#define ll long long
#define maxn 1000005
#define re register
#define inf 1e9
#define eps 1e-10
using namespace std;

inline ll read()
{
	ll x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll x,cnt,f,f2;
ll len;
char s2[maxn];
const ll modc=1e9+7;

int main()
{
	ll T=read();
	while(T--)
	{
		x=read(); scanf("%s",s2);
		len=strlen(s2); f2=0;
		ll nlen=len;
		for(int i=0;i<x;i++)
		{
			if(i>len) {cout<<strlen(s2)<<endl; f2=1; break;}
			if(s2[i]=='1') continue;
			ll tmp1=(nlen-i-1+modc)%modc;
			nlen=(nlen+(tmp1*(s2[i]-'0'-1)))%modc;
			if(f2==0)
			{
				char tmp[maxn]; int cnt=0;
				for(int j=i+1;j<len;j++) tmp[++cnt]=s2[j];
				for(int j=1;j<=s2[i]-'0'-1&&len<=x;j++) for(int k=1;k<=cnt&&len<=x;k++) s2[len++]=tmp[k];
				if(len>x) f2=1;
			}
		}
		cout<<nlen<<endl;
	}
	return 0;
}


#include<iostream>
#include<bits/stdc++.h>
#define int long long

using namespace std;
int dp[1000001];
typedef pair<int, int> pi;

int32_t main()
{
	int t;
	cin >> t;

	while(t--)
	{
		int x;
		cin >> x;
		string s;
		cin >> s;
		std::vector<int> v;
		for(auto i: s){
			v.push_back(i - '0');
		}
		int p1 = 0;
		while(v.size() <= x && p1 < v.size() - 1){
			int num = v[p1];
			int start = p1 + 1;
			int end = v.size();
			num--;
			while(num--){
				for (int i = start; i < end; ++i)
				{
					v.push_back(v[i]);
				}
			}
			p1++;
		}

		dp[0] = s.size();
		int i = 1, ans;
		while(i <= x && i <= v.size()){
			dp[i] = (dp[i-1] + (dp[i-1] - i)*(v[i-1] - 1));
			dp[i] %= 1000000007;
			ans = dp[i];
			i++;
		}

		cout << ans << endl;

	}
}


#include<iostream>
#include<bits/stdc++.h>
#define int long long

using namespace std;
typedef pair<int, int> pi;
int inp[3000][2], flag = 0;
map<int, int> vis;
std::vector<int> ans;
map<int, std::vector<int>> adj;
float distance(int x1, int y1, int x2, int y2)
{
    // Calculating distance
    return sqrt(pow(x2 - x1, 2) +
                pow(y2 - y1, 2) * 1.0);
}

void makeGaph(std::vector<pi> v){
	for(auto i: v){
		adj[i.first].push_back(i.second);
		adj[i.second].push_back(i.first);
	}
}

void DFS(int node){
	if(!vis[node]){
		vis[node] = 1;
		ans.push_back(node);
	}

	for(auto i: adj[node]){
		if(!vis[i])
			DFS(i);
	}
}

int32_t main()
{
	int n;
	cin >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> inp[i][0] >> inp[i][1];
	}
	map<float, std::vector<pi>> distv;
	map<pair<int, float>, std::vector<pi>> freqdist;
	for (int i = 0; i < n; ++i)
	{
		for (int j = i + 1; j < n; ++j)
		{
			float dist = distance(inp[i][0], inp[i][1], inp[j][0], inp[j][1]);
			//cout << "dist " << dist << endl;
			distv[dist].push_back({i,j});
		}
	}

	for(auto i: distv){
		// cout << i.first << " ->";
		// for(auto j: i.second){
		// 	cout << j.first << " " << j.second << " ";
		// }
		// cout << endl;
		freqdist[{i.second.size(), i.first}] = distv[i.first];
	}

	for (auto i: freqdist)
	{
		ans.clear();
		flag = 0;
		adj.clear();
		makeGaph(i.second);
		vis.clear();
		for(auto j: adj){
			if(!vis[j.first]){
				DFS(j.first);
				break;
			}
		}
		if(!flag){
			cout << ans.size() << endl;
			for(auto j: ans){
				cout << j + 1<< " ";
			}
			cout << endl;
			return 0;
		}
	}
}


#include<iostream>
#include<bits/stdc++.h>
#define int long long

using namespace std;
int dp[1000001];
typedef pair<int, int> pi;

int32_t main()
{
	int t;
	cin >> t;

	while(t--)
	{
		int x;
		cin >> x;
		string s;
		cin >> s;
		std::vector<int> v;
		for(auto i: s){
			v.push_back(i - '0');
		}
		int p1 = 0;
		while(v.size() <= x && p1 < v.size() - 1){
			int num = v[p1];
			int start = p1 + 1;
			int end = v.size();
			num--;
			while(num--){
				for (int i = start; i < end; ++i)
				{
					v.push_back(v[i]);
				}
			}
			p1++;
		}

		dp[0] = s.size();
		int i = 1, ans;
		while(i <= x && i <= v.size()){
			dp[i] = dp[i-1];
			dp[i] += (dp[i-1] - i)*(v[i-1] - 1);
			dp[i] %= 1000000007;
			ans = dp[i];
			i++;
		}

		cout << ans << endl;

	}
}


#include<iostream>
#include<bits/stdc++.h>
#define int long long

using namespace std;
int dp[1000001];
typedef pair<int, int> pi;

int32_t main()
{
	int t;
	cin >> t;

	while(t--)
	{
		int x;
		cin >> x;
		string s;
		cin >> s;
		std::vector<int> v;
		for(auto i: s){
			v.push_back(i - '0');
		}
		int p1 = 0;
		while(v.size() <= x && p1 < v.size() - 1){
			int num = v[p1];
			int start = p1 + 1;
			int end = v.size();
			num--;
			while(num--){
				for (int i = start; i < end; ++i)
				{
					v.push_back(v[i]);
				}
			}
			p1++;
		}

		dp[0] = s.size();
		int i = 1, ans;
		while(i <= x && i <= v.size()){
			dp[i] = (dp[i-1]
			dp[i] += (dp[i-1] - i)*(v[i-1] - 1));
			dp[i] %= 1000000007;
			ans = dp[i];
			i++;
		}

		cout << ans << endl;

	}
}


#include<iostream>
#include<bits/stdc++.h>
#define int long long

using namespace std;
int dp[1000010];
typedef pair<int, int> pi;

int32_t main()
{
	int t;
	cin >> t;
	memset(dp, 0, sizeof(dp));
	while(t--)
	{
		int x;
		cin >> x;
		string s;
		cin >> s;
		std::vector<int> v;
		for(auto i: s){
			v.push_back(i - '0');
		}
		int p1 = 0;
		while(v.size() <= x && p1 < v.size() - 1){
			int num = v[p1];
			int start = p1 + 1;
			int end = v.size();
			num--;
			while(num--){
				for (int i = start; i < end; ++i)
				{
					v.push_back(v[i]);
				}
			}
			p1++;
		}
		dp[0] = s.size();
		int i = 1;
		while(i <= x){
			dp[i] = (dp[i-1] + (dp[i-1] - i)*(v[i-1] - 1));
			i++;
		}

		cout << dp[x] % 1000000007<< endl;
	}
}


#include<iostream>
#include<bits/stdc++.h>
#define int long long

using namespace std;
int dp[1000001];
typedef pair<int, int> pi;

int32_t main()
{
	int t;
	cin >> t;

	while(t--)
	{
		int x;
		cin >> x;
		string s;
		cin >> s;
		std::vector<int> v;
		for(auto i: s){
			v.push_back(i - '0');
		}
		int p1 = 0;
		while(v.size() <= x){
			int num = v[p1];
			int start = p1 + 1;
			int end = v.size();
			num--;
			while(num--){
				for (int i = start; i < end; ++i)
				{
					v.push_back(v[i]);
				}
			}
			p1++;
		}

		dp[0] = s.size();
		int i = 1;
		while(i <= x){
			dp[i] = (dp[i-1] + (dp[i-1] - i)*(v[i-1] - 1)) % 1000000007;
			i++;
		}

		cout << dp[x] << endl;

	}
}


#include<iostream>
#include<bits/stdc++.h>
#define int long long

using namespace std;
int dp[1000010];
typedef pair<int, int> pi;

int32_t main()
{
	int t;
	cin >> t;
	memset(dp, 0, sizeof(dp));
	while(t--)
	{
		int x;
		cin >> x;
		string s;
		cin >> s;
		std::vector<int> v;
		for(auto i: s){
			v.push_back(i - '0');
		}
		int p1 = 0;
		while(v.size() <= x && p1 < v.size() - 1){
			int num = v[p1];
			int start = p1 + 1;
			int end = v.size();
			num--;
			while(num--){
				for (int i = start; i < end; ++i)
				{
					v.push_back(v[i]);
				}
			}
			p1++;
		}
		dp[0] = s.size();
		int i = 1;
		while(i <= x){
			dp[i] = (dp[i-1] + (dp[i-1] - i)*(v[i-1] - 1));
			if(dp[i] % 1000000007 > x){
				dp[i] %= 1000000007;
			}
			i++;
		}

		cout << dp[x] % 1000000007<< endl;
	}
}


#include<iostream>
#include<bits/stdc++.h>
#define int long long

using namespace std;
int dp[1000001];
typedef pair<int, int> pi;

int32_t main()
{
	int t;
	cin >> t;

	while(t--)
	{
		int x;
		cin >> x;
		string s;
		cin >> s;
		std::vector<int> v;
		for(auto i: s){
			v.push_back(i - '0');
		}
		int p1 = 0;
		while(v.size() <= x && p1 < v.size() - 1){
			int num = v[p1];
			int start = p1 + 1;
			int end = v.size();
			num--;
			while(num--){
				for (int i = start; i < end; ++i)
				{
					v.push_back(v[i]);
				}
			}
			p1++;
		}

		dp[0] = s.size();
		int i = 1;
		while(i <= x){
			dp[i] = (dp[i-1] + (dp[i-1] - i)*(v[i-1] - 1)) % 1000000007;
			i++;
		}

		cout << dp[x] << endl;

	}
}


#include<iostream>
#include<bits/stdc++.h>
#define int long long

using namespace std;
int dp[1000001];
typedef pair<int, int> pi;

int32_t main()
{
	int t;
	cin >> t;

	while(t--)
	{
		int x;
		cin >> x;
		string s;
		cin >> s;
		std::vector<int> v;
		for(auto i: s){
			v.push_back(i - '0');
		}
		int p1 = 0;
		while(v.size() <= x && p1 < v.size() - 1){
			int num = v[p1];
			int start = p1 + 1;
			int end = v.size();
			num--;
			while(num--){
				for (int i = start; i < end; ++i)
				{
					v.push_back(v[i]);
				}
			}
			p1++;
		}

		dp[0] = s.size();
		int i = 1, ans;
		while(i <= x && i <= v.size()){
			dp[i] = dp[i-1];
			dp[i] += ((dp[i-1] - i)%1000000007)*(v[i-1] - 1);
			dp[i] %= 1000000007;
			ans = dp[i];
			i++;
		}

		cout << ans << endl;

	}
}


/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ

 */
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , k ;
void make(string& t){
	for(ll i=0; ; i++){
		if(t.length()>=k)break;
		if(t[i]=='1')continue;
		string a , b ;
		b=t.substr(i+1);
		ll tm=t[i]-'1';
		for(ll j=0;j<tm ; j++){
			t+=b ;
			if(t.length()>=k)break;
		}
		if(t.length()>=k)break;
	}
}
void solve(){
	scanf("%lld", &k);
	char s[501];
	string  t;
	scanf("%s" , s) ; n = strlen(s);
	t=s;
	make(t);
	// cerr<<t<<endl;
	for(ll i=0;i<k ; i++){
		ll tm=t[i]-'0';
		n=((tm%mod*(n-i-1)%mod)%mod + (i+1)%mod +mod)%mod;
		n%=mod;
		// cerr<<n<<endl;
	}
	printf("%lld\n" , n);
}

int main(){
	//mahakal();
	fast;
	ll t =1 ;
	scanf("%lld",&t);
	while(t--)solve();
	// cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}


/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ

 */
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , k ;
void make(string& t){
	for(ll i=0; ; i++){
		if(t.length()>=k)break;
		if(t[i]=='1')continue;
		string a , b ;
		b=t.substr(i+1);
		t=t.substr(0 , i+1);
		// t.clear(); t= a;
		ll tm=t[i]-'0';
		for(ll j=0;j<tm ; j++){
			t+=b ;
			if(t.length()>=k)break;
		}
		if(t.length()>=k)break;
	}
}
void solve(){
	scanf("%lld", &k);
	char s[501];
	string  t;
	scanf("%s" , s) ; n = strlen(s);
	t=s;
	make(t);
	// cerr<<t<<endl;
	for(ll i=0;i<k ; i++){
		ll tm=t[i]-'0';
		n=((tm%mod*(n-i-1)%mod)%mod + (i+1)%mod +mod)%mod;
		n%=mod;
		// cerr<<n<<endl;
	}
	printf("%lld\n" , n);
}

int main(){
	mahakal();
	fast;
	ll t =1 ;
	scanf("%lld",&t);
	while(t--)solve();
	// cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}


/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ

 */
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , k ;
void make(string& t){
	for(ll i=0; ; i++){
		string a , b ;
		a=t.substr(0 , i+1);
		b=t.substr(i+1);
		t.clear(); t= a;
		ll tm=t[i]-'0';
		for(ll j=0;j<tm ; j++){
			t+=b ;
			if(t.length()>=k)break;
		}
		if(t.length()>=k)break;
	}
}
void solve(){
	cin>> k ;
	string s  , t;
	cin>> s ; n = s.length();
	t=s;
	make(t);
	// cerr<<t<<endl;
	for(ll i=0;i<k ; i++){
		ll tm=t[i]-'0';
		n=((tm%mod*(n-i-1)%mod)%mod + (i+1)%mod)%mod;
		// cerr<<n<<endl;
	}
	cout<<n <<endl;

}

int main(){
	mahakal();
	fast;
	ll t =1 ;
	cin>> t ;
	while(t--)solve();
	cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}


/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ

 */
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , k ;
void make(string& t){
	for(ll i=0; ; i++){
		if(t.length()>=k)break;
		if(t[i]=='1')continue;
		string a , b ;
		b=t.substr(i+1);
		t=t.substr(0 , i+1);
		// t.clear(); t= a;
		ll tm=t[i]-'0';
		for(ll j=0;j<tm ; j++){
			t+=b ;
			if(t.length()>=k)break;
		}
		if(t.length()>=k)break;
	}
}
void solve(){
	scanf("%lld", &k);
	char s[501];
	string  t;
	scanf("%s" , s) ; n = strlen(s);
	t=s;
	make(t);
	// cerr<<t<<endl;
	for(ll i=0;i<k ; i++){
		ll tm=t[i]-'0';
		n=((tm%mod*(n-i-1)%mod)%mod + (i+1)%mod +mod)%mod;
		n%=mod;
		// cerr<<n<<endl;
	}
	printf("%lld\n" , n);
}

int main(){
//	mahakal();
	fast;
	ll t =1 ;
	scanf("%lld",&t);
	while(t--)solve();
	// cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}


/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ

 */
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , k ;
void make(string& t){
	for(ll i=0; ; i++){
		if(t.length()>=k)break;
		if(t[i]=='1')continue;
		string a , b ;
		a=t.substr(0 , i+1);
		b=t.substr(i+1);
		t.clear(); t= a;
		ll tm=t[i]-'0';
		for(ll j=0;j<tm ; j++){
			t+=b ;
			if(t.length()>=k)break;
		}
		if(t.length()>=k)break;
	}
}
void solve(){
	scanf("%lld", &k);
	char s[501];
	string  t;
	scanf("%s" , s) ; n = strlen(s);
	t=s;
	make(t);
	// cerr<<t<<endl;
	for(ll i=0;i<k ; i++){
		ll tm=t[i]-'0';
		n=((tm%mod*(n-i-1)%mod)%mod + (i+1)%mod +mod)%mod;
		n%=mod;
		// cerr<<n<<endl;
	}
	printf("%lld\n" , n);
}

int main(){
	//mahakal();
	fast;
	ll t =1 ;
	scanf("%lld",&t);
	while(t--)solve();
	// cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}


/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ

 */
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , k ;
void make(string& t){
	for(ll i=0; ; i++){
		string a , b ;
		a=t.substr(0 , i+1);
		b=t.substr(i+1);
		t.clear(); t= a;
		ll tm=t[i]-'0';
		for(ll j=0;j<tm ; j++){
			t+=b ;
			if(t.length()>=k)break;
		}
		if(t.length()>=k)break;
	}
}
void solve(){
	scanf("%lld", &k);
	char s[501];
	string  t;
	scanf("%s" , s) ; n = strlen(s);
	t=s;
	make(t);
	// cerr<<t<<endl;
	for(ll i=0;i<k ; i++){
		ll tm=t[i]-'0';
		n=((tm%mod*(n-i-1)%mod)%mod + (i+1)%mod +mod)%mod;
		n%=mod;
		// cerr<<n<<endl;
	}
	printf("%lld\n" , n);
}

int main(){
// 	mahakal();
	fast;
	ll t =1 ;
	scanf("%lld",&t);
	while(t--)solve();
	// cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}


/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂

                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ

 */
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n , k ;
void make(string& t){
	for(ll i=0; ; i++){
		string a , b ;
		a=t.substr(0 , i+1);
		b=t.substr(i+1);
		t.clear(); t= a;
		ll tm=t[i]-'0';
		for(ll j=0;j<tm ; j++){
			t+=b ;
			if(t.length()>=k)break;
		}
		if(t.length()>=k)break;
	}
}
void solve(){
	cin>> k ;
	string s  , t;
	cin>> s ; n = s.length();
	t=s;
	make(t);
	// cerr<<t<<endl;
	for(ll i=0;i<k ; i++){
		ll tm=t[i]-'0';
		n=((tm%mod*(n-i-1)%mod)%mod + (i+1)%mod +mod)%mod;
		n%=mod;
		// cerr<<n<<endl;
	}
	cout<<n <<endl;

}

int main(){
	mahakal();
	fast;
	ll t =1 ;
	cin>> t ;
	while(t--)solve();
	cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
	return 0;
}


#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#include <iostream>
#define ll long long int
#define all(x) x.begin(),x.end()

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define v vector<long long int>
#define vv vector< int>
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int ,long long int>
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 1111LL
# define cout1(x) cout<<x<<"\n";
# define  deb(x) cout<<#x<<" "<<x<<"\n";
#define  vii vector<pa>;
using namespace std;
# define MAXN 1000000ll

// template<typename... T>
// void read(T&... args){
//     ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
//     ((cout<<args<<"\n"), ...);
// }

v visited(N);
vector<ll> ans={-1};
v level(N);
v ind(N);
ll sz[N];

// void dfs(ll node, ll par){

//     visited[node]=1;
//     if (node==1)level[1]=0;
//     else level[node] = level[par]+1;
//     ans.pb(node);
//     for(auto x:graph[node]){
//         if (!visited[x]){
//             dfs(x,node);
//             sz[node]+=sz[x];

//         }

//     }
//      ++sz[node];

// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
//     cout<<ans<<" "<<x<<endl;
//     if (cnt[ans%x]==0)return ans;
//     else if (cnt[ans%x==1] && ans>x)return ans;
//     else{
//         cnt[ans%x]-=1;
//         cnt[ans]+=1;
//         answer(ans+1,x);
//     }

// }
ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (ll i=2; i<MAXN; i++)

        spf[i] = i;

    for (ll i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (ll i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (ll j=i*i; j<MAXN; j+=i)

                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}

ll power(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

auto primeFactors(ll n)
{   map<ll,ll> fact;
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        fact[2]+=1;
        n = n/2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {

        while (n % i == 0)
        {
            fact[i]+=1;
            n = n/i;
        }
    }
    if (n > 2)
        fact[n]+=1;
    return fact;
}
auto getFactorization(int x)
{
    map<ll,ll> ret;;
    while (x != 1)
    {
        ret[spf[x]]+=1;
        x = x / spf[x];
    }
    return ret;
}

char _s[N];
ll solve() {
    int x;
    scanf("%d%s", &x, _s);
    ll ls = strlen(_s);
    vector<char> s(_s, _s + ls);
    for (int i = 1; i <= x; i++) {
        int nn = s[i - 1] - '1';
        if (s.size() < x) {
            vector<char> sub(s.begin() + i, s.end());
            for (int it = 0; it < nn; it++) s.insert(s.end(), sub.begin(), sub.end());
        }
        ls = (ls + (ls - i) * nn) % mod;
    }
    return ls;
}

int main() {
    int z;
    for (scanf("%d", &z); z--; printf("%lld\n", (solve() % mod + mod) % mod));
}


#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#include <iostream>
#define ll long long int
#define all(x) x.begin(),x.end()

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define v vector<long long int>
#define vv vector< int>
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int ,long long int>
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 100005LL
# define cout1(x) cout<<x<<"\n";
# define  deb(x) cout<<#x<<" "<<x<<"\n";
#define  vii vector<pa>;
using namespace std;
# define MAXN 1000000ll

// template<typename... T>
// void read(T&... args){
//     ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
//     ((cout<<args<<"\n"), ...);
// }

v visited(N);
vector<ll> ans={-1};
v level(N);
v ind(N);
ll sz[N];

// void dfs(ll node, ll par){

//     visited[node]=1;
//     if (node==1)level[1]=0;
//     else level[node] = level[par]+1;
//     ans.pb(node);
//     for(auto x:graph[node]){
//         if (!visited[x]){
//             dfs(x,node);
//             sz[node]+=sz[x];

//         }

//     }
//      ++sz[node];

// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
//     cout<<ans<<" "<<x<<endl;
//     if (cnt[ans%x]==0)return ans;
//     else if (cnt[ans%x==1] && ans>x)return ans;
//     else{
//         cnt[ans%x]-=1;
//         cnt[ans]+=1;
//         answer(ans+1,x);
//     }

// }
ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (ll i=2; i<MAXN; i++)

        spf[i] = i;

    for (ll i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (ll i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (ll j=i*i; j<MAXN; j+=i)

                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}

ll power(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

auto primeFactors(ll n)
{   map<ll,ll> fact;
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        fact[2]+=1;
        n = n/2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {

        while (n % i == 0)
        {
            fact[i]+=1;
            n = n/i;
        }
    }
    if (n > 2)
        fact[n]+=1;
    return fact;
}
auto getFactorization(int x)
{
    map<ll,ll> ret;;
    while (x != 1)
    {
        ret[spf[x]]+=1;
        x = x / spf[x];
    }
    return ret;
}

char _s[N];

ll solve(){
    int x;
    scanf("%d%s", &x, _s);
    ll ls = strlen(_s);
    vector<char> s(_s, _s + ls);
    for (int i = 1; i <= x; i++) {
        int dd = s[i - 1] - '1';
        if (s.size() < x) {
            vector<char> sub(s.begin() + i, s.end());
            for (int it = 0; it < dd; it++) s.insert(s.end(), sub.begin(), sub.end());
        }
        ls = (ls + (ls - i) * dd) % mod;
    }
    cout1(ls%mod);
}

int main(){
    fastio;
    ll t;
    cin>>t;

    while(t--)solve();
}


#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#include <iostream>
#define ll long long int
#define all(x) x.begin(),x.end()

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define v vector<long long int>
#define vv vector< int>
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int ,long long int>
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 100005LL
# define cout1(x) cout<<x<<"\n";
# define  deb(x) cout<<#x<<" "<<x<<"\n";
#define  vii vector<pa>;
using namespace std;
# define MAXN 1000000ll

// template<typename... T>
// void read(T&... args){
//     ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
//     ((cout<<args<<"\n"), ...);
// }

v visited(N);
vector<ll> ans={-1};
v level(N);
v ind(N);
ll sz[N];

// void dfs(ll node, ll par){

//     visited[node]=1;
//     if (node==1)level[1]=0;
//     else level[node] = level[par]+1;
//     ans.pb(node);
//     for(auto x:graph[node]){
//         if (!visited[x]){
//             dfs(x,node);
//             sz[node]+=sz[x];

//         }

//     }
//      ++sz[node];

// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
//     cout<<ans<<" "<<x<<endl;
//     if (cnt[ans%x]==0)return ans;
//     else if (cnt[ans%x==1] && ans>x)return ans;
//     else{
//         cnt[ans%x]-=1;
//         cnt[ans]+=1;
//         answer(ans+1,x);
//     }

// }
ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (ll i=2; i<MAXN; i++)

        spf[i] = i;

    for (ll i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (ll i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (ll j=i*i; j<MAXN; j+=i)

                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}

ll power(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

auto primeFactors(ll n)
{   map<ll,ll> fact;
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        fact[2]+=1;
        n = n/2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {

        while (n % i == 0)
        {
            fact[i]+=1;
            n = n/i;
        }
    }
    if (n > 2)
        fact[n]+=1;
    return fact;
}
auto getFactorization(int x)
{
    map<ll,ll> ret;;
    while (x != 1)
    {
        ret[spf[x]]+=1;
        x = x / spf[x];
    }
    return ret;
}

ll solve(){
    ll n;string s;
    cin>>n>>s;
    vector<char> arr;
    f(i,s.length())arr.pb(s[i]);
    ll ans=s.length();
    ll i=0;
    f(i,n){
        vector<char> temp(s.begin()+i+1,s.end());
        ans+=(s[i]-'0'-1)%mod*(ans-i-1)%mod;
        // deb(ans);
        // ans=ans%mod;
        if (s.length()<n){
            f(z,s[i]-'0'-1)
            s.insert(s.end(),temp.begin(),temp.end());
        }
        // deb(s.length());

    }
    cout1(ans%mod);

}

int main(){
    fastio;
    ll t;
    cin>>t;

    while(t--)solve();
}


#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#include <iostream>
#define ll long long int
#define all(x) x.begin(),x.end()

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define v vector<long long int>
#define vv vector< int>
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int ,long long int>
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 100005LL
# define cout1(x) cout<<x<<"\n";
# define  deb(x) cout<<#x<<" "<<x<<"\n";
#define  vii vector<pa>;
using namespace std;
# define MAXN 1000000ll

// template<typename... T>
// void read(T&... args){
//     ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
//     ((cout<<args<<"\n"), ...);
// }

v visited(N);
vector<ll> ans={-1};
v level(N);
v ind(N);
ll sz[N];

// void dfs(ll node, ll par){

//     visited[node]=1;
//     if (node==1)level[1]=0;
//     else level[node] = level[par]+1;
//     ans.pb(node);
//     for(auto x:graph[node]){
//         if (!visited[x]){
//             dfs(x,node);
//             sz[node]+=sz[x];

//         }

//     }
//      ++sz[node];

// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
//     cout<<ans<<" "<<x<<endl;
//     if (cnt[ans%x]==0)return ans;
//     else if (cnt[ans%x==1] && ans>x)return ans;
//     else{
//         cnt[ans%x]-=1;
//         cnt[ans]+=1;
//         answer(ans+1,x);
//     }

// }
ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (ll i=2; i<MAXN; i++)

        spf[i] = i;

    for (ll i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (ll i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (ll j=i*i; j<MAXN; j+=i)

                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}

ll power(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

auto primeFactors(ll n)
{   map<ll,ll> fact;
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        fact[2]+=1;
        n = n/2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {

        while (n % i == 0)
        {
            fact[i]+=1;
            n = n/i;
        }
    }
    if (n > 2)
        fact[n]+=1;
    return fact;
}
auto getFactorization(int x)
{
    map<ll,ll> ret;;
    while (x != 1)
    {
        ret[spf[x]]+=1;
        x = x / spf[x];
    }
    return ret;
}

ll solve(){
    ll n;string s;
    cin>>n>>s;
    vector<char> arr;
    f(i,s.length())arr.pb(s[i]);
    ll ans=s.length();
    ll i=0;
    f(i,n){
        vector<char> temp(arr.begin()+i+1,arr.end());
        ans+=(arr[i]-'0'-1)%mod*(ans-i-1)%mod;
        // deb(ans);
        // ans=ans%mod;
        if (arr.size()<n){
            f(z,arr[i]-'0'-1)
            arr.insert(arr.end(),temp.begin(),temp.end());
        }
        // deb(s.length());

    }
    cout1(ans%mod);

}

int main(){
    fastio;
    ll t;
    cin>>t;

    while(t--)solve();
}


#include <bits/stdc++.h>
#include<numeric>
#include<cstdlib>
#include <iostream>
#define ll long long int
#define all(x) x.begin(),x.end()

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define v vector<long long int>
#define vv vector< int>
#define gcd(m,n) __gcd(m,n)
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define itr vector<long long int>::iterator
#define pa pair<long long int ,long long int>
#define f(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,n) for (ll i=a ; i<n ;i+=1)
#define fe(d,e) for(auto d:e)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
# define N 100005LL
# define cout1(x) cout<<x<<"\n";
# define  deb(x) cout<<#x<<" "<<x<<"\n";
#define  vii vector<pa>;
using namespace std;
# define MAXN 1000000ll

// template<typename... T>
// void read(T&... args){
//     ((cin>>args), ...);
// }
// template<typename... T>
// void write(T... args){
//     ((cout<<args<<"\n"), ...);
// }

v visited(N);
vector<ll> ans={-1};
v level(N);
v ind(N);
ll sz[N];

// void dfs(ll node, ll par){

//     visited[node]=1;
//     if (node==1)level[1]=0;
//     else level[node] = level[par]+1;
//     ans.pb(node);
//     for(auto x:graph[node]){
//         if (!visited[x]){
//             dfs(x,node);
//             sz[node]+=sz[x];

//         }

//     }
//      ++sz[node];

// }
// map<ll,ll> cnt;
// ll answer(ll ans,ll x){
//     cout<<ans<<" "<<x<<endl;
//     if (cnt[ans%x]==0)return ans;
//     else if (cnt[ans%x==1] && ans>x)return ans;
//     else{
//         cnt[ans%x]-=1;
//         cnt[ans]+=1;
//         answer(ans+1,x);
//     }

// }
ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (ll i=2; i<MAXN; i++)

        spf[i] = i;

    for (ll i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (ll i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (ll j=i*i; j<MAXN; j+=i)

                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}

ll power(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

auto primeFactors(ll n)
{   map<ll,ll> fact;
    // Print the number of 2s that divide n
    while (n % 2 == 0)
    {
        fact[2]+=1;
        n = n/2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {

        while (n % i == 0)
        {
            fact[i]+=1;
            n = n/i;
        }
    }
    if (n > 2)
        fact[n]+=1;
    return fact;
}
auto getFactorization(int x)
{
    map<ll,ll> ret;;
    while (x != 1)
    {
        ret[spf[x]]+=1;
        x = x / spf[x];
    }
    return ret;
}

char _s[N];

void solve(){
    int x;
    scanf("%d%s", &x, _s);
    ll ls = strlen(_s);
    vector<char> s(_s, _s + ls);
    for (int i = 1; i <= x; i++) {
        int dd = s[i - 1] - '1';
        if (s.size() < x) {
            vector<char> sub(s.begin() + i, s.end());
            for (int it = 0; it < dd; it++) s.insert(s.end(), sub.begin(), sub.end());
        }
        ls = (ls + (ls - i) * dd) % mod;
    }
    cout1(ls%mod);
}

int main(){
    fastio;
    ll t;
    cin>>t;

    while(t--)solve();
}


#include <bits/stdc++.h>
#include <bitset>
#include <chrono>
#include <iomanip>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
#define prq priority_queue<ll>;

ll MOD=1000000007;
#define PI 3.1415926535897932384626433832795
#define llMAX 1000000000000000008
#define llMIN -1000000000000000008

#define forx(i,j,n) for(int i=j;i<n;i++)
#define fory(i,j,n) for(int i=j;i>=n;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false)
#define testcase int t; cin>>t
#define MEM(xx,yy) memset(xx,yy,sizeof(xx))
#define vbs(xx,x) binary_search(all(xx),x)
#define vlb(xx,x) lower_bound(all(xx),x)
#define vub(xx,x) upper_bound(all(xx),x)

#define inpi(xx) scanf("%d",&xx)
#define inpl(xx) scanf("%lld",&xx)
#define inpc(xx) scanf("%c",&xx)
#define inps(xx) scanf("%s",&xx)
#define pri(xx) printf("%d",xx)
#define prl(xx) printf("%lld",xx)
#define prls(xx) printf("%lld ",xx)
#define prle(xx) printf("%lld\n",xx)
#define prc(xx) printf("%c",xx)
#define prs printf(" ")
#define pre printf("\n")
#define flush fflush(stdout)

ll mul(ll mul_1,ll mul_2){ ll mul_t=((mul_1%MOD)*(mul_2%MOD)+MOD)%MOD; return mul_t; }
ll mul3(ll mul_1,ll mul_2,ll mul_3){ ll mul_t=mul(mul(mul_1,mul_2),mul_3)%MOD; return mul_t; }
ll add(ll add_1,ll add_2){ ll add_t=((add_1%MOD)+(add_2%MOD)+MOD+MOD)%MOD; return add_t; }
ll sub(ll sub_1,ll sub_2){ ll sub_r=1e15; ll sub_t=(((sub_1+sub_r)%MOD)-((sub_2+sub_r)%MOD)+sub_r)%MOD; return sub_t; }
ll power(ll x,ll y,ll p){ ll res=1; x=x%p; while(y>0){ if(y&1) res=(res*x)%p; y=y/2; x=(x*x)%p; } return res; }
ll gcd(ll num1,ll num2){ return (num2?gcd(num2,num1%num2):num1); }
ll lcm(ll num1,ll num2){ return 1LL*((num1*num2)/__gcd(num1,num2)); }
ll countbit(ll num){ return 1LL*(__builtin_popcountll(num)); }
ll setbit(ll num, ll kk){ return 1LL*(num|(1LL<<kk)); }
ll unsetbit(ll num, ll kk){ return 1LL*(num&~(1LL<<kk)); }
ll invertbit(ll num, ll kk){ return 1LL*(num^(1LL<<kk)); }
bool kthbit(ll num, ll kk){ return num&(1LL<<kk); }
ll zerotrail(ll num){ return 1LL*(__builtin_ctzll(num)); }
ll zerobegin(ll num){ return 1LL*(__builtin_clzll(num)); }

clock_t tim;
void showtime(){ tim=clock()-tim; cout<<" ===> "<<(ld)tim/CLOCKS_PER_SEC<<" seconds\n"; }

ll prime[1000005];
void sieve(){ //spf
    forx(i,0,1000005) prime[i]=i;
    for(ll p=2; 1LL*p*p<1000005; p++){ if(prime[p]==p) { for(ll i=1LL*p*p; i<1000005; i+=p) if(prime[i]==i) prime[i]=p; } }
    return;
}
bool isPrime(ll pri){
    if(pri==1||pri==0) return 0;
    if(prime[pri]==pri) return 1;
    return 0;
}
vl alldiv(ll num){
    vl prDiv; for(ll i=1; 1LL*i*i<=num; i++){ if(num%i==0){ prDiv.pb(i); if(i!=(num/i)) prDiv.pb(num/i); } }
    sort(all(prDiv)); return prDiv;
}
vl prdiv(ll num){
    vl prDiv; while(num!=1){ prDiv.pb(prime[num]); ll prtemp=prime[num]; while(num%prtemp==0) num/=prtemp; }
    return prDiv;
}

int main() {
    fastio; //tim=clock();
    testcase;
    //ll t=1;
    forx(T,1,1+t){
        ll x,e=0;
        cin>>x;
        ll dp[x+2];
        string str;
        cin>>str;
        vl c;
        ll a=str[0]-'0';
        ll n=str.size();
        dp[0]=n;
        forx(i,0,n) c.pb(str[i]-'0');
        e=n;
        forx(i,1,x+2){
            dp[i]=(dp[i-1]+((c[i-1]-1ll)*(dp[i-1]-(ll)i))%MOD)%MOD;
            if(e<x+2){
                ll m=e;
                e=0;
                forx(ii,1,c[i-1]){
                    ll j=i;
                    while(j<m){
                        c.pb(c[j]);
                        j++; e++;
                        if(m+e==x+2) break;
                    }
                }
                e=m+e;
            }
        }
        cout<<(dp[x]+MOD)%MOD<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>
#include <bitset>
#include <chrono>
#include <iomanip>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
#define prq priority_queue<ll>;

ll MOD=1000000007;
#define PI 3.1415926535897932384626433832795
#define llMAX 1000000000000000008
#define llMIN -1000000000000000008

#define forx(i,j,n) for(int i=j;i<n;i++)
#define fory(i,j,n) for(int i=j;i>=n;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false)
#define testcase int t; cin>>t
#define MEM(xx,yy) memset(xx,yy,sizeof(xx))
#define vbs(xx,x) binary_search(all(xx),x)
#define vlb(xx,x) lower_bound(all(xx),x)
#define vub(xx,x) upper_bound(all(xx),x)

#define inpi(xx) scanf("%d",&xx)
#define inpl(xx) scanf("%lld",&xx)
#define inpc(xx) scanf("%c",&xx)
#define inps(xx) scanf("%s",&xx)
#define pri(xx) printf("%d",xx)
#define prl(xx) printf("%lld",xx)
#define prls(xx) printf("%lld ",xx)
#define prle(xx) printf("%lld\n",xx)
#define prc(xx) printf("%c",xx)
#define prs printf(" ")
#define pre printf("\n")
#define flush fflush(stdout)

ll mul(ll mul_1,ll mul_2){ ll mul_t=((mul_1%MOD)*(mul_2%MOD)+MOD)%MOD; return mul_t; }
ll mul3(ll mul_1,ll mul_2,ll mul_3){ ll mul_t=mul(mul(mul_1,mul_2),mul_3)%MOD; return mul_t; }
ll add(ll add_1,ll add_2){ ll add_t=((add_1%MOD)+(add_2%MOD)+MOD+MOD)%MOD; return add_t; }
ll sub(ll sub_1,ll sub_2){ ll sub_r=1e15; ll sub_t=(((sub_1+sub_r)%MOD)-((sub_2+sub_r)%MOD)+sub_r)%MOD; return sub_t; }
ll power(ll x,ll y,ll p){ ll res=1; x=x%p; while(y>0){ if(y&1) res=(res*x)%p; y=y/2; x=(x*x)%p; } return res; }
ll gcd(ll num1,ll num2){ return (num2?gcd(num2,num1%num2):num1); }
ll lcm(ll num1,ll num2){ return 1LL*((num1*num2)/__gcd(num1,num2)); }
ll countbit(ll num){ return 1LL*(__builtin_popcountll(num)); }
ll setbit(ll num, ll kk){ return 1LL*(num|(1LL<<kk)); }
ll unsetbit(ll num, ll kk){ return 1LL*(num&~(1LL<<kk)); }
ll invertbit(ll num, ll kk){ return 1LL*(num^(1LL<<kk)); }
bool kthbit(ll num, ll kk){ return num&(1LL<<kk); }
ll zerotrail(ll num){ return 1LL*(__builtin_ctzll(num)); }
ll zerobegin(ll num){ return 1LL*(__builtin_clzll(num)); }

clock_t tim;
void showtime(){ tim=clock()-tim; cout<<" ===> "<<(ld)tim/CLOCKS_PER_SEC<<" seconds\n"; }

ll prime[1000005];
void sieve(){ //spf
    forx(i,0,1000005) prime[i]=i;
    for(ll p=2; 1LL*p*p<1000005; p++){ if(prime[p]==p) { for(ll i=1LL*p*p; i<1000005; i+=p) if(prime[i]==i) prime[i]=p; } }
    return;
}
bool isPrime(ll pri){
    if(pri==1||pri==0) return 0;
    if(prime[pri]==pri) return 1;
    return 0;
}
vl alldiv(ll num){
    vl prDiv; for(ll i=1; 1LL*i*i<=num; i++){ if(num%i==0){ prDiv.pb(i); if(i!=(num/i)) prDiv.pb(num/i); } }
    sort(all(prDiv)); return prDiv;
}
vl prdiv(ll num){
    vl prDiv; while(num!=1){ prDiv.pb(prime[num]); ll prtemp=prime[num]; while(num%prtemp==0) num/=prtemp; }
    return prDiv;
}

int main() {
    fastio; //tim=clock();
    testcase;
    //ll t=1;
    forx(T,1,1+t){
        ll x,e=0;
        cin>>x;
        ll dp[x+2];
        string str;
        cin>>str;
        vl c;
        ll a=str[0]-'0';
        ll n=str.size();
        dp[0]=n;
        forx(i,0,n) c.pb(str[i]-'0');
        forx(i,1,x+2){
            dp[i]=(dp[i-1]+((c[i-1]-1ll)*(dp[i-1]-(ll)i))%MOD)%MOD;
            if(c.size()<x+2){
                forx(ii,1,c[i-1]){
                    forx(j,i,dp[i-1]){
                        c.pb(c[j]);
                        if(c.size()==x+2) break;
                    }
                }
            }
        }
        cout<<dp[x]<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>
#include <bitset>
#include <chrono>
#include <iomanip>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
#define prq priority_queue<ll>;

ll MOD=1000000007;
#define PI 3.1415926535897932384626433832795
#define llMAX 1000000000000000008
#define llMIN -1000000000000000008

#define forx(i,j,n) for(int i=j;i<n;i++)
#define fory(i,j,n) for(int i=j;i>=n;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false)
#define testcase int t; cin>>t
#define MEM(xx,yy) memset(xx,yy,sizeof(xx))
#define vbs(xx,x) binary_search(all(xx),x)
#define vlb(xx,x) lower_bound(all(xx),x)
#define vub(xx,x) upper_bound(all(xx),x)

#define inpi(xx) scanf("%d",&xx)
#define inpl(xx) scanf("%lld",&xx)
#define inpc(xx) scanf("%c",&xx)
#define inps(xx) scanf("%s",&xx)
#define pri(xx) printf("%d",xx)
#define prl(xx) printf("%lld",xx)
#define prls(xx) printf("%lld ",xx)
#define prle(xx) printf("%lld\n",xx)
#define prc(xx) printf("%c",xx)
#define prs printf(" ")
#define pre printf("\n")
#define flush fflush(stdout)

ll mul(ll mul_1,ll mul_2){ ll mul_t=((mul_1%MOD)*(mul_2%MOD)+MOD)%MOD; return mul_t; }
ll mul3(ll mul_1,ll mul_2,ll mul_3){ ll mul_t=mul(mul(mul_1,mul_2),mul_3)%MOD; return mul_t; }
ll add(ll add_1,ll add_2){ ll add_t=((add_1%MOD)+(add_2%MOD)+MOD+MOD)%MOD; return add_t; }
ll sub(ll sub_1,ll sub_2){ ll sub_r=1e15; ll sub_t=(((sub_1+sub_r)%MOD)-((sub_2+sub_r)%MOD)+sub_r)%MOD; return sub_t; }
ll power(ll x,ll y,ll p){ ll res=1; x=x%p; while(y>0){ if(y&1) res=(res*x)%p; y=y/2; x=(x*x)%p; } return res; }
ll gcd(ll num1,ll num2){ return (num2?gcd(num2,num1%num2):num1); }
ll lcm(ll num1,ll num2){ return 1LL*((num1*num2)/__gcd(num1,num2)); }
ll countbit(ll num){ return 1LL*(__builtin_popcountll(num)); }
ll setbit(ll num, ll kk){ return 1LL*(num|(1LL<<kk)); }
ll unsetbit(ll num, ll kk){ return 1LL*(num&~(1LL<<kk)); }
ll invertbit(ll num, ll kk){ return 1LL*(num^(1LL<<kk)); }
bool kthbit(ll num, ll kk){ return num&(1LL<<kk); }
ll zerotrail(ll num){ return 1LL*(__builtin_ctzll(num)); }
ll zerobegin(ll num){ return 1LL*(__builtin_clzll(num)); }

clock_t tim;
void showtime(){ tim=clock()-tim; cout<<" ===> "<<(ld)tim/CLOCKS_PER_SEC<<" seconds\n"; }

ll prime[1000005];
void sieve(){ //spf
    forx(i,0,1000005) prime[i]=i;
    for(ll p=2; 1LL*p*p<1000005; p++){ if(prime[p]==p) { for(ll i=1LL*p*p; i<1000005; i+=p) if(prime[i]==i) prime[i]=p; } }
    return;
}
bool isPrime(ll pri){
    if(pri==1||pri==0) return 0;
    if(prime[pri]==pri) return 1;
    return 0;
}
vl alldiv(ll num){
    vl prDiv; for(ll i=1; 1LL*i*i<=num; i++){ if(num%i==0){ prDiv.pb(i); if(i!=(num/i)) prDiv.pb(num/i); } }
    sort(all(prDiv)); return prDiv;
}
vl prdiv(ll num){
    vl prDiv; while(num!=1){ prDiv.pb(prime[num]); ll prtemp=prime[num]; while(num%prtemp==0) num/=prtemp; }
    return prDiv;
}

int main() {
    fastio; //tim=clock();
    testcase;
    //ll t=1;
    forx(T,1,1+t){
        ll x,e=0;
        cin>>x;
        ll dp[x+1];
        string str;
        cin>>str;
        vl c;
        ll a=str[0]-'0';
        ll n=str.size();
        dp[0]=n;
        forx(i,0,n) c.pb(str[i]-'0');
        e=n;
        forx(i,1,x+1){
            dp[i]=(dp[i-1]+((c[i-1]-1ll)*(dp[i-1]-(ll)i))%MOD)%MOD;
            if(e<x+1){
                ll m=e;
                e=0;
                forx(ii,1,c[i-1]){
                    ll j=i;
                    while(j<m){
                        c.pb(c[j]);
                        j++; e++;
                        if(m+e==x+1) break;
                    }
                }
                e=m+e;
            }
        }
        //forx(i,0,e) cout<<c[i];
        cout<<(dp[x]+MOD)%MOD<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>
#include <bitset>
#include <chrono>
#include <iomanip>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
#define prq priority_queue<ll>;

ll MOD=1000000007;
#define PI 3.1415926535897932384626433832795
#define llMAX 1000000000000000008
#define llMIN -1000000000000000008

#define forx(i,j,n) for(int i=j;i<n;i++)
#define fory(i,j,n) for(int i=j;i>=n;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false)
#define testcase int t; cin>>t
#define MEM(xx,yy) memset(xx,yy,sizeof(xx))
#define vbs(xx,x) binary_search(all(xx),x)
#define vlb(xx,x) lower_bound(all(xx),x)
#define vub(xx,x) upper_bound(all(xx),x)

#define inpi(xx) scanf("%d",&xx)
#define inpl(xx) scanf("%lld",&xx)
#define inpc(xx) scanf("%c",&xx)
#define inps(xx) scanf("%s",&xx)
#define pri(xx) printf("%d",xx)
#define prl(xx) printf("%lld",xx)
#define prls(xx) printf("%lld ",xx)
#define prle(xx) printf("%lld\n",xx)
#define prc(xx) printf("%c",xx)
#define prs printf(" ")
#define pre printf("\n")
#define flush fflush(stdout)

ll mul(ll mul_1,ll mul_2){ ll mul_t=((mul_1%MOD)*(mul_2%MOD)+MOD)%MOD; return mul_t; }
ll mul3(ll mul_1,ll mul_2,ll mul_3){ ll mul_t=mul(mul(mul_1,mul_2),mul_3)%MOD; return mul_t; }
ll add(ll add_1,ll add_2){ ll add_t=((add_1%MOD)+(add_2%MOD)+MOD+MOD)%MOD; return add_t; }
ll sub(ll sub_1,ll sub_2){ ll sub_r=1e15; ll sub_t=(((sub_1+sub_r)%MOD)-((sub_2+sub_r)%MOD)+sub_r)%MOD; return sub_t; }
ll power(ll x,ll y,ll p){ ll res=1; x=x%p; while(y>0){ if(y&1) res=(res*x)%p; y=y/2; x=(x*x)%p; } return res; }
ll gcd(ll num1,ll num2){ return (num2?gcd(num2,num1%num2):num1); }
ll lcm(ll num1,ll num2){ return 1LL*((num1*num2)/__gcd(num1,num2)); }
ll countbit(ll num){ return 1LL*(__builtin_popcountll(num)); }
ll setbit(ll num, ll kk){ return 1LL*(num|(1LL<<kk)); }
ll unsetbit(ll num, ll kk){ return 1LL*(num&~(1LL<<kk)); }
ll invertbit(ll num, ll kk){ return 1LL*(num^(1LL<<kk)); }
bool kthbit(ll num, ll kk){ return num&(1LL<<kk); }
ll zerotrail(ll num){ return 1LL*(__builtin_ctzll(num)); }
ll zerobegin(ll num){ return 1LL*(__builtin_clzll(num)); }

clock_t tim;
void showtime(){ tim=clock()-tim; cout<<" ===> "<<(ld)tim/CLOCKS_PER_SEC<<" seconds\n"; }

ll prime[1000005];
void sieve(){ //spf
    forx(i,0,1000005) prime[i]=i;
    for(ll p=2; 1LL*p*p<1000005; p++){ if(prime[p]==p) { for(ll i=1LL*p*p; i<1000005; i+=p) if(prime[i]==i) prime[i]=p; } }
    return;
}
bool isPrime(ll pri){
    if(pri==1||pri==0) return 0;
    if(prime[pri]==pri) return 1;
    return 0;
}
vl alldiv(ll num){
    vl prDiv; for(ll i=1; 1LL*i*i<=num; i++){ if(num%i==0){ prDiv.pb(i); if(i!=(num/i)) prDiv.pb(num/i); } }
    sort(all(prDiv)); return prDiv;
}
vl prdiv(ll num){
    vl prDiv; while(num!=1){ prDiv.pb(prime[num]); ll prtemp=prime[num]; while(num%prtemp==0) num/=prtemp; }
    return prDiv;
}

int main() {
    fastio; //tim=clock();
    testcase;
    //ll t=1;
    forx(T,1,1+t){
        ll x,e=0;
        cin>>x;
        ll dp[x+2];
        string str;
        cin>>str;
        vl c;
        ll a=str[0]-'0';
        ll n=str.size();
        dp[0]=n;
        forx(i,0,n) c.pb(str[i]-'0');
        forx(i,1,x+2){
            dp[i]=(dp[i-1]+((c[i-1]-1ll)*(dp[i-1]-(ll)i))%MOD)%MOD;
            if(c.size()<x+2){
                forx(ii,1,c[i-1]){
                    forx(j,i,dp[i-1]){
                        c.pb(c[j]);
                        if(c.size()==x+2) break;
                    }
                }
            }
        }
        cout<<(dp[x]+MOD)%MOD<<"\n";
    }
	return 0;
}


#include <bits/stdc++.h>
#include <bitset>
#include <chrono>
#include <iomanip>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
#define prq priority_queue<ll>;

ll MOD=1000000007;
#define PI 3.1415926535897932384626433832795
#define llMAX 1000000000000000008
#define llMIN -1000000000000000008

#define forx(i,j,n) for(int i=j;i<n;i++)
#define fory(i,j,n) for(int i=j;i>=n;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define fastio ios_base::sync_with_stdio(false)
#define testcase int t; cin>>t
#define MEM(xx,yy) memset(xx,yy,sizeof(xx))
#define vbs(xx,x) binary_search(all(xx),x)
#define vlb(xx,x) lower_bound(all(xx),x)
#define vub(xx,x) upper_bound(all(xx),x)

#define inpi(xx) scanf("%d",&xx)
#define inpl(xx) scanf("%lld",&xx)
#define inpc(xx) scanf("%c",&xx)
#define inps(xx) scanf("%s",&xx)
#define pri(xx) printf("%d",xx)
#define prl(xx) printf("%lld",xx)
#define prls(xx) printf("%lld ",xx)
#define prle(xx) printf("%lld\n",xx)
#define prc(xx) printf("%c",xx)
#define prs printf(" ")
#define pre printf("\n")
#define flush fflush(stdout)

ll mul(ll mul_1,ll mul_2){ ll mul_t=((mul_1%MOD)*(mul_2%MOD)+MOD)%MOD; return mul_t; }
ll mul3(ll mul_1,ll mul_2,ll mul_3){ ll mul_t=mul(mul(mul_1,mul_2),mul_3)%MOD; return mul_t; }
ll add(ll add_1,ll add_2){ ll add_t=((add_1%MOD)+(add_2%MOD)+MOD+MOD)%MOD; return add_t; }
ll sub(ll sub_1,ll sub_2){ ll sub_r=1e15; ll sub_t=(((sub_1+sub_r)%MOD)-((sub_2+sub_r)%MOD)+sub_r)%MOD; return sub_t; }
ll power(ll x,ll y,ll p){ ll res=1; x=x%p; while(y>0){ if(y&1) res=(res*x)%p; y=y/2; x=(x*x)%p; } return res; }
ll gcd(ll num1,ll num2){ return (num2?gcd(num2,num1%num2):num1); }
ll lcm(ll num1,ll num2){ return 1LL*((num1*num2)/__gcd(num1,num2)); }
ll countbit(ll num){ return 1LL*(__builtin_popcountll(num)); }
ll setbit(ll num, ll kk){ return 1LL*(num|(1LL<<kk)); }
ll unsetbit(ll num, ll kk){ return 1LL*(num&~(1LL<<kk)); }
ll invertbit(ll num, ll kk){ return 1LL*(num^(1LL<<kk)); }
bool kthbit(ll num, ll kk){ return num&(1LL<<kk); }
ll zerotrail(ll num){ return 1LL*(__builtin_ctzll(num)); }
ll zerobegin(ll num){ return 1LL*(__builtin_clzll(num)); }

clock_t tim;
void showtime(){ tim=clock()-tim; cout<<" ===> "<<(ld)tim/CLOCKS_PER_SEC<<" seconds\n"; }

ll prime[1000005];
void sieve(){ //spf
    forx(i,0,1000005) prime[i]=i;
    for(ll p=2; 1LL*p*p<1000005; p++){ if(prime[p]==p) { for(ll i=1LL*p*p; i<1000005; i+=p) if(prime[i]==i) prime[i]=p; } }
    return;
}
bool isPrime(ll pri){
    if(pri==1||pri==0) return 0;
    if(prime[pri]==pri) return 1;
    return 0;
}
vl alldiv(ll num){
    vl prDiv; for(ll i=1; 1LL*i*i<=num; i++){ if(num%i==0){ prDiv.pb(i); if(i!=(num/i)) prDiv.pb(num/i); } }
    sort(all(prDiv)); return prDiv;
}
vl prdiv(ll num){
    vl prDiv; while(num!=1){ prDiv.pb(prime[num]); ll prtemp=prime[num]; while(num%prtemp==0) num/=prtemp; }
    return prDiv;
}

int main() {
    fastio; //tim=clock();
    testcase;
    //ll t=1;
    forx(T,1,1+t){
        ll x,e=0;
        cin>>x;
        ll dp[x+2];
        string str;
        cin>>str;
        vl c;
        ll a=str[0]-'0';
        ll n=str.size();
        dp[0]=n;
        forx(i,0,n) c.pb(str[i]-'0');
        forx(i,1,x+2){
            dp[i]=(dp[i-1]+((c[i-1]-1)*(dp[i-1]-i))%MOD)%MOD;
            if(c.size()<x+2){
                forx(ii,1,c[i-1]){
                    forx(j,i,dp[i-1]){
                        c.pb(c[j]);
                        if(c.size()==x+2) break;
                    }
                }
            }
        }
        cout<<dp[x]<<"\n";
    }
	return 0;
}