#include <bits/stdc++.h>
using namespace std;
long long dp[1000050];
const int mod = 1e9 + 7;
int main() {
  int t, x, len;
  scanf("%d", &t);
  while (t--) {
    string a, b, c;
    scanf("%d", &x);
    cin >> a;
    len = a.size();
    int k = 1;
    while (a.size() < x) {
      int l = a.size();
      for (int i = 1; i < a[k - 1] - '0'; i++) {
        a += a.substr(k, l - k);
      }
      k++;
    }
    dp[0] = len;
    for (long long i = 1; i <= x; i++) {
      dp[i] = (i + ((dp[i - 1] - i) * (a[i - 1] - '0')) % mod + mod) % mod;
    }
    cout << dp[x] << endl;
  }
}
