import java.util.Scanner;

public class que3 {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int test = scn.nextInt();

		for (int t = 1; t <= test; t++) {
			int x = scn.nextInt();
			String s = scn.next();
			StringBuilder sb = new StringBuilder(s);

			
			long ans = sb.length();
			int mod = 1000000007;
			boolean f=false;
			long last=sb.length();
			for (int i = 0; i < x; i++) {
				int val = sb.charAt(i)-'0';
				  int  l=i+1;
				 if(val==2){
					
					long tl= (last+(last-l+mod)%mod)%mod;
					ans=tl;
					last=tl;
					if(f){
						continue;
					}
					if(x<=sb.length()){
						f=true;
						continue;
					}
					if(tl<=x){
						sb.append(sb.substring(l));
					}else{
						
						if(l+x-sb.length()>sb.length()){
							sb.append(sb.substring(l));
						}else{
							System.out.println(l+x-sb.length());
						sb.append(sb.substring(l,l+x-sb.length()));
						f=true;
						}
					}
					}
				 else if(val==3){
					     
						long tl=(last+(2*((last-l+mod)%mod)%mod))%mod;
						ans=tl;
						last=tl;
						 if(f==true){
							 continue;
						 }
						 else if(tl<=x){
							 String ls=sb.substring(l);
							sb.append(sb.substring(l));
							sb.append(ls);
						}else if(x<=sb.length()){
							f=true;
							continue;
						}
						 else{
							
							if(l+x-sb.length()>sb.length()){
								sb.append(sb.substring(l));
							}else{
								
							sb.append(sb.substring(l,l+x-sb.length()));
							f=true;
							}
						}
					}
				 }
System.out.println(ans);
			}
		}
	}


