#include <bits/stdc++.h>
using namespace std;
long long int x;
string result = "";
string s;
void fun() {
  long long int index = 0;
  while (s.size() < x) {
    long long int c = s[index] - '0';
    string subc = s.substr(index + 1, s.size() - index - 1);
    for (long long int i = 1; i < c; i++) {
      s += subc;
    }
    index++;
  }
}
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    cin >> x;
    cin >> s;
    long long int sz = s.size();
    fun();
    long long total = 0, left = 0, right = 0;
    for (long long int i = 0; i < x; i++) {
      left = (i + 1) % 1000000007;
      right = (sz - left + 1000000007) % 1000000007;
      total = (left + (right * (s[i] - '0')) % 1000000007) % 1000000007;
      sz = total % 1000000007;
    }
    cout << total << endl;
  }
}
