#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  a = a % 1000000007;
  if (b == 0) return 1LL;
  if (b == 1) return a;
  long long int temp = power(a, b / 2);
  if (b % 2 == 0) return (temp * temp) % 1000000007;
  return (((a * temp) % 1000000007) * temp) % 1000000007;
}
void dfs(vector<vector<long long int> > &graph, int mark[], long long int i) {
  mark[i] = 1;
  for (long long int j = 0; j < (long long int)graph[i].size(); j++)
    if (mark[graph[i][j]] == 0) dfs(graph, mark, graph[i][j]);
}
int check(string a, string b) {
  long long int i;
  for (i = 0; i < (long long int)b.length(); i++) {
    if (a[(long long int)a.length() - 1 - i] !=
        b[(long long int)b.length() - 1 - i])
      return 0;
  }
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    long long int n, x, mark = -1, leftValue = 0;
    cin >> x;
    string s;
    cin >> s;
    n = s.length();
    while ((long long int)s.size() < x) {
      mark++;
      leftValue = (long long int)(s[mark] - '0');
      long long int cnt = (s.size() - 1 - mark) * (leftValue - 1), j;
      j = mark + 1;
      long long int markEnd = s.size(), i;
      for (i = 0; i < cnt and (long long int) s.size() < x; i++) {
        s.push_back(s[j]);
        j++;
        if (j == markEnd) j = mark + 1;
      }
    }
    leftValue = 0, mark = 0;
    long long int totalSize = n;
    while (mark < x) {
      leftValue = ((long long int)(s[mark] - '0')) % 1000000007;
      long long int cnt = (((totalSize - 1 - mark + 1000000007) % 1000000007) *
                           (leftValue - 1)) %
                          1000000007;
      totalSize = (totalSize + cnt) % 1000000007;
      mark++;
    }
    cout << totalSize << endl;
  }
}
