n=int(input())
mod=((10**9)+7)
for j in range(n):
  x=int(input())
  sleft=str(input())
  length=len(sleft)
  l=0
  while len(sleft)<x:
    l+=1
    if sleft[l-1]=="2":
      sright=sleft[l:]
      sleft+=sright
    elif sleft[l-1]=="3":
      sright=sleft[l:]
      sleft+=sright*2
    else:
      continue
    
  for l in range(1,x+1):
    mult=int(sleft[l-1])
    length=l+mult*((length-l)%mod)
    length=length%mod
    
  print(length)
  