#include <bits/stdc++.h>
using namespace std;
long long R = pow(10, 9) + 7;
template <typename T>
T last(vector<T>& v) {
  return v[v.size() - 1];
}
template <typename T>
void prll(vector<T>& v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << ' ';
  }
  cout << endl;
}
template <typename T1, typename T2>
void prll(vector<pair<T1, T2>>& v) {
  cout << "[";
  for (long long i = 0; i < v.size(); i++) {
    cout << '(' << v[i].first << ',' << v[i].second << "),";
  }
  cout << "]" << endl;
}
template <typename T>
void prll(vector<vector<T>>& v) {
  cout << "[";
  for (long long i = 0; i < v.size(); i++) {
    prll(v[i]);
  }
  cout << "]" << endl;
}
template <typename T>
void prll(set<T>& v) {
  cout << "{";
  for (auto i : v) {
    cout << i << ' ';
  }
  cout << "}" << endl;
}
template <typename T1, typename T2>
void prll(map<T1, T2>& v) {
  cout << "{";
  for (auto i : v) {
    cout << i.first << ':' << i.second << ',';
  }
  cout << "}" << endl;
}
template <typename T>
bool in(set<T>& indices, T x) {
  return indices.find(x) != indices.end();
}
template <typename T, typename T_>
bool in(map<T, T_>& indices, T x) {
  return indices.find(x) != indices.end();
}
long long power(long long x, long long y) {
  long long res = 1;
  x = x % R;
  if (x == 0) return 0;
  while (y > 0) {
    if (y % 2 == 1) res = (res * x) % R;
    y /= 2;
    x = (x * x) % R;
  }
  return res;
}
void TestCase() {
  long long x;
  cin >> x;
  x--;
  string s;
  cin >> s;
  long long n = s.length();
  long long l = -1;
  bool simulate = true;
  while (l < x) {
    l++;
    if (simulate) {
      string ss = s.substr(l + 1, n - l - 1);
      for (long long i = 0; i < s[l] - '1'; i++) {
        s.append(ss);
      }
    }
    n = (l + 1) + (s[l] - '0') * (n - l - 1);
    n = (n + R) % R;
    if (n > x) {
      simulate = false;
    }
  }
  cout << n << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long T;
  T = 1;
  cin >> T;
  for (long long tt = 1; tt <= T; tt++) {
    TestCase();
  }
}
