#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
char s[1000009], t[1000009];
int mod(long long x) {
  x %= 1000000007;
  if (x < 0) x += 1000000007;
  return x;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int x;
    scanf("%d", &x);
    scanf("%s", s);
    int n = strlen(s);
    int cur = n, tmp = n, pos = 0;
    while (tmp < x) {
      int mal = tmp;
      for (int j = 1; j < (s[pos] - '0'); j++) {
        for (int i = pos + 1; mal < x and i < tmp; i++) s[mal++] = s[i];
      }
      tmp = mal;
      pos++;
    }
    for (int i = 0; i < x; i++)
      cur = mod((i + 1) + (cur - i - 1) * 1LL * (s[i] - '0'));
    printf("%d\n", cur);
  }
  return 0;
}
