#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long x;
    cin >> x;
    string inp;
    cin >> inp;
    long long cur = 0;
    while (inp.size() < x) {
      cur++;
      string tmp = inp.substr(cur);
      for (__typeof((inp[cur - 1] - '1')) i =
               (0) - ((0) > ((inp[cur - 1] - '1')));
           i != ((inp[cur - 1] - '1')) - ((0) > ((inp[cur - 1] - '1')));
           i += 1 - 2 * ((0) > ((inp[cur - 1] - '1'))))
        inp += tmp;
    }
    cur++;
    long long ans = inp.size();
    for (__typeof(x + 1) i = (cur) - ((cur) > (x + 1));
         i != (x + 1) - ((cur) > (x + 1)); i += 1 - 2 * ((cur) > (x + 1))) {
      ans += (((inp[i - 1] - '1') * (ans - i + 1000000007)) % 1000000007);
      ans %= 1000000007;
    }
    cout << ans << '\n';
  }
  return 0;
}
