#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s;
    int x;
    cin >> x >> s;
    long long ans = s.size();
    for (int i = 0; (int)s.size() < x; i++) {
      if (s[i] == '1') continue;
      string tmp = "";
      for (int j = i + 1; j < (int)s.size(); j++) {
        tmp += s[j];
      }
      for (int j = 1; j < s[i] - 48; j++) s += tmp;
    }
    for (int i = 1; i <= x; i++) {
      long long t1 = (ans - i + mod) % mod;
      int cur = s[i - 1] - 48;
      ans = (i + (t1 * cur) % mod) % mod;
    }
    cout << ans << "\n";
  }
}
