import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int x=sc.nextInt();
		while(x-->0) {
			int t=0,c=0;
			int n=sc.nextInt();
			String a=sc.next();
			for(int i=0;i<a.length()-1;i++) {
				if(n!=1&&a.charAt(i)-'0'==14&&a.charAt(i+1)-'0'==12)
					t++;
				else if(n!=1&&a.charAt(i)-'0'==12&&a.charAt(i+1)-'0'==14)
					c++;
			}
			if(n==1)
				System.out.println(0);
			else if(t>=c)
				System.out.println(0);
			else if(c>t)
				System.out.println(1);
		}
	}
}