#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
bool sortbysec_2(const pair<string, int> &a, const pair<string, int> &b) {
  return (a.second < b.second);
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second > b.second;
}
double distance(int x1, int y1, int x2, int y2) {
  return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) * 1.0);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    string second;
    cin >> second;
    vector<char> c;
    for (int i = 0; i < second.size(); i++) c.push_back(second[i]);
    long long int m = 0;
    for (int i = 0; i < x; i++) {
      if (c.size() < x) {
        long long int m1 = c.size();
        for (int first = 0; first < (c[i] - '0') - 1; first++) {
          for (int j = i + 1; j < m1; j++) {
            c.push_back(c[j]);
          }
        }
      }
      long long int a = (i + 1) % 1000000007;
      long long int b = (c.size() - (i + 1)) % 1000000007;
      long long int c1 = (c[i] - '0');
      m = (a + (b * c1) % 1000000007) % 1000000007;
    }
    cout << m << endl;
  }
}
