package codeJam;
import java.util.Scanner;
public class CountingSheep {
	static Scanner sc=new Scanner(System.in);
	
	public static boolean checkWholeBinaryArray(boolean[] ar){
		boolean ans=true;
		for(int x=0;x<10;x++) ans=ans&&ar[x];
	return ans;
	}
	
	public static void main(String[] args){
		int testCases=Integer.parseInt(sc.nextLine());
		for(int caseNo=0;caseNo<testCases;caseNo++){
			int x=Integer.parseInt(sc.nextLine());
			runOnce(caseNo,x);
		}
	}

	public static void runOnce(int caseNo, int n){
		if(n==0) System.out.println("Case #"+(caseNo+1)+": "+"INSOMNIA");
		else{
			boolean[] check=new boolean[10];
			int i=1;
			while(!checkWholeBinaryArray(check)){
				if(i!=1) n=n*i/(i-1);
				else n=n*i;
				check=updateBooleanArray(check,n);
				i++;
			}
			System.out.println("Case #"+(caseNo+1)+": "+n);
		}
	}
	
	public static boolean[] updateBooleanArray(boolean[] ar,int x){
		String s=x+"";
		//System.out.print(s+" ");
		for(int y=0;y<s.length();y++) ar[Integer.parseInt(s.substring(y, y+1))]=true;
		return ar;
	}
	
	
	
}

@@ -1,8 +1,645 @@
+/*%0D%0A%0D%0ACopyright Hackers' Club, University Of Peradeniya%0D%0AAuthor : Gihan Chanaka Jayatilaka (E/4/158)%0D%0ALicensed under the Apache License, Version 2.0 (the %22License%22);%0D%0Ayou may not use this file except in compliance with the License.%0D%0AYou may obtain a copy of the License at *%0D%0Ahttp://www.apache.org/licenses/LICENSE-2.0 *%0D%0AUnless required by applicable law or agreed to in writing, software%0D%0Adistributed under the License is distributed on an %22AS IS%22 BASIS,%0D%0AWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0D%0ASee the License for the specific language governing permissions and%0D%0Alimitations under the License.%0D%0A*/%0D%0A
 package 

Update CountingSheep.java