//IF YOU GIVE UP,THEN YOU DON'T DESERVE IT

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI 3.14159265358979323846264

using namespace std;  
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define T int
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>

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

    while(t--)
    {ll x;string str;
        cin>>x>>str;
        ll ans=str.size();

        for(int i=0;i<str.size() and str.size()<x;i++)
        {  if(str[i]=='1')continue;
            string s=str.substr(i+1,str.size()-i-1);
            int num=str[i]-'0';
            for(int j=1;j<=num and str.size()<x;j++)
                str+=s;
        }
      //  cout<<"here "<<str.size()<<endl;
        for(int i=0;i<x;i++)
        {
           ll cur=(((ans-i-1+mod)%mod)*(str[i]-'0'-1))%mod;
           ans=(ans+cur)%mod;
        }
        cout<<ans<<endl;

    }
}