#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int N = 2e3 + 2;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int x;
    scanf("%d", &x);
    string s;
    cin >> s;
    int ans = s.size();
    for (int l = 1; l < (int)x + 1; l++) {
      if (s.size() < x) {
        if (s[l - 1] == '2') {
          string temp = s.substr(l);
          s.append(temp);
        } else if (s[l - 1] == '3') {
          string temp = s.substr(l);
          s.append(temp);
          s.append(temp);
        }
      }
      int lastdig = s[l - 1] - '0';
      ans = (l + 1ll * (ans - l) * lastdig) % mod;
      if (ans < 0) ans += mod;
    }
    printf("%d\n", (int)(int)ans % mod);
  }
  return 0;
}
