#include <bits/stdc++.h>
using namespace std;
long long int max(long long int a, long long int b) {
  if (a > b) return a;
  return b;
}
int main() {
  int t;
  cin >> t;
  for (int j = 0; j < t; j++) {
    int x;
    string s;
    cin >> x;
    cin >> s;
    int n = s.length();
    if (n == 1) {
      cout << "1\n";
      continue;
    }
    long long int test = n;
    long long int mod = pow(10, 9) + 7;
    string s2 = s;
    long long int l = 0;
    long long int forward = n;
    while (l != x) {
      l++;
      forward--;
      if (s2[l - 1] - 48 > 1) {
        test = (test + (forward * (s2[l - 1] - 49)) % mod) % mod;
        forward = (forward + (forward * (s2[l - 1] - 49)) % mod) % mod;
        if (s2.length() < x) {
          string temp = "";
          for (int i = l; i < s2.length(); i++) temp += s2[i];
          if (s2[l - 1] - 48 == 2) {
            s2 += temp;
          } else {
            s2 += temp;
            s2 += temp;
          }
        }
      }
    }
    cout << test << endl;
  }
  return 0;
}
