#include <bits/stdc++.h>
using namespace std;
string s, c;
void getstrc(unsigned long long int x) {
  unsigned long long int l, i, sl, cl;
  c = s;
  l = 1;
  while (c.length() < x) {
    char ch = c[l - 1];
    sl = int(ch) - 48;
    cl = c.length() - l;
    string scl = c.substr(l, cl);
    for (i = 0; i < (sl - 1); i++) c += scl;
    l++;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    unsigned long long int x, i, str, sl, cl, l;
    cin >> x;
    cin >> s;
    if (x <= (s.length()))
      c = s;
    else
      getstrc(x);
    str = s.length();
    for (i = 0; i < x; i++) {
      l = i + 1;
      char ch = c[i];
      sl = ch - '0';
      cl = str - l;
      str = str + ((sl - 1) * ((cl + 1000000007) % 1000000007)) % 1000000007;
      str %= 1000000007;
    }
    cout << str << endl;
  }
}
