#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define reset(x, k) memset(x, k, sizeof(x))
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
  int res = 1;

  x = x % p;
  while (y > 0)
  {

    if (y & 1)
      res = (res * x) % p;

    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--)
  {
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<int, int> mp;
    for (int i = 0; i < s.size();i++){
      mp[i + 1] = s[i] - '1';
    }
    int ans = s.size();
    int u = ans+1;
    int co = ans;
    for (int i = 1; i <= n;i++){
      int f = ans - i;
      int z = mp.size();
      //cout << z << " ";
      int k = i+1;
      for (int j = co+1; j <= min(n,f*mp[i]+co); j++)
      {
        //cout << j << " ";
        mp[j] = mp[k];
        k++;
         
      }
      f = f * mp[i];
      ans =(ans%mod+ f%mod)%mod;
      co = co + f;
    }
      cout << ans<<endl;
  }

  return 0;
}