#include <bits/stdc++.h>
using namespace std;
int a[1000020];
long long mod = 1e9 + 7;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int x;
    char s[520];
    scanf("%d", &x);
    scanf("%s", s);
    int m = strlen(s);
    for (int i = 0; i <= m - 1; i++) {
      a[i] = s[i] - '0';
    }
    int point = m;
    int end = m - 1;
    long long count = m;
    long long sum = 0;
    for (int i = 0; i <= x - 1; i++) {
      if (point <= x) {
        for (int j = 0; j < a[i] - 1; j++) {
          for (int k = i + 1; k <= end; k++) {
            if (point <= x) {
              a[point++] = a[k];
            }
          }
        }
      }
      end = point - 1;
      sum++;
      count = (((count - 1 + mod) % mod) * a[i]) % mod;
    }
    printf("%lld\n", (sum + count) % mod);
  }
  return 0;
}
