#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T>
inline T biton(T n, T pos) {
  return n | ((T)1 << pos);
}
template <class T>
inline T bitoff(T n, T pos) {
  return n & ~((T)1 << pos);
}
template <class T>
inline T ison(T n, T pos) {
  return (bool)(n & ((T)1 << pos));
}
template <class T>
inline T gcd(T a, T b) {
  while (b) {
    a = a % b;
    swap(a, b);
  }
  return a;
}
template <class T>
inline T bigmod(T p, T e, T m) {
  T ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % m;
    p = (p * p) % m;
  }
  return (T)ret;
};
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " is " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " is " << arg1 << " | ";
  __f(comma + 1, args...);
}
void solve() {
  int x;
  cin >> x;
  string str;
  cin >> str;
  int n = (int)str.size();
  long long ans = n;
  int i = 1;
  long long md = 1e9 + 7;
  while (i <= x) {
    long long rem = ans - i;
    long long t = (str[i - 1] - '0') - 1;
    ans += rem * t;
    if (str.size() < x) {
      string sub = str.substr(i);
      for (int f = 1; f <= t; f++) {
        str += sub;
      }
    }
    ans = ans % md;
    while (ans < 0) {
      ans += md;
    }
    i++;
  }
  cout << ans << "\n";
  ;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(10);
  cout.tie(nullptr);
  cin.tie(nullptr);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
