package manila; import java.io.*; import java.util.*; /* >diff groups.out out 119c119 < 1, 3, 5, 7, 8, 10, 13, 14, 16, 19, 20, 23 --- > 1, 3, 4, 7, 9, 10, 13, 15, 16, 18, 20, 23 149,150c149,150 < 1, 3, 5, 7, 8, 10, 13, 14, 16, 19, 20, 23 < *** 29 --- > 1, 3, 4, 7, 9, 10, 13, 15, 16, 18, 20, 23 > *** 29 */ /** * @author Tomoya Taniguchi */ public class D { public static int n; public static int zero; public static int selectNum; public static int count; public static int[][] mat; public static void loop(int depth,int[] table,int selected) { if(selected == selectNum) { check(table); return; } if(depth == n)return; if(depth == zero) { loop(depth+1,table,selected); return; } table[depth] = 1; loop(depth + 1,table,selected + 1); table[depth] = 0; loop(depth + 1,table,selected); } public static void check(int[] table) { for(int i = 0;i < n;i++) if(table[i] == 1) { boolean inverseFlag = false; for(int j = 0;j < n;j++) if(table[j] == 1) { if(table[mat[i][j]] != 1) return; if(mat[i][j] == zero) inverseFlag = true; } if(!inverseFlag) return; } print(table); } public static void print(int[] table) { boolean flag = false; for(int i = 0;i < n;i++) if(table[i] == 1) { if(flag) System.out.print(", " + i); else { flag = true; System.out.print("" + i); } } System.out.println(""); count++; } public static void main(String[] args)throws Exception { BufferedReader r = new BufferedReader(new FileReader("groups.in")); int l = Integer.parseInt(r.readLine()); for(int loop = 0;loop < l;loop++) { n = Integer.parseInt(r.readLine()); mat = new int[n][]; int[] ze = new int[n]; for(int i = 0;i < n;i++) ze[i] = i; for(int i = 0;i < n;i++) { mat[i] = new int[n]; StringTokenizer st = new StringTokenizer(r.readLine(),","); for(int j = 0;j < n;j++) { mat[i][j] = Integer.parseInt(st.nextToken()); } if(Arrays.equals(mat[i],ze)) zero = i; } count = 0; for(int i = 1;i < n-1;i++) { if(n % i == 0) { int[] param = new int[n]; Arrays.fill(param,0); param[zero] = 1; selectNum = i; loop(0,param,1); } } System.out.println("*** " + count); } } }