#include <bits/stdc++.h>
using namespace std;
string s, sLeft, sRight;
int times[1000005];
int main() {
  int t, x, siz, tem;
  cin >> t;
  while (t) {
    --t;
    cin >> x;
    cin >> s;
    siz = s.length();
    int l = 0;
    string s_ = s;
    while (siz < x) {
      tem = s[l] - '0';
      if (tem == 1) {
        l++;
        continue;
      }
      sRight = s.substr(l + 1);
      for (int i = 1; i < tem; ++i) {
        s += sRight;
      }
      l++;
      siz = s.length();
    }
    for (int i = 0; i < x; ++i) {
      times[i] = (s[i] - '0') - 1;
    }
    unsigned long long num = s_.length();
    for (int i = 0; i < x; ++i) {
      if (num < i + 1) num += 1000000007;
      num += times[i] * (num - i - 1);
      if (num > 1000000007) num %= 1000000007;
    }
    cout << num % 1000000007 << endl;
  }
  return 0;
}
