#include using namespace std; int n,m; map alph; void nextELEMENT(char ch[3]){ if(ch[0] == '9') ch[0] = ch[1] = 'A'; ch[0]++; ch[1]++; } int comp(char a){ if(a != 'A' && a != 'B' && a != 'C' && a != 'D' && a != 'E' && a != 'F') return(a-'0'); else return(alph[a]); } void find(char ch[3]){ char start[3]; ch[2] = '\0'; start[0] = ch[0]; start[1] = ch[0]; start[2] = '\0'; char stop[3]; stop[0] = ch[1]; stop[1] = ch[1]; stop[2] = '\0'; if(ch[0] == ch[1]) return; int oneV = comp(start[0]) * 16 + comp(start[1]); int twoV = comp(stop[0]) * 16 + comp(stop[1]); if( oneV > twoV) { char aux[3]; aux[0] = start[0]; aux[1] = start[1]; start[0] = stop[0]; start[1] = stop[1]; stop[0] = aux[0]; stop[1] = aux[1]; } char setted[3]; setted[2] = '\0'; int MIN = 1e9; //cout << start << ' ' << stop << endl; int always = comp(ch[0]) * 16 + comp(ch[1]); //cout << ch << ' ' << always << endl; while( start[0] != stop[0] || start[1] != stop[1] ){ //cout << start[0] << ' ' << start[1] << endl; int curr = comp(start[0]) * 16 + comp(start[1]); //cout << curr << endl; int diff = abs(always - curr); if(diff < MIN && start[0] == start[1]){ setted[0] = start[0]; setted[1] = start[1]; MIN = diff; } nextELEMENT(start); } // cout << start[0] << ' ' << start[1] << endl; int curr = comp(start[0]) * 16 + comp(start[1]); // cout << curr << endl; int diff = abs(always - curr); if(diff < MIN && start[0] == start[1]){ setted[0] = start[0]; setted[1] = start[1]; MIN = diff; } ch[0] = setted[0]; ch[1] = setted[1]; } int main(){ // ifstream cin("input.in"); alph['A'] = 10; alph['B'] = 11; alph['C'] = 12; alph['D'] = 13; alph['E'] = 14; alph['F'] = 15; cin >> n >> m; for(int i=0; i> diez; cin >> ch0[0] >> ch0[1]; cin >> ch1[0] >> ch1[1]; cin >> ch2[0] >> ch2[1]; find(ch0); find(ch1); find(ch2); cout << diez << ch0[0] << ch1[0] << ch2[0] << ' '; } cout << endl; } return(0); }