#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+5;
const ll M = 1e9+7;
 
ll a[N];
 
int main()
{
	int x,T;
	scanf("%d",&T);
	while(T--){
		scanf("%d",&x);
		string s;
		cin >> s;
		
		a[0] = s.size()%M;
		bool f = 0;
		for(ll i = 1;i <= x;++i){
			if(!f){
				for(int j = 1;j < (s[i-1]-'0');++j) s += s.substr(i,a[i-1]-i+1);
			}
			if(s[i-1] == '1') a[i] = a[i-1];
			else a[i] = ((i%M)+(((a[i-1]-i)%M)*(s[i-1]-'0'))%M)%M;
			if(a[i] >= x) f = 1;
		}
		printf("%lld\n",(a[x]+M)%M);
	}
	return 0;
}