#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

vector<int> dx = {-1, 0, 1, 0};
vector<int> dy = {0, -1, 0, 1};
vector<int> ex = {-1, -1, 1, 1};
vector<int> ey = {-1, 1, -1, 1};

signed main() {
  int h, w, a, b; cin >> h >> w >> a >> b;
  vector<string> t(h); REP (i, h) cin >> t[i];
  ii s, g;
  REP (i, h) {
    REP (j, w) {
      if (t[i][j] == 's') s = {i, j};
      if (t[i][j] == 'g') g = {i, j};
    }
  }
  auto valid = [&](ii p) {
    return 0 <= p.fi && p.fi < h && 0 <= p.se && p.se < w;
  };
  auto around_bomb = [&](ii p) {
    bool ret = false;
    ret |= t[p.fi][p.se] == '*';
    REP (i, 4) {
      ii to = {p.fi + dy[i], p.se + dx[i]};
      if (valid(to)) ret |= t[to.fi][to.se] == '*';
    }
    REP (i, 4) {
      ii to = {p.fi + ey[i], p.se + ex[i]};
      if (valid(to)) ret |= t[to.fi][to.se] == '*';
    }
    return ret;
  };

  vector<vector<int>> d(h, vector<int>(w, 1e17));
  d[s.fi][s.se] = 0;
  priority_queue<pair<int, ii>, vector<pair<int, ii>>, greater<pair<int, ii>>> q;
  q.push({0, {s}});
  while (!q.empty()) {
    pair<int, ii> pii = q.top(); q.pop();
    ii p = pii.se;
    if (d[p.fi][p.se] < pii.fi) continue;
    bool bomb = around_bomb(p);
    REP (i, 4) {
      ii to = {p.fi + dy[i], p.se + dx[i]};
      if (!valid(to)) continue;
      int tmp = d[p.fi][p.se] + a;
      if (t[to.fi][to.se] == '#') {
        if (bomb) continue;
        tmp += b;
      }
      if (chmin(d[to.fi][to.se], tmp)) {
        q.push({tmp, to});
      }
    }
    REP (i, 4) {
      ii to = {p.fi + ey[i], p.se + ex[i]};
      if (!valid(to)) continue;
      int tmp = d[p.fi][p.se] + 2 * a;
      if (t[to.fi][to.se] == '#' || (t[p.fi + ey[i]][p.se] == '#' && t[p.fi][p.se + ex[i]])) {
        if (bomb) continue;
        tmp += b;
      }
      if (chmin(d[to.fi][to.se], tmp)) {
        q.push({tmp, to});
      }
    }
  }
  dump(d);
  if (d[g.fi][g.se] == 1e17) {
    cout << "INF" << endl;
  } else {
    cout << d[g.fi][g.se] << endl;
  }
}



Measured memory_bytes: 11692