#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 *************** 

class DirectedGraph {
  struct Edge { int to, cost; };
public:
  vector<vector<Edge>> G;
  int V;
  DirectedGraph(int V) : G(V), V(V) {}
  void add_edge(int u, int v, int cost) {
    G[u].push_back({v, cost});
    // G[v].push_back({u, cost});
  }
  vector<int> dijkstra(int s) {
    vector<int> d(V, 1e18); d[s] = 0;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> que; // {dist, v}
    que.push({0, s});
    while (!que.empty()) {
      pair<int, int> p = que.top(); que.pop();
      int v = p.second;
      if (d[v] < p.first) continue;  // 定数倍枝刈り
      for (Edge e: G[v]) {
        int tmp = d[v] + e.cost;
        if (d[e.to] <= tmp) continue;
        d[e.to] = tmp;
        que.push({tmp, e.to});
      }
    }
    return d;
  }
};

vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};

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 i2ii = [&](int i) { return ii({i / w, i % w}); };
  auto ii2i = [&](ii p) { return p.fi * w + p.se; };
  auto valid = [&](ii p) {
    return 0 <= p.fi && p.fi < h && 0 <= p.se && p.se < w;
  };
  auto around_bomb = [&](ii p) {
    for (ii dir: dirs) {
      ii to = {p.fi + dir.fi, p.se + dir.se};
      if (!valid(to)) continue;
      if (t[to.fi][to.se] == '*') return true;
    }
    return false;
  };

  DirectedGraph G(h * w);
  REP (i, h) {
    REP (j, w) {
      bool bomb = around_bomb({i, j});
      for (ii dir: dirs) {
        ii to = {i + dir.fi, j + dir.se};
        if (!valid(to)) continue;
        if (abs(dir.fi) + abs(dir.se) == 1) {
          int cost = a;
          if (t[to.fi][to.se] == '#') {
            if (bomb) continue;
            cost += b;
          }
          G.add_edge(ii2i({i, j}), ii2i(to), cost);
        } else if (abs(dir.fi) + abs(dir.se) == 2) {
          int cost = 2 * a;
          if (t[to.fi][to.se] == '#' || (t[i + dir.fi][j] == '#' && t[i][j + dir.se] == '#')) {
            if (bomb) continue;
            cost += b;
          }
          G.add_edge(ii2i({i, j}), ii2i(to), cost);
        }
      }
    }
  }
  vector<int> d = G.dijkstra(ii2i(s));
  if (d[ii2i(g)] == 1e18) {
    cout << "INF" << endl;
  } else {
    cout << d[ii2i(g)] << endl;
  }
}



Measured memory_bytes: 175720