M = int(1e9+7)
n = int(input())

while n>0:
  n -= 1
  x = int(input())
  s = input()
  idx = 0
  length = len(s)
  while length < x:
    t = ord(s[idx])-ord('1')
    s += s[idx+1:]*t
    length += (length-idx-1)*t
    idx += 1
  while idx != x:
    t = ord(s[idx])-ord('1')
    length += ((length-idx-1)*t)%M
    idx += 1
  print(length%M)