#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 1000100;
const int INF = 0x3f3f3f3f;
char c[MAXN];
int T, x;
long long ans;
bool flag;
long long read() {
  char c = getchar();
  long long x = 0, flag = 1;
  while (c < '0' || c > '9') {
    if (c == '-') flag = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * flag;
}
int main() {
  scanf("%d", &T);
  while (T) {
    --T, ans = 0, flag = 0;
    scanf("%d", &x);
    scanf("%s", c + 1);
    int ans = strlen(c + 1);
    for (int i = 1; i <= x; ++i) {
      long long len = ans;
      ans = (ans + (c[i] - '1') * (ans - (long long)i + MOD) % MOD) % MOD;
      if (flag) continue;
      if (c[i] == '1') continue;
      if (c[i] == '2') {
        if (ans < x)
          for (int j = len + 1; j <= ans; ++j) c[j] = c[j - (ans - len)];
        else {
          flag = 1;
          for (int j = len + 1; j <= x; ++j) c[j] = c[j - (ans - len)];
        }
      }
      if (c[i] == '3') {
        if (len + (ans - len) / 2 < x) {
          for (int j = len + 1; j <= len + (ans - len) / 2; ++j)
            c[j] = c[j - (ans - len) / 2];
        } else {
          flag = 1;
          for (int j = len + 1; j <= x; ++j) c[j] = c[j - (ans - len) / 2];
          continue;
        }
        if (ans < x) {
          for (int j = len + (ans - len) / 2 + 1; j <= ans; ++j)
            c[j] = c[j - (ans - (len + (ans - len) / 2))];
        } else {
          flag = 1;
          for (int j = len + (ans - len) / 2 + 1; j <= x; ++j)
            c[j] = c[j - (ans - (len + (ans - len) / 2))];
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
