for _ in range(int(input())):
  x=int(input())
  s=input()
  i=0
  while len(s)<x:
    s+=s[i+1:]*(int(s[i])-1)
    i+=1
  ans=len(s)
  for j in range(i,x):
    ans+=(ans-j-1)*(int(s[j])-1)
    ans%=10**9+7
  print(ans)