#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int i, k, n, x, t;
  string s, r;
  cin >> t;
  while (t--) {
    cin >> x >> s;
    n = s.length();
    for (i = 0; i < x; i++) {
      n = (n + (((n - i - 1 + 1000000007) % 1000000007) * (s[i] - '0' - 1)) %
                   1000000007) %
          1000000007;
      if ((long long int)(s.length()) < x) {
        vector<char> v(s.begin() + i + 1, s.end());
        k = s[i] - '0' - 1;
        while (k--) s.insert(s.end(), v.begin(), v.end());
      }
    }
    cout << n << '\n';
  }
  return 0;
}
