// Arup Guha
// 3/5/2022
// Solution to 2021 SER D2 Problem: Tetris Generation

import java.util.*;
import java.io.*;

public class tetris {
	
	public static void main(String[] args) throws Exception {
	
		BufferedReader stdin =  new BufferedReader(new InputStreamReader(System.in));
		int nC = Integer.parseInt(stdin.readLine());
		
		// Process all cases.
		for (int loop=0; loop<nC; loop++) {
		
			// Get String
			char[] s = stdin.readLine().toCharArray();
			int n = s.length;
				
			// See if any potential break works.
			int res = 0;
			for (int i=0; i<Math.min(n,7); i++) {
				res = Math.max(res, go(s, i));
				if (res == 1) break;
			}
			
			// Ta da!
			System.out.println(res);
		}
	}
	
	// Returns 1 if dividing s with the first div characters works, 0 otherwise.
	public static int go(char[] s, int div) {
	
		// Check first group.
		int[] freq = new int[26];
		for (int i=0; i<div; i++) {
			freq[s[i]-'A']++;
			if (freq[s[i]-'A'] > 1) return 0;
		}
		
		// s is the starter.
		for (int x=div; x<s.length; x+=7) {
		
			// Reset for these 7.
			Arrays.fill(freq, 0);
			
			// Do 7 in a row.
			for (int i=0,j=x; i<7 && j<s.length; i++,j++) {
				freq[s[j]-'A']++;
				if (freq[s[j]-'A'] > 1) return 0;
			}
		}
		
		// If we get here, we are good.
		return 1;
	}
}