#include <bits/stdc++.h>
using namespace std;
class compare {
 public:
  bool operator()(pair<long long, long long> a, pair<long long, long long> b) {
    if (a.first > b.first) return true;
    return false;
  }
};
bool comp(long long a, long long b) { return a > b; }
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;
    }
    b /= 2;
    a = (a * a) % 1000000007;
  }
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    string st;
    long long x;
    cin >> x >> st;
    long long ls = st.length();
    vector<char> s(st.begin(), st.begin() + ls);
    for (long long i = 1; i <= x; i++) {
      long long v = s[i - 1] - '1';
      if (s.size() < x) {
        vector<char> sub(s.begin() + i, s.end());
        for (long long it = 0; it < v; it++) {
          s.insert(s.end(), sub.begin(), sub.end());
        }
      }
      ls = (ls % 1000000007 + ((ls - i) * v) % 1000000007) % 1000000007;
    }
    cout << (ls + 1000000007) % 1000000007 << "\n";
  }
}
