#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <algorithm>
#include <functional>
#include <chrono>

// 修正

template <typename unit, typename Clock = std::chrono::high_resolution_clock>
struct StopWatch {
    typename Clock::time_point start;
    StopWatch() : start(Clock::now()) {}

	unsigned getDifference(){
		 return std::chrono::duration_cast<unit>(Clock::now() - start).count();
	}
};

template <typename Integer>
struct Resolver {
	using WordType = std::vector<Integer>;
	
	std::string line;
	std::array<WordType,3> words;
	std::string operatorSymbol;

    std::vector<Integer> combinationMap;
	std::map<char,Integer> charMap;

	Resolver(std::string& aLine) : line(aLine) {
		std::array<std::string, 3> rawWords;
		std::string eq;
		std::stringstream(line) >> rawWords[0] >> operatorSymbol >>  rawWords[1] >> eq >> rawWords[2];
		
		{
			int i = 0;
			for( auto rawWord: rawWords )
				for( auto ch: rawWord )
					if(charMap.count(ch) <= 0)
						charMap[ch] = i++;
		}

		for( int i = 0; i < rawWords.size(); i++ ){
			std::vector<Integer> word;
			for( auto ch: rawWords[i] )
				word.push_back( charMap[ch] );

			words[i] = word;
		}
	}
	
	std::string getResultString(){
		std::string buffer;
		std::stringstream stream(buffer);
		stream << toInteger(words[0]) << " " << operatorSymbol << " " << toInteger(words[1])
		       << " = " << toInteger(words[2]);

		return stream.str();
	}


	bool validate(){
		bool found;
		Integer n1 = toInteger(words[0]);
		Integer n2 = toInteger(words[1]);
		Integer n3 = toInteger(words[2]);
		
		switch(operatorSymbol[0]){
			default:
			case '+': found = (n1 + n2) == n3; break;
			case '-': found = (n1 - n2) == n3; break;
			case '*': found = (n1 * n2) == n3; break;
			case '/': found = (n1 / n2) == n3; break;
		}
		if( !found )
			return false;

		for( auto word: words )
			if( combinationMap[ word[0] ] == 0 )
				return false;
			
		return true;
				
	}

	Integer toInteger(std::vector<Integer>& word){
		return std::accumulate( word.begin(), word.end(), 0, [&](Integer prev, Integer ch){
			return (prev * 10) + combinationMap[ch];
		});
	}
	
	StopWatch<std::chrono::milliseconds> stopWatch;
	void print(){
		std::cout << line << " -> " << getResultString()
		          << " (in " << stopWatch.getDifference() << "ms)"
		          << std::endl;
	}

	void resolve(){
	    std::vector<bool> taken(10);
    	std::fill(taken.end() - charMap.size(), taken.end() , true);

   		combinationMap = std::vector<Integer>( charMap.size() );

    	do {
    		int n = 0;
   	        for (int i = 0; i < 10; ++i)
	            if ( taken[i] )
		            combinationMap[n++] = i;
			
			do if( validate() )
				print();
		    while (std::next_permutation(combinationMap.begin(),combinationMap.end()));

	    }
	    while (std::next_permutation(taken.begin(), taken.end()));
	}
};

int main() {
	for( std::string line; std::getline(std::cin,line); )
		Resolver<int>(line).resolve();
		
	return 0;
}