#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
inline long long add(long long a, long long b) {
  return ((a % MOD) + (b % MOD)) % MOD;
}
inline long long subtract(long long a, long long b) {
  a = a % MOD;
  b = b % MOD;
  if (a >= b)
    return (a - b);
  else
    return a - b + MOD;
}
inline long long multiply(long long a, long long b) {
  return ((a % MOD) * (b % MOD)) % MOD;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    int x;
    string s;
    cin >> x >> s;
    int l = 0;
    long long curLength = s.length();
    for (int l = 1; l <= x; l++) {
      long long rem = subtract(curLength, l);
      curLength = add(curLength, multiply(rem, s[l - 1] - '1'));
      if (s.length() <= x) {
        string temp = s.substr(l);
        for (int i = 1; i < s[l - 1] - '0'; i++) {
          s += temp;
        }
      }
    }
    cout << curLength << '\n';
  }
  return 0;
}
