#include <bits/stdc++.h>
using namespace std;
long long int mul(int a, int b) {
  return (a % 1000000007 * 1ll * b % 1000000007) % 1000000007;
}
long long int solve() {
  int x;
  long long int pre;
  int cp = 0;
  string se;
  cin >> x >> se;
  vector<char> c;
  vector<char> s(se.begin(), se.end());
  int l = 0;
  long long int ans = s.size();
  while (l != x) {
    l++;
    pre = ans;
    ans = (pre + mul(((int)(s[l - 1] - '0') - 1), (pre - l))) % 1000000007;
    if (s.size() < x + 2) {
      c.clear();
      c.insert(c.begin(), s.begin() + l, s.end());
      for (int i = 1; i <= (int)(s[l - 1] - '0') - 1; i++) {
        s.insert(s.end(), c.begin(), c.end());
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cout << (solve() % 1000000007 + 1000000007) % 1000000007 << "\n";
  }
}
