#include <bits/stdc++.h>
int main() {
  long long int tot_c, tot_s, m = 1000000007;
  int x, t;
  unsigned char ls, fc;
  scanf("%d", &t);
  while (t--) {
    char inp[1000000] = {0};
    char *fc_ptr = inp;
    scanf("%d", &x);
    scanf("%s", &inp);
    unsigned int len = strlen(inp);
    ls = (*fc_ptr++) - '0';
    fc = *fc_ptr - '0';
    tot_c = len - 1;
    tot_s = x;
    while (x--) {
      unsigned int tmp;
      unsigned int tmp_ls = ls;
      while (ls > 1) {
        tmp = 0;
        while (tmp < tot_c) {
          if (len == 1000000) break;
          inp[len++] = *fc_ptr++;
          tmp++;
        }
        fc_ptr -= tmp;
        ls--;
      }
      tot_c *= tmp_ls;
      tot_c--;
      tot_c %= m;
      ls = fc;
      fc_ptr++;
      fc = *fc_ptr - '0';
    }
    long long s = (tot_c + 1 + tot_s) % m;
    printf("%lld\n", s);
  }
  return 0;
}
