#include <bits/stdc++.h>
int main() {
  long long q = 1e9 + 7;
  int s[1000000];
  int t;
  std::cin >> t;
  for (int i = 0; i < t; i++) {
    int x;
    std::cin >> x;
    for (int z = 0; z < x; z++) {
      s[z] = 0;
    }
    std::string tmp;
    std::cin >> tmp;
    for (int z = 0; z < tmp.length(); z++) {
      s[z] = tmp[z] - '0';
    }
    long long c = tmp.length();
    int nul = tmp.length();
    for (int j = 0; j < x; j++) {
      if (s[j] > 1) {
        c = ((q + c - j - 1) * s[j] + j + 1) % q;
        if (nul < x) {
          int nul0 = nul;
          for (int k = 0; k < s[j] - 1; k++) {
            for (int l = j + 1; l < nul0; l++) {
              if (nul == x) {
                break;
              }
              s[nul] = s[l];
              nul++;
            }
          }
        }
      }
    }
    printf("%lld\n", c);
  }
}
