from collections import Counter, defaultdict, deque
import bisect
from sys import stdin, stdout,setrecursionlimit
from itertools import repeat


# sys.stdin = open('input')
# n, k = map(int, raw_input().split())
# da = map(int, raw_input().split())
# db = map(int, raw_input().split())
def main():
    q = map(int, raw_input().split())[0]
    mod = int(1e9+7)
    for iq in range(q):
        x = map(int, raw_input().split())[0]
        da = map(int, raw_input().strip())
        l = len(da)
        for i in range(x):
            for ti in range(da[i]):
                if len(da) >= x:
                    break
                for idx in range(i+1, l):
                    if len(da) >= x:
                        break
                    da.append(da[idx])
            l = i+1+da[i]*(l-i-1)
            l %= mod
            # print da
        print l









main()
