#include <bits/stdc++.h>
using namespace std;
const long long int use = 1e6;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    long long int x;
    cin >> x;
    string s;
    cin >> s;
    long long int len = s.size();
    string temp = s;
    for (long long int l = 1; l <= x; l++) {
      long long int k = temp[l - 1] - 48;
      if (len < x) {
        string paste = temp.substr(l);
        for (long long int i = 0; i < k - 1 and temp.size() < x; i++)
          temp.insert(temp.end(), paste.begin(), paste.end());
      }
      long long int y = (len - l + 1000000007) % 1000000007;
      len = (len + (y * (k - 1)) % 1000000007) % 1000000007;
    }
    cout << len << endl;
  }
}
