#include #include #include #include #include using namespace std; map myMap; int main() { #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); #endif // ONLINE_JUDGE int N, M; cin >> N >> M; for(char i = '0'; i <= '9'; ++i) { myMap[i] = i - '0'; } for(char i = 'A'; i <= 'F'; ++i) { myMap[i] = i - 'A' + 10; } string str = ""; for(int i = 1; i <= N; ++i) { for(int j = 1; j <= M; ++j) { cin >> str; int R = myMap[str[1]] * 16 + myMap[str[2]]; int G = myMap[str[3]] * 16 + myMap[str[4]]; int B = myMap[str[5]] * 16 + myMap[str[6]]; int x = myMap[str[1]] * 16 + myMap[str[1]]; int y = x - 1; char nxt = str[1]; if(str[1] != 'F') { y = (myMap[str[1]] + 1) * 16 + myMap[str[1]] + 1; nxt = (str[1] == '9' ? 'A' : str[1] + 1); } if(abs(x - R) < abs(y - R)) { str[2] = str[1]; } else { str[1] = nxt; } x = myMap[str[3]] * 16 + myMap[str[3]]; y = x - 1; nxt = str[3]; if(str[3] != 'F') { y = (myMap[str[3]] + 1) * 16 + myMap[str[3]] + 1; nxt = (str[3] == '9' ? 'A' : str[3] + 1); } if(abs(x - G) < abs(y - G)) { str[4] = str[3]; } else { str[3] = nxt; } x = myMap[str[5]] * 16 + myMap[str[5]]; y = x - 1; nxt = str[5]; if(str[5] != 'F') { y = (myMap[str[5]] + 1) * 16 + myMap[str[5]] + 1; nxt = (str[5] == '9' ? 'A' : str[5] + 1); } if(abs(x - B) < abs(y - B)) { str[6] = str[5]; } else { str[5] = nxt; } string rez = ""; rez = rez + str[0] + str[1] + str[3] + str[5]; cout << rez << ' '; } cout << '\n'; } return 0; }