#include <bits/stdc++.h>
using namespace std;
string str[105];
int row_c[105];
int col_c[105];
vector <int> r_cuts;
int main()
{
// cout << "Hello World!" << endl;
ios::sync_with_stdio(false);
int t;
cin>>t;
for(int caseno=1;caseno<=t;caseno++){
cout<<"Case #"<<caseno<<": ";
for(int i=0;i<105;i++){
row_c[i]=0;
col_c[i]=0;
}
r_cuts.erase(r_cuts.begin(),r_cuts.end());
int r,c,h,v;
cin>>r>>c>>h>>v;
int chips=0;
for(int i=0;i<r;i++){
cin>>str[i];
}
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
if(str[i][j]=='@'){
chips++;
row_c[i]++;
}
}
}
// for(int i=0;i<r;i++)cout<<row_c[i]<<",,,";
if(chips%((h+1)*(v+1))!=0){
cout<<"IMPOSSIBLE\n";
for(int i=0;i<r;i++)row_c[i]=0;
continue;
}
int per_row=chips/(h+1);
int cur=0;
bool poss=true;
for(int i=0;i<r;i++){
cur+=row_c[i];
if(cur>per_row){
poss=false;
break;
}
else if(cur==per_row){
r_cuts.push_back(i);
cur=0;
}
}
// cout<<r_cuts.size()<<"\n";
if(poss==false){
cout<<"IMPOSSIBLE\n";
for(int i=0;i<r;i++)row_c[i]=0;
r_cuts.erase(r_cuts.begin(),r_cuts.end());
continue;
}
int per_col=per_row/(v+1);
for(int i=0;i<c;i++){
int index=0;
for(int j=0;j<r;j++){
if(str[j][i]=='@'){
col_c[index]++;
}
if(j==r_cuts[index]){
index++;
}
}
bool same=true;
for(int j=0;j<index;j++){
if(col_c[j]<per_col){
same=false;
}
if(col_c[j]>per_col){
poss=false;
break;
}
}
if(same){
for(int j=0;j<index;j++){
col_c[j]=0;
}
}
if(!poss){
break;
}
}
if(poss==true){
cout<<"POSSIBLE\n";
}
else{
cout<<"IMPOSSIBLE\n";
}
}
return 0;
}
/*
6
3 6 1 1
.@@..@
.....@
@.@.@@
4 3 1 1
@@@
@.@
@.@
@@@
4 5 1 1
.....
.....
.....
.....
4 4 1 1
..@@
..@@
@@..
@@..
3 4 2 2
@.@@
@@.@
@.@@
3 4 1 2
.@.@
@.@.
.@.@
*/
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgc3RyWzEwNV07CmludCByb3dfY1sxMDVdOwppbnQgY29sX2NbMTA1XTsKdmVjdG9yIDxpbnQ+IHJfY3V0czsKaW50IG1haW4oKQp7CiAgICAvLyBjb3V0IDw8ICJIZWxsbyBXb3JsZCEiIDw8IGVuZGw7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBpbnQgdDsKICAgIGNpbj4+dDsKICAgIGZvcihpbnQgY2FzZW5vPTE7Y2FzZW5vPD10O2Nhc2VubysrKXsKICAgICAgICBjb3V0PDwiQ2FzZSAjIjw8Y2FzZW5vPDwiOiAiOwogICAgICAgIGZvcihpbnQgaT0wO2k8MTA1O2krKyl7CiAgICAgICAgICAgIHJvd19jW2ldPTA7CiAgICAgICAgICAgIGNvbF9jW2ldPTA7CiAgICAgICAgfQogICAgICAgIHJfY3V0cy5lcmFzZShyX2N1dHMuYmVnaW4oKSxyX2N1dHMuZW5kKCkpOwogICAgICAgIGludCByLGMsaCx2OwogICAgICAgIGNpbj4+cj4+Yz4+aD4+djsKICAgICAgICBpbnQgY2hpcHM9MDsKICAgICAgICAKICAgICAgICBmb3IoaW50IGk9MDtpPHI7aSsrKXsKICAgICAgICAgICAgY2luPj5zdHJbaV07CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgaT0wO2k8cjtpKyspewogICAgICAgICAgICBmb3IoaW50IGo9MDtqPGM7aisrKXsKICAgICAgICAgICAgICAgIGlmKHN0cltpXVtqXT09J0AnKXsKICAgICAgICAgICAgICAgICAgICBjaGlwcysrOwogICAgICAgICAgICAgICAgICAgIHJvd19jW2ldKys7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgLy8gZm9yKGludCBpPTA7aTxyO2krKyljb3V0PDxyb3dfY1tpXTw8IiwsLCI7CiAgICAgICAgaWYoY2hpcHMlKChoKzEpKih2KzEpKSE9MCl7CiAgICAgICAgICAgIGNvdXQ8PCJJTVBPU1NJQkxFXG4iOwogICAgICAgICAgICBmb3IoaW50IGk9MDtpPHI7aSsrKXJvd19jW2ldPTA7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBpbnQgcGVyX3Jvdz1jaGlwcy8oaCsxKTsKICAgICAgICBpbnQgY3VyPTA7CiAgICAgICAgYm9vbCBwb3NzPXRydWU7CiAgICAgICAgZm9yKGludCBpPTA7aTxyO2krKyl7CiAgICAgICAgICAgIGN1cis9cm93X2NbaV07CiAgICAgICAgICAgIGlmKGN1cj5wZXJfcm93KXsKICAgICAgICAgICAgICAgIHBvc3M9ZmFsc2U7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgICAgICBlbHNlIGlmKGN1cj09cGVyX3Jvdyl7CiAgICAgICAgICAgICAgICByX2N1dHMucHVzaF9iYWNrKGkpOwogICAgICAgICAgICAgICAgY3VyPTA7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgLy8gY291dDw8cl9jdXRzLnNpemUoKTw8IlxuIjsKICAgICAgICBpZihwb3NzPT1mYWxzZSl7CiAgICAgICAgICAgIGNvdXQ8PCJJTVBPU1NJQkxFXG4iOwogICAgICAgICAgICBmb3IoaW50IGk9MDtpPHI7aSsrKXJvd19jW2ldPTA7CiAgICAgICAgICAgIHJfY3V0cy5lcmFzZShyX2N1dHMuYmVnaW4oKSxyX2N1dHMuZW5kKCkpOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgaW50IHBlcl9jb2w9cGVyX3Jvdy8odisxKTsKICAgICAgICBmb3IoaW50IGk9MDtpPGM7aSsrKXsKICAgICAgICAgICAgaW50IGluZGV4PTA7CiAgICAgICAgICAgIGZvcihpbnQgaj0wO2o8cjtqKyspewogICAgICAgICAgICAgICAgaWYoc3RyW2pdW2ldPT0nQCcpewogICAgICAgICAgICAgICAgICAgIGNvbF9jW2luZGV4XSsrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgaWYoaj09cl9jdXRzW2luZGV4XSl7CiAgICAgICAgICAgICAgICAgICAgaW5kZXgrKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBib29sIHNhbWU9dHJ1ZTsKICAgICAgICAgICAgZm9yKGludCBqPTA7ajxpbmRleDtqKyspewogICAgICAgICAgICAgICAgaWYoY29sX2Nbal08cGVyX2NvbCl7CiAgICAgICAgICAgICAgICAgICAgc2FtZT1mYWxzZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGlmKGNvbF9jW2pdPnBlcl9jb2wpewogICAgICAgICAgICAgICAgICAgIHBvc3M9ZmFsc2U7CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoc2FtZSl7CiAgICAgICAgICAgICAgICBmb3IoaW50IGo9MDtqPGluZGV4O2orKyl7CiAgICAgICAgICAgICAgICAgICAgY29sX2Nbal09MDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZighcG9zcyl7CiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpZihwb3NzPT10cnVlKXsKICAgICAgICAgICAgY291dDw8IlBPU1NJQkxFXG4iOwogICAgICAgIH0KICAgICAgICBlbHNlewogICAgICAgICAgICBjb3V0PDwiSU1QT1NTSUJMRVxuIjsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQovKgo2CjMgNiAxIDEKLkBALi5ACi4uLi4uQApALkAuQEAKNCAzIDEgMQpAQEAKQC5ACkAuQApAQEAKNCA1IDEgMQouLi4uLgouLi4uLgouLi4uLgouLi4uLgo0IDQgMSAxCi4uQEAKLi5AQApAQC4uCkBALi4KMyA0IDIgMgpALkBACkBALkAKQC5AQAozIDQgMSAyCi5ALkAKQC5ALgouQC5ACiov