#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
char s[10000006];
int vis[10000006];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    cin >> s + 1;
    long long len = strlen(s + 1);
    for (int i = 1; i <= len; i++) vis[i] = 1;
    long long tmp = 0;
    long long ans = len;
    while (1) {
      tmp++;
      if (tmp > n) break;
      ans =
          (1ll * tmp +
           1ll * (ans - tmp + mod) % mod * (1ll * (s[tmp] - '0')) % mod + mod) %
          mod;
      if (len < n) {
        int x = len + 1;
        for (int i = 1; i <= s[tmp] - '0' - 1; i++) {
          for (int j = tmp + 1;; j++) {
            if (vis[j] == 0) break;
            s[++len] = s[j];
          }
          if (len > n) break;
        }
        for (int i = x; i <= len; i++) vis[i] = 1;
      }
    }
    cout << ans << endl;
    for (int i = 1; i <= len; i++) s[i] = 0, vis[i] = 0;
  }
}
