#include <bits/stdc++.h>
using namespace std;
long long x;
char s[5005];
int main() {
  int t;
  cin >> t;
  while (t--) {
    scanf("%d", &x);
    scanf("%s", s + 1);
    vector<int> v;
    v.clear();
    v.push_back(0);
    int len = strlen(s + 1);
    for (int i = 1; i <= len; i++) v.push_back(s[i] - '0');
    long long ans = v.size() - 1;
    for (int i = 1; i <= x; i++) {
      int loop = v[i] - 1;
      if (v.size() - 1 <= x) {
        int size = v.size();
        while (loop--) {
          for (int j = i + 1; j < size; j++) v.push_back(v[j]);
        }
        ans = v.size() - 1;
      } else {
        ans = (ans + (ans - i + 1000000007) * loop + 1000000007) % 1000000007;
      }
    }
    cout << ans << '\n';
  }
}
