#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
char in[1000100], store[3000100];
long long get_ans(int x, int len) {
  for (int i = 1; i <= len; i++) store[i] = in[i];
  long long ret = len, last = len, right = len;
  for (int i = 1; i <= x; i++) {
    right = (right + mod - 1) % mod;
    if (store[i] == '1')
      continue;
    else if (store[i] == '2') {
      ret += right;
      ret %= mod;
      if (last <= x) {
        for (int j = 1; j <= right; j++) {
          char s = store[j + i];
          store[i + right + j] = s;
        }
        last += right;
      }
      right *= 2;
      right %= mod;
    } else if (store[i] == '3') {
      ret += right * 2;
      ret %= mod;
      if (last <= x) {
        for (int j = 1; j <= right; j++) {
          char s = store[j + i];
          store[i + right + j] = s;
          store[i + right * 2 + j] = s;
        }
        last += right * 2;
      }
      right *= 3;
      right %= mod;
    }
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int x;
    cin >> x;
    cin >> in + 1;
    int len = strlen(in + 1);
    long long ans = get_ans(x, len);
    cout << ans << endl;
  }
  return 0;
}
