#include <bits/stdc++.h>
using namespace std;
void shikhar7s(long long int cas) {
  long long int x;
  cin >> x;
  string s, c;
  cin >> s;
  long long int ls = (long long int)s.length(), lc = 0, i, j, f = 0;
  for (i = 1; i <= x; i++) {
    c = "";
    if (!f) {
      for (j = i; j < ls; j++) {
        c.push_back(s[j]);
      }
      for (j = 0; j < (s[i - 1] - '0') - 1; j++) {
        s.append(c);
        if ((long long int)s.length() >= x) break;
      }
    }
    if (ls < x) {
      lc = ls - i;
      ls = i;
      ls += (lc * (s[i - 1] - '0'));
    } else {
      lc = (ls - i + 1000000007) % 1000000007;
      ls = i;
      ls = (ls + (lc * (s[i - 1] - '0')) % 1000000007) % 1000000007;
      f = 1;
    }
    if (ls >= x) f = 1;
  }
  cout << ls << "\n";
}
signed main() {
  std::ios_base::sync_with_stdio(false);
  long long int t = 1;
  cin >> t;
  long long int cas = 1;
  while (cas <= t) {
    shikhar7s(cas);
    cas++;
  }
  return 0;
}
