#include<bits/stdc++.h>
#define pb push_back
//#define mp make_pair
#define fastread ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define openfile ifstream cin; ofstream cout; cin.open("input.txt"); cout.open("output.txt");
#define f(i, x, y) for(int i = x; i < y; i++)
#define all(X) X.begin(), X.end()
#define int long long
#define ll long long
#define key pair<int, int>
#define keyy pair<pair<int, int>, int>
#define keyyy pair<pair<int, int>, pair<int, int>>
#define keyd pair<double, double>
#define ff first
#define ss second
#define double long double
int mod = 1e9 + 7;
const int inf = 1e18;
using namespace std;
 
main()
{
    int T; cin>>T;
    while(T--)
    {
        int x; cin>>x; string s; cin>>s;
        int n = s.length();
        f(i, 0, x)
        {
            int tt = -1;
            if(n < x)
            {
                string t = s.substr(i+1, n);
                f(j, 0, s[i] - '0' -  1)
                    s += t;
                n = s.length();
            }
            else
            {
                // cout<<"a "<<s[i]<<" "<<(s[i] - '0' - 1)<<" "<<n-i<<"\n";
                tt = (s[i] - '0' - 1) * (n - i - 1);
                n = (n + tt) % mod;
            }
            // cout<<s<<" "<<s.length()<<" "<<s[i]<<n<<" "<<tt<<"\n";
        }
        cout<<n<<"\n";
    }
}