#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long T;
  cin >> T;
  while (T--) {
    string S;
    long long x;
    cin >> x >> S;
    long long i = 0, ans = 0, temp = S.length();
    while (i < x) {
      if (S.length() < x) {
        string str = S.substr(i + 1, S.length() - 1);
        ans = (i + 1 + str.length() * (S[i] - 48) + 1000000007) % 1000000007;
        for (long long j = 1; j < S[i] - 48; j++) S += str;
        temp = ans;
      } else {
        ans = ((temp - i - 1) * (S[i] - 48) + i + 1 + 1000000007) % 1000000007;
        temp = ((temp - i - 1) * (S[i] - 48) + i + 1 + 1000000007) % 1000000007;
      }
      i++;
    }
    cout << ans << endl;
  }
}
