#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007LL;
int T;
string S;
int main() {
  ios::sync_with_stdio(false);
  cin >> T;
  while (T--) {
    int x;
    cin >> x;
    cin >> S;
    long long Ans = S.size();
    for (register int i = 1; i <= x; ++i) {
      Ans = ((long long)i + (long long)(Ans - (long long)i) *
                                (long long)(S[i - 1] - '0') % MOD) %
            MOD;
      if (S.size() < x) {
        string str = S.substr(i);
        int Count = S[i - 1] - '0';
        for (register int j = 1; j <= Count - 1; ++j) {
          S += str;
          if (S.size() > x) break;
        }
      }
    }
    cout << Ans % MOD << endl;
  }
  return 0;
}
