#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, T;
  cin >> T;
  for (t = 1; t <= T; t++) {
    int x;
    string s;
    cin >> x;
    cin >> s;
    string p;
    p += s;
    int index = 0;
    while (p.length() < x) {
      index += 1;
      string c = p.substr(index);
      int u, k = p[index - 1] - '1';
      for (u = 1; u <= k; u++) p += c;
    }
    long long len = s.length();
    int i;
    for (i = 1; i <= x; i++) {
      len += (long long)(p[i - 1] - '1') * (long long)(len - i);
      len = len % 1000000007;
    }
    if (len < 0) len = len + 1000000007;
    cout << len << endl;
  }
  return 0;
}
