#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long ans;
int t, x, l, len;
string s;
int main() {
  cin >> t;
  while (t--) {
    l = 1;
    cin >> x;
    cin >> s;
    len = s.size();
    while (len < x) {
      for (int i = 1; i < s[l - 1] - '0'; ++i) {
        s += s.substr(l, len - l);
      }
      len = s.size();
      l++;
    }
    ans = s.size();
    for (int i = l; i <= x; ++i) {
      ans = (ans + (s[i - 1] - '0' - 1) * (ans - i) % mod) % mod;
    }
    cout << ans << endl;
  }
  return 0;
}
