#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    string second;
    cin >> second;
    long long ans = second.size();
    string s1 = second;
    long long mod = 1e9 + 7;
    for (int i = 0; i < second.size(); i++) {
      s1.erase(s1.begin());
      int num = second[i] - '0';
      string temp = s1;
      int sz = second.size();
      int sz1 = s1.size();
      for (int j = 1; j < num; j++) {
        for (auto y : temp) {
          second += y;
          s1 += y;
          if (second.size() >= x) break;
        }
        if (second.size() >= x) break;
      }
      if (second.size() >= x) break;
    }
    for (long long i = 0; i < x; i++) {
      long long num = second[i] - '0';
      long long temp = (ans - i - 1 + mod) % mod;
      ans = (i + 1 + num * temp % mod) % mod;
    }
    cout << ans << endl;
  }
  return 0;
}
