#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int mod = 1e9 + 7;
const int N = 505;
char s[N];
LL solve() {
  int x;
  scanf("%d%s", &x, &s);
  LL len = strlen(s);
  vector<char> obj(s, s + len);
  for (int i = 1; i <= x; ++i) {
    int v = obj[i - 1] - '1';
    if (obj.size() < x) {
      vector<char> sub(obj.begin() + i, obj.end());
      for (int j = 0; j < v; ++j) obj.insert(obj.end(), sub.begin(), sub.end());
    }
    len = (len + (len - i) * v) % mod;
  }
  return len;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    printf("%lld\n", (solve() % mod + mod) % mod);
  }
  return 0;
}
