/**********************************************************************
 * 
 * After reading an id string we first determine the position of the
 * missing digit. Then we simply try all ten possible digits in that
 * position, checking whether the checksum ends with a zero.
 * 
 * Instead of trying and checking all possibilities, we could also
 * compute the missing digit directly using the extended Euclidean
 * algorithm to find the multiplicative inverse of the "missing"
 * checksum part. Imagine the example but with a missing digit:
 * 
 *     id number :   1  3  9  0  ?  7  2
 *     factors   :   9  7  3  9  7  3  9
 *     products  :   9 21 27  0  ? 21 18
 * 
 * The checksum without the contribution of the missing digit is 96,
 * so we'd like to add a product that ends with 4. In other words,
 * which digit multiplied with factor 7 results in 4 modulo 10?
 * 
 * However, the numbers are so small here that tring all possibilities
 * takes almost no time and programming the multiplicative inverse
 * would be complete overkill (though in Java, it's already in the
 * standard library as java.math.BigInteger.modInverse(...) so we
 * could use that).
 * 
 **********************************************************************/

#include <iostream>
#include <string>
using namespace std;

int main () {
  int SC;
  cin >> SC;
  for( int S=1; S<=SC; S++ ){
    cout << "Scenario #" << S << ":" << endl;
    
    string id;
    cin >> id;
    
    //--- Find the missing digit.
    int miss = 0;
    while( id[miss] != '?' )
      miss++;
    
    //--- Try and check all possibilities.
    for( id[miss]='0'; ; id[miss]++ ){
      int sum = 0;
      for( int i=0; i<(int)id.size(); i++ )
	sum += (id[i] - '0') * ("793"[(id.size()-i)%3] - '0');
      if( sum % 10 == 0 )
	break;
    }
    
    //--- Answer.
    cout << id << endl << endl;
  }
}
