#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    string s, c;
    cin >> s;
    long long int res, temp = s.length();
    for (int t = 1; t <= x; ++t) {
      int k = s[t - 1] - '1';
      if (s.size() <= x) {
        string sub = s.substr(t);
        for (int j = 0; j < k; ++j) s.append(sub);
      }
      temp = (temp + (temp - t) * k) % mod;
    }
    cout << (temp % mod + mod) % mod << "\n";
  }
  return 0;
}
