#include <bits/stdc++.h>
using namespace std;
int main() {
  long long tc = 0;
  cin >> tc;
  while (tc > 0) {
    long long x = 0;
    cin >> x;
    string s = "";
    cin >> s;
    long long n = s.length();
    long long temp = 1;
    string c = "";
    long long times = 0;
    long long temp2 = n - 1;
    long long g = x;
    while (x > 0) {
      times = s[temp - 1] - '0' - 1;
      if (n <= g) {
        if (times == 1) {
          for (long long i = temp; i < temp + temp2; i++) {
            s += s[i];
          }
          n = s.length();
        }
        if (times == 2) {
          for (long long i = temp; i < temp + temp2; i++) {
            s += s[i];
          }
          for (long long i = temp; i < temp + temp2; i++) {
            s += s[i];
          }
          n = s.length();
        }
      } else {
        n += (times * temp2 % 1000000007);
      }
      temp++;
      temp2 = n - (temp);
      x--;
    }
    cout << n % 1000000007 << "\n";
    tc--;
  }
  return 0;
}
