#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}
template <typename T>
T pow(T a, int b) {
  return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1;
}
void solve() {
  int x;
  cin >> x;
  string s;
  cin >> s;
  long long ans = (int)s.size();
  int pos = 0;
  while ((int)s.size() < x) {
    pos++;
    string c = s.substr(pos, (int)s.size());
    for (int i = 0; i < (s[pos - 1] - '0' - 1); ++i) s += c;
  }
  for (int i = 0; i < (x); ++i) {
    ans = ans + (ans - (i + 1) + (int)(1e9 + 7)) % (int)(1e9 + 7) *
                    (s[i] - '0' - 1) % (int)(1e9 + 7);
    ans %= (int)(1e9 + 7);
  }
  cout << ans << endl;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    solve();
  }
}
