#include <bits/stdc++.h>
using namespace std;
long long int MAX_NUM = pow(10, 9) + 7;
long long int next_length(long long int current_length,
                          long long int current_position,
                          long long int current_number) {
  long long int length = 0;
  for (int i = 0; i < current_number; i++) {
    length += current_length - current_position - 1;
    length %= MAX_NUM;
  }
  length += current_position + 1;
  length %= MAX_NUM;
  if (length < 0) {
    length += MAX_NUM;
  }
  return length;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long int x;
    string s;
    cin >> x >> s;
    long long int length = s.size();
    long long int position = 0;
    while (s.size() < x) {
      if (position == x) {
        break;
      }
      long long int number = ((long long int)s[position]) - 48;
      position++;
      string copied = s.substr(position);
      for (long long int i = 0; i < number - 1; i++) {
        s += copied;
      }
      length = next_length(length, position - 1, number);
    }
    while (position < x) {
      long long int number = ((long long int)s[position]) - 48;
      position++;
      length = next_length(length, position - 1, number);
    }
    cout << length << '\n';
  }
}
