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