#include <bits/stdc++.h>
using namespace std;
string temp, h;
const int mod = 1e9 + 7;
long long len;
int t, x;
int main() {
  cin >> t;
  while (t--) {
    cin >> x >> temp;
    len = temp.size();
    for (int i = 1; i <= x; i++) {
      int cc = temp[i - 1] - '1';
      if (temp.size() < x) {
        h = temp.substr(i);
        for (int j = 1; j <= cc; j++) temp += h;
      }
      len = (len + cc * (len - i) + mod) % mod;
    }
    cout << len % mod << endl;
  }
  return 0;
}
