Problem: Problem

Kotatsu turtle is a turtle with a kotatsu shell.


As soon as Kotatsu was pokita (getting up), he was trapped in a stage divided into grid-like sections. There is only one exit on this stage. The parcel is either a road, a fence or a bomb, and the kotatsu can move up, down, left and right to enter the parcel of the road or bomb. It cannot be moved diagonally. In addition, the fence section cannot be passed. The road section extends infinitely outside the stage, but it cannot be passed because there is a crocodile, the natural enemy of the turtle.

Kotatsu wants to go home (sleep) quickly, so I decided to head to the exit of this stage.

The kotatsu turtle, which can freely manipulate the infrared rays of the kotatsu, has the ability to turn eight sections around it into a road at the same time. However, if the 8 sections and one of the sections where you are located are bomb sections, the kotatsu will burn up when you explode, and you will not even be able to use the famous SNS "Kametta", so you will activate the ability. I can't do that.

<image>

An example is illustrated. The section where the illustration is not placed and the section where the kotatsu is placed are the sections of the road. The eight compartments around the kotatsu are the orange compartments. In the figure on the left, the 8 compartments around the kotatsu and the compartment where you are are not included in the bomb compartment, so you can activate the ability. However, in the figure on the right, the ability cannot be activated because the bomb compartment is included in either the surrounding 8 compartments or the compartment where you are.

The cost to move is $ A $ for each parcel move, and the cost to activate the ability is $ B $ each time. Please note that it is not the cost per wall turned into a road. The starting point and the exit of the stage are roads. Output the minimum sum of the cost of moving from the starting point to the exit of the stage and the cost of activating the ability. However, if you cannot reach the exit of the stage, output "INF" instead.

Constraints

The input satisfies the following conditions.

* $ 1 \ le H, W, A, B \ le 1000 $
* $ 3 \ le H + W $
* $ c_ {i, j} \ in $ {'s','g','.','#','*'}
*'s' and'g' appear once each

Input

The input is given in the following format.


$ H $ $ W $ $ A $ $ B $
$ c_ {1,1} \ cdots c_ {1, W} $
$ \ vdots $
$ c_ {H, 1} \ cdots c_ {H, W} $


The input consists of $ H + 1 $ lines.
On the $ 1 $ line, there are an integer $ H $ that represents the vertical length, an integer $ W $ that represents the left and right length, an integer $ A $ that represents the cost to move, and an integer $ B $ that represents the cost to activate the ability. Each is given with a blank delimiter.
The $ H $ line from the $ 2 $ line is given the state $ c_ {i, j} $ in each section of the stage where the kotatsu is confined.
$ c_ {i, j} $ consists of one of's','g','.','#','*', Each, and the partition $ (i, j) $ is in the following state. Represents that.
's': Indicates that the section is the starting point.
'g': Indicates that the parcel is the exit of the stage.
'.': Indicates that the section is a road.
'#': Indicates that the section is a fence.
'*': Indicates that the parcel is a bomb.

Output

Output the minimum sum of the cost of moving from the starting point to the exit of the stage and the cost of activating the ability. However, if you cannot reach the exit of the stage, output "INF" instead.

Examples

Input

4 4 1 1
g#..
#...
.*..
...s


Output

7


Input

4 4 1 1
g#..
...
.*..
...s


Output

7


Input

4 4 1 1
g#..
*..
....
...s


Output

INF


Input

2 4 1 1
g
s###


Output

6


Input

3 3 1 10
g..
.
s..


Output

6


Input

3 3 10 1
g..
.
s..


Output

21

Solution (in CPP):

Solution:
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

const int INF=1234567890;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

bool inG(ll x,ll n){return 0<=x && x<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

const int dx9[]={-1,-1,-1,0,1,1,1,0,0},dy9[]={-1,0,1,1,1,0,-1,-1,0};

#define MAX_HW 1000000

int d[MAX_HW];
vector <pii> g[MAX_HW];
void dijk(int V,int s){

  priority_queue <pii,vector<pii>,greater<pii> > que;
  fill(d,d+V,INF);

  d[s]=0;

  que.push(pii(0,s));

  for(;!que.empty();){

    pii p=que.top(); que.pop();
    int v=p.se;

    if (d[v]<p.fi) continue;

    for(int i=0;i<(int)g[v].size();i++){

      pii e=g[v][i]; //fiが場所、seがコスト

      if(d[e.fi]>d[v]+e.se){

	       d[e.fi]=d[v]+e.se;
	       que.push(pii(d[e.fi],e.fi));

      }
    }
  }
}

signed main(){

  int h,w,a,b;
  cin>>h>>w>>a>>b;

  vs s(h);

  cin>>s;

  int st=-1,go=-1;

  REP(i,h) REP(j,w){

    bool isbom=false;

    if(s[i][j] == 's') st=i*w+j;
    if(s[i][j] == 'g') go=i*w+j;

    REP(dir,9){

      int y=i+dy9[dir],x=j+dx9[dir];

      if(outG(y,h) || outG(x,w)) continue;

      if(s[y][x] == '*') isbom=true;

    }

    REP(dir,4){

      int y=i+dy[dir],x=j+dx[dir];

      if(outG(y,h) || outG(x,w)) continue;

      if(s[y][x] != '#') g[i*w+j].pb(mp(y*w+x,a));
      if(!isbom){

        g[i*w+j].pb(mp(y*w+x,a+b));

        int y_=y,x_=x;

        if(dy[dir]) x_+=dy[dir];
        else y_-=dx[dir];

        if(inG(y_,h) && inG(x_,w)) g[i*w+j].pb(mp(y_*w+x_,a*2+b));


        // y_=y,x_=x;
        //
        // if(dy[dir]) x_-=dy[dir];
        // else y_-=dx[dir];
        //
        // if(!(outG(y_,h) || outG(x_,w))) g[i*w+j].pb(mp(y_*w+x_,a*2+b));

      }

    }

  }

  dijk(h*w,st);

  if(d[go] == INF) cout<<"INF"<<endl;
  else cout<<d[go]<<endl;

  return 0;

}