#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long M = 1e9 + 7;
long long a[N];
int main() {
  int x, T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &x);
    string s;
    cin >> s;
    a[0] = s.size();
    int k = 0;
    while (s.size() < x) {
      int o = s[k] - '0';
      string t = s.substr(k + 1);
      s = s.substr(0, k + 1);
      for (int i = 1; i <= o; ++i) s += t;
      k++;
    }
    for (int i = 1; i <= x; ++i) {
      if (s[i - 1] == '1')
        a[i] = a[i - 1];
      else {
        a[i] = i + (a[i - 1] - i) * (long long)(s[i - 1] - '0');
        a[i] %= M;
      }
    }
    printf("%d\n", a[x]);
  }
  return 0;
}
