#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long res = 1;
  a = a % 1000000007;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b /= 2;
  }
  return res;
}
long long invmod(long long a) { return power(a, 1000000007 - 2); }
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s, h;
    long long x;
    cin >> x >> s;
    long long ans = s.size();
    for (int i = 0; i < x; i++) {
      if (s[i] == '1') continue;
      if (s.size() < x) {
        h = s.substr(i + 1);
        for (int j = 0; j < s[i] - '1'; j++) s += h;
      }
      ans = (ans + (ans - i - 1) * (s[i] - '0' - 1) + 1000000007) % 1000000007;
    }
    cout << ans % 1000000007 << "\n";
  }
  return 0;
}
