#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include // #include // #include // #include // using namespace __gnu_pbds; // #include // namespace multiprecisioninteger = boost::multiprecision; // using cint=multiprecisioninteger::cpp_int; using namespace std; using ll=long long; using datas=pair; using ddatas=pair; using tdata=pair; using vec=vector; using mat=vector; using pvec=vector; using pmat=vector; // using llset=tree,rb_tree_tag,tree_order_statistics_node_update>; #define For(i,a,b) for(i=a;i<(ll)b;++i) #define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i) #define rep(i,N) For(i,0,N) #define rep1(i,N) For(i,1,N) #define brep(i,N) bFor(i,N,0) #define brep1(i,N) bFor(i,N,1) #define all(v) (v).begin(),(v).end() #define allr(v) (v).rbegin(),(v).rend() #define vsort(v) sort(all(v)) #define vrsort(v) sort(allr(v)) #define uniq(v) vsort(v);(v).erase(unique(all(v)),(v).end()) #define endl "\n" #define popcount __builtin_popcountll #define eb emplace_back #define print(x) cout< ostream& operator<<(ostream& os,const pair& p){return os<<"("< ostream& operator<<(ostream& os,const vector& v){ os<<"{";bool f=false; for(auto& x:v){if(f)os<<",";os< ostream& operator<<(ostream& os,const set& v){ os<<"{";bool f=false; for(auto& x:v){if(f)os<<",";os< ostream& operator<<(ostream& os,const map& v){ os<<"{";bool f=false; for(auto& x:v){if(f)os<<",";os< inline bool chmax(T& a,T b){bool x=a inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} #ifdef DEBUG void debugg(){cout<void debugg(const T& x,const Args&... args){cout<<" "< struct mf_graph{ public: mf_graph():_n(0){} mf_graph(int n):_n(n),g(n){} int add_edge(int from,int to,Cap cap){ assert(0<=from&&from<_n); assert(0<=to&&to<_n); assert(0<=cap); int m=int(pos.size()); pos.push_back({from,int(g[from].size())}); int from_id=int(g[from].size()); int to_id=int(g[to].size())+int(from==to); g[from].push_back(_edge{to,to_id,cap}); g[to].push_back(_edge{from,from_id,0}); return m; } struct edge { int from,to; Cap cap,flow; }; edge get_edge(int i){ assert(0<=i&&i edges(){ vector result; for(int i=0;i::max()); } Cap flow(int s,int t,Cap flow_limit){ assert(0<=s&&s<_n); assert(0<=t&&t<_n); assert(s!=t); vector level(_n),iter(_n); simple_queue que; auto bfs=[&](){ fill(level.begin(),level.end(),-1); level[s]=0; que.clear(); que.push(s); while(!que.empty()){ int v=que.front(); que.pop(); for(auto e:g[v]){ if(e.cap==0||level[e.to]>=0)continue; level[e.to]=level[v]+1; if(e.to==t)return; que.push(e.to); } } }; auto dfs=[&](auto self,int v,Cap up){ if(v==s)return up; Cap res=0; int level_v=level[v]; for(int&i=iter[v]; i min_cut(int s){ vector visited(_n); simple_queue que; que.push(s); while(!que.empty()){ int p=que.front(); que.pop(); visited[p]=true; for(auto e:g[p]){ if(e.cap&&!visited[e.to]){ visited[e.to]=true; que.push(e.to); } } } return visited; } private: int _n; struct _edge{ int to,rev; Cap cap; }; vector> pos; vector> g; templatestruct simple_queue{ vector payload; int pos=0; void reserve(int n){payload.reserve(n);} int size() const{return int(payload.size())-pos;} bool empty() const{return pos==int(payload.size());} void push(const T& t){payload.push_back(t);} T& front(){return payload[pos];} void clear(){ payload.clear(); pos=0; } void pop(){++pos;} }; }; ll H,W; bool check(vector g){ ll i,j,cnt=0; rep(i,H)rep(j,W)cnt+=g[i][j]=='#'; if(cnt&1)return false; cnt/=2; mf_graph fl(H*W+2); rep(i,H)rep(j,W){ if(g[i][j]=='#'){ if(i&&g[i-1][j]=='#'){ if((i+j)&1)fl.add_edge((i-1)*W+j,i*W+j,1); else fl.add_edge(i*W+j,(i-1)*W+j,1); } if(j&&g[i][j-1]=='#'){ if((i+j)&1)fl.add_edge(i*W+j-1,i*W+j,1); else fl.add_edge(i*W+j,i*W+j-1,1); } } if((i+j)&1)fl.add_edge(i*W+j,H*W+1,1); else fl.add_edge(H*W,i*W+j,1); } if(cnt!=fl.flow(H*W,H*W+1))return false; printyes; vector pr(H,string(W,'.')); char now='a'; for(auto x:fl.edges()){ if(max(x.from,x.to)>=H*W||!x.flow)continue; pr[x.from/W][x.from%W]=pr[x.to/W][x.to%W]=now++; if(now>'z')now='A'; } rep(i,H)print(pr[i]); return true; } int main(){ startupcpp(); // int codeforces;cin>>codeforces;while(codeforces--){ ll i,j,cnt=0; cin>>H>>W; vector v(H); { bool f=false; rep(i,H){ cin>>v[i]; rep(j,W)if(v[i][j]=='#')break; if(v[i]==string(W,'#')){ printno; return 0; } if(j g(H,string(W,'#')); j=0; rep(i,H)if(bit>>i&1)g[i]=v[j++]; i=0; while(1){ if(check(g))return 0; rep(j,W){ if(g[i][j]=='.')break; g[i][j]='.'; } if(j