#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<pair<long long, long long>, long long> &a,
               const pair<pair<long long, long long>, long long> &b) {
  return (a.second < b.second);
}
string add(string st1, string st2) {
  long long r = 0;
  string ans;
  ans.resize(3000);
  for (long long i = 2999; i >= 0; i--) {
    long long x = st1[i] - '0';
    long long y = st2[i] - '0';
    long long z = x + y + r;
    if (z >= 10) {
      r = 1;
    } else
      r = 0;
    ans[i] = (z % 10) + '0';
  }
  return ans;
}
long long p(long long x) { return ((x % 1000000007) * 2) % 1000000007; }
long long mat[1005][1005];
long long f(long long h, set<long long> s, long long ans) {
  if (h <= 1) {
    return ans;
  }
  cout << ans << endl;
  long long ans1, ans2, ans3, ans4;
  if (s.find(h - 1) == s.end()) {
    ans1 = f(h - 1, s, ans);
  } else {
    ans1 = f(h - 1, s, ans + 1);
  }
  if (s.find(h - 1) == s.end()) {
    ans2 = f(h - 2, s, ans + 1);
  } else {
    ans2 = f(h - 2, s, ans);
  }
  cout << ans1 << " " << ans2 << "t\n";
  return min(ans1, ans2);
}
long long ar[100000 + 5];
long long prevs[1000];
long long cnt[1000];
double f(double x) { return ((pow(4, x)) + pow(6, x) - pow(9, x)); }
long long gcd(long long a, long long b);
long long power(long long x, unsigned long long y, unsigned long long m);
long long modInverse(long long a, long long m) {
  long long g = gcd(a, m);
  if (g != 1)
    ;
  else {
    return power(a, m - 2, m);
  }
}
long long power(long long x, unsigned long long y, unsigned long long m) {
  if (y == 0) return 1;
  long long p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  long long q;
  cin >> q;
  while (q--) {
    long long x;
    string st;
    cin >> x;
    cin >> st;
    if (st.size() == 1) {
      cout << 1 << endl;
      continue;
    }
    string st1 = st;
    long long i = 0;
    long long a = st[0] - '0';
    while (st.size() <= x) {
      long long s = st.size();
      for (long long j = 0; j < a - 1; j++) {
        for (long long k = i + 1; k < s; k++) {
          st.push_back(st[k]);
        }
      }
      i++;
      if (st.size() >= x) break;
      a = st[i] - '0';
    }
    i = 0;
    long long l = 1;
    a = st[0] - '0';
    long long sz = st1.size();
    long long m = 1000000000 + 7;
    for (long long i = 0; i < x;) {
      long long l = i + 1;
      sz = (((sz - l + m) % m * a % m) % m + l % m) % m;
      i++;
      if (i == x) break;
      a = (st[i] - '0') % m;
    }
    cout << sz % m << endl;
  }
}
