#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;
const int MAXM = 2e5 + 5;
const int MOD = 1e9 + 7;
const int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
string s, c;
long long x, t;
long long l, ans;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> x >> s;
    l = 0, ans = s.size();
    while (l < x) {
      l++;
      if (s.size() < x && s[l - 1] > '1') {
        c = s.substr(l);
        for (int i = 0; i < s[l - 1] - '1'; i++) s += c;
      }
      ans = (ans + (ans - l + MOD) % MOD * (s[l - 1] - '1') % MOD) % MOD;
    }
    cout << ans << endl;
  }
  return 0;
}
