#include <bits/stdc++.h>
//#define mp make_pair
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rp(i,a,n) for(int i=a;i<=int(n);i++)
#define IT(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define oo INT_MAX
#define fill(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define mod 1000000007
using namespace std;
int dr[8] = {1,1,0,-1,-1,-1, 0, 1};
int dc[8] = {0,1,1, 1, 0,-1,-1,-1};
int dh[4] = {0, 1, 0, -1};
int dv[4] = {-1, 0, 1, 0};
int n,m,a,b;
char s[550][550],mp[550][550];
int vis[550][550];
ll ans[550][550];
void dfs(int x,int y,char c)
{
if(vis[x][y]||s[x][y]!='.') return ;
vis[x][y]=1;
mp[x][y]=c;
rep(i,4) dfs(x+dh[i],y+dv[i],c=='T'?'W':'T');
}
void dfs2(int x,int y,ll cnt)
{
if(vis[x][y]||s[x][y]!='.') return ;
vis[x][y]=1;
ans[x][y]=min(ans[x][y],cnt);
if(mp[x][y]=='T') cnt+=a;else cnt+=b;
rep(i,4) dfs2(x+dh[i],y+dv[i],cnt);
}
int main()
{
cin >> n >> m >> a >> b;
swap(n,m);
rep(i,n+5) rep(j,m+5) s[i][j]=mp[i][j]='#' ;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin >> s[i][j];
dfs(1,1,'T');
if(!vis[n][m]) { cout << "IMPOSSIBLE\n"; return 0; }
for(int i=0;i<=n+5;i++) for(int j=0;j<=m+5;j++) vis[i][j]=0,ans[i][j]=1000000000;
dfs2(1,1,0);
cout << ans[n][m] << "\n";
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Ci8vI2RlZmluZSBtcCBtYWtlX3BhaXIKI2RlZmluZSBwYiBwdXNoX2JhY2sKI2RlZmluZSB2aSB2ZWN0b3I8aW50PgojZGVmaW5lIHBpaSBwYWl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