public class alien_number{
	private String input,source,target;
	
	public alien_number(String inputz,String sourcez,String targetz){
		input=inputz;
		source=sourcez;
		target=targetz;	
	}
	
	public String convert(){
		String ans=new String();
		String tans=new String();
		String source_org="";
		int source_dec=0;
		//change to number format in the source power
		for(int i=0;i<input.length();i++){
			for(int j=0;j<source.length();j++)
				if(input.charAt(i)==source.charAt(j))
					source_org=source_org+j;
		}
		//change to decimal
		for(int i=0;i<source_org.length();i++){
			int temp=Character.getNumericValue(source_org.charAt(i));
			source_dec+=temp*(Math.pow(source.length(),(source_org.length()-1-i)));
		}
		
		//change to target in num
		do{
			tans=Integer.toString(source_dec%target.length())+tans;
			if(source_dec/target.length()!=0)
				source_dec=source_dec/target.length();
			else
				source_dec=0;	
		}while(source_dec!=0);
		
		//final convert to target language
		for(int i=0;i<tans.length();i++){
			ans+=target.charAt(Character.getNumericValue(tans.charAt(i)));
		}
		return ans;
	}
	
	public static void main(String[] args){
		alien_number al=new alien_number("Foo","oF8","0123456789");
		System.out.println(al.convert());
	}
}
