input = raw_input

MOD = int(1e9+7)

T = int(input())

for _ in range(T):
  x = int(input())
  s = list(input())
  sz = len(s)

  i = 1
  while len(s) < x:
    if s[i-1] != '1':
      subs = s[i:]
      s += subs * (int(s[i-1])-1)
    i += 1
  i = 1
  for _ in range(x):
    sz = i + (sz - i) * int(s[i-1])
    sz %= MOD
    i += 1
  print(sz%MOD)

