#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 10005;
const int mod = 1e9 + 7;
struct disj{
int pa[MAXN];
void init(int n){
iota(pa, pa + n + 1, 0);
}
int find(int x){
return pa[x] = (pa[x] == x ? x : find(pa[x]));
}
bool uni(int p, int q){
p = find(p);
q = find(q);
if(p == q) return 0;
pa[q] = p; return 1;
}
}disj;
int K;
pi a[MAXN][2];
int chk[MAXN][2];
pi par[MAXN][2];
namespace graph{
vector<pi> gph[10005];
int par[10005], pae[10005];
void dfs(int x, int p){
for(auto &i : gph[x]){
if(i.second != p){
par[i.second] = x;
pae[i.second] = i.first;
dfs(i.second, x);
}
}
}
void clear(){
for(int i=0; i<K; i++){
for(int j=0; j<2; j++){
gph[a[i][j].first].clear();
gph[a[i][j].second].clear();
par[a[i][j].first] = -1;
par[a[i][j].second] = -1;
}
}
}
vector<pi> inCycle(pi x){
for(int i=0; i<K; i++){
for(int j=0; j<2; j++){
if(chk[i][j]){
int w = i * 2 + j;
int l = a[i][j].first;
int r = a[i][j].second;
gph[l].emplace_back(w, r);
gph[r].emplace_back(w, l);
}
}
}
dfs(x.first, -1);
if(par[x.second] == -1){
clear();
return vector<pi>();
}
vector<pi> ret;
for(int y = x.second; y != x.first; y = par[y]){
ret.emplace_back(pae[y] / 2, pae[y] % 2);
}
clear();
return ret;
}
}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int n, m;
char str[105][105];
int vis[105][105];
bool ok(int x, int y){ return 0 <= x && x < n && 0 <= y && y < m; }
void dfs(int x, int y, int c){
vis[x][y] = c;
for(int i=0; i<4; i++){
if(ok(x + dx[i], y + dy[i]) &&
!vis[x + dx[i]][y + dy[i]] &&
str[x][y] == str[x + dx[i]][y + dy[i]]){
dfs(x + dx[i], y + dy[i], c);
}
}
}
char dap[105][105];
int main(){
int tc;
scanf("%d",&tc);
memset(graph::par, -1, sizeof(graph::par));
for(int i=1; i<=tc; i++){
memset(vis, 0, sizeof(vis));
memset(chk, 0, sizeof(chk));
memset(dap, 0, sizeof(dap));
int cnt = 0;
scanf("%d %d",&n,&m);
for(int i=0; i<n; i++) scanf("%s", str[i]);
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
if(!vis[i][j]){
++cnt;
dfs(i, j, cnt);
}
}
}
if(cnt == 1){
printf("Case #%d: POSSIBLE\n", i);
for(int i=0; i<n-1; i++){
for(int j=0; j<m-1; j++) putchar('/');
puts("");
}
continue;
}
int answ = 0;
disj.init(n * m);
for(int i=1; i<n; i++){
for(int j=1; j<m; j++){
if(str[i-1][j-1] == str[i][j] && str[i-1][j] == str[i][j-1]){
continue;
}
if(str[i-1][j-1] != str[i][j] && str[i-1][j] != str[i][j-1]){
dap[i-1][j-1] = '.';
}
else if(str[i-1][j-1] != str[i][j]){
dap[i-1][j-1] = '/';
answ += disj.uni(vis[i-1][j], vis[i][j-1]);
}
else{
dap[i-1][j-1] = '\\';
answ += disj.uni(vis[i-1][j-1], vis[i][j]);
}
}
}
K = 0;
for(int i=1; i<n; i++){
for(int j=1; j<m; j++){
if(dap[i-1][j-1]) continue;
int s1 = disj.find(vis[i-1][j-1]);
int e1 = disj.find(vis[i][j]);
int s2 = disj.find(vis[i-1][j]);
int e2 = disj.find(vis[i][j-1]);
a[K][0] = pi(s1, e1);
a[K][1] = pi(s2, e2);
K++;
}
}
for(int i=0; i<K; i++){
bool vis[MAXN][2] = {};
queue<pi> que;
for(int j=0; j<2; j++){
que.emplace(i, j);
vis[i][j] = 1;
par[i][j] = pi(-1, -1);
}
while(!que.empty()){
auto x = que.front();
que.pop();
if(chk[x.first][x.second] == 0){
auto edg = a[x.first][x.second];
if(edg.first == edg.second) continue;
auto adj = graph::inCycle(edg);
if(adj.empty()){
for(pi i = x; i != pi(-1, -1); i = par[i.first][i.second]){
chk[i.first][i.second] ^= 1;
}
answ++;
break;
}
else{
for(auto &y : adj){
if(!vis[y.first][y.second]){
vis[y.first][y.second] = 1;
par[y.first][y.second] = x;
que.push(y);
}
}
}
}
else{
if(!vis[x.first][x.second^1]){
vis[x.first][x.second^1] = 1;
par[x.first][x.second^1] = x;
que.emplace(x.first, x.second ^ 1);
}
}
}
}
if(answ + 2 < cnt){
printf("Case #%d: IMPOSSIBLE\n", i);
continue;
}
else{
printf("Case #%d: POSSIBLE\n", i);
int L = 0;
for(int i=1; i<n; i++){
for(int j=1; j<m; j++){
if(dap[i-1][j-1]) continue;
if(chk[L][0]){
dap[i-1][j-1] = '\\';
}
else if(chk[L][1]){
dap[i-1][j-1] = '/';
}
else{
dap[i-1][j-1] = '.';
}
L++;
}
puts(dap[i-1]);
}
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnVzaW5nIGxpbnQgPSBsb25nIGxvbmc7CnVzaW5nIHBpID0gcGFpcjxpbnQsIGludD47CmNvbnN0IGludCBNQVhOID0gMTAwMDU7CmNvbnN0IGludCBtb2QgPSAxZTkgKyA3OwoKc3RydWN0IGRpc2p7CglpbnQgcGFbTUFYTl07Cgl2b2lkIGluaXQoaW50IG4pewoJCWlvdGEocGEsIHBhICsgbiArIDEsIDApOwoJfQoJaW50IGZpbmQoaW50IHgpewoJCXJldHVybiBwYVt4XSA9IChwYVt4XSA9PSB4ID8geCA6IGZpbmQocGFbeF0pKTsKCX0KCWJvb2wgdW5pKGludCBwLCBpbnQgcSl7CgkJcCA9IGZpbmQocCk7CgkJcSA9IGZpbmQocSk7CgkJaWYocCA9PSBxKSByZXR1cm4gMDsKCQlwYVtxXSA9IHA7IHJldHVybiAxOwoJfQp9ZGlzajsKCmludCBLOwpwaSBhW01BWE5dWzJdOwppbnQgY2hrW01BWE5dWzJdOwpwaSBwYXJbTUFYTl1bMl07Cm5hbWVzcGFjZSBncmFwaHsKCXZlY3RvcjxwaT4gZ3BoWzEwMDA1XTsKCWludCBwYXJbMTAwMDVdLCBwYWVbMTAwMDVdOwoJdm9pZCBkZnMoaW50IHgsIGlud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