#include <bits/stdc++.h>
using namespace std;
long long int p = 1e9 + 7;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    string s;
    cin >> s;
    int inl = s.length();
    int i = 0;
    while (s.length() < x) {
      int l1 = s.length();
      for (int j = 0; j < (s[i] - '1'); j++)
        s.append(s.substr(i + 1, l1 - i - 1));
      i++;
    }
    s = s.substr(0, x);
    long long int prod = 1, temp = 0;
    for (int i = x - 1; i >= 0; i--) {
      prod = (prod * (s[i] - '0')) % p;
      temp = (temp - prod + p) % p;
    }
    prod = (prod * inl) % p;
    temp = (temp + x + prod) % p;
    cout << temp << endl;
  }
  return 0;
}
