#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    unsigned x;
    char s[1000];
    cin >> x >> s;
    unsigned long long l = 0, size = strlen(s), step = 0, max = 1e9 + 7;
    int p = x;
    vector<char> st(s, s + size);
    while (p-- > 0) {
      ++l;
      int t = st[l - 1] - '0';
      step = ((t - 1) * ((size - l) % max)) % max;
      size = (size + step) % max;
      if (st.size() < x) {
        vector<char> sub(st.begin() + l, st.end());
        while (--t > 0) st.insert(st.end(), sub.begin(), sub.end());
      }
    }
    cout << size << "\n";
  }
}
