INF = 10**10
def main():
    print = out.append
    ''' Cook your dish here! '''
    x = get_int()
    P = 10 ** 9 + 7
    li = list(map(int, input()))
    ptr = 0
    res = len(li)
    while ptr < x:
        ptr += 1
        if len(li) < x and li[ptr-1]>1:
            li += li[ptr:] * (li[ptr - 1] - 1)
        res -= 1
        res = (res * li[ptr - 1]) % P
        #print("while")
        # print(res, ptr, li)
    print((res + ptr) % P)



''' Coded with love at Satyam Kumar, India '''
import sys
#from collections import defaultdict, Counter
#from functools import reduce
#import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
#main()
[main() for _ in range(int(input()))]
print(*out, sep='\n')


