#include <bits/stdc++.h>
using namespace std;
const int N = 1000007, inf = 0x3f3f3f3f;
const int M = 1000000007;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    string s;
    cin >> s;
    long long len = s.size();
    int cur = 0;
    while (1) {
      cur++;
      int times = s[cur - 1] - '1';
      long long aux = len;
      if (s.size() < x) {
        for (int i = 0; i < times; ++i) {
          for (int j = cur + 1; j <= aux; ++j) {
            s += s[j - 1];
          }
        }
      }
      len += ((aux - cur + M) % M) * times % M;
      len %= M;
      if (cur == x) break;
    }
    cout << len << '\n';
  }
}
