#include <bits/stdc++.h>
int T, x;
char s[4000005];
int length, cursor;
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d\n", &x);
    scanf("%s", s + 1);
    length = strlen(s + 1);
    cursor = 0;
    bool moded = 0;
    while (cursor < x) {
      cursor++;
      if (moded) {
        long long t1 = length - cursor;
        if (t1 < 0) t1 += 1000000007;
        t1 *= (s[cursor] - '0');
        t1 += cursor;
        t1 %= 1000000007;
        length = (int)t1;
      } else {
        int old_len = length;
        for (int rep = s[cursor] - '0'; rep > 1; rep--) {
          for (int j = cursor + 1; j <= old_len; j++) s[++length] = s[j];
        }
        if (length > 1000000) moded = true;
      }
    }
    printf("%d\n", length);
  }
  return 0;
}
