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:
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353LL
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
#define ll long long
int grid[2000][2000] = {};
long long dp[2000][2000] = {};
long long visited[2000][2000] = {};
int main() {
	long long h, w, a, b;
	cin >> h >> w >> a >> b;
	pair<int, int> start, end;
	REP(i, h) {
		string s;
		cin >> s;
		REP(q, s.length()) {
			if (s[q] == 'g') end = make_pair(i, q);
			else if (s[q] == '#') grid[i][q] = 1;//wall
			else if (s[q] == '*') grid[i][q] = 2;//bomb
			else if (s[q] == 's') start = make_pair(i, q);
		}
	}
	priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll>>, greater<tuple<ll, ll, ll>>> next;
	next.push(make_tuple(0, start.first, start.second));
	REP(i, h) {
		REP(q, w) {
			dp[i][q] = LONG_INF;
		}
	}
	dp[start.first][start.second] = 0;
	while (next.empty() == false) {
		tuple<ll, ll, ll> now = next.top();
		next.pop();
		if (visited[get<1>(now)][get<2>(now)] == 1) continue;
		visited[get<1>(now)][get<2>(now)] = 1;
		int xe[8] = { 0,0,1,-1,1,1,-1,-1 };
		int ye[8] = { 1,-1,0,0,1,-1,1,-1 };
		//move road
		for (int t = 0; t < 4; ++t) {
			int x = xe[t] + get<1>(now);
			int y = ye[t] + get<2>(now);
			if (x >= 0 && x < h&&y >= 0 && y < w) {
				if (grid[x][y] != 1) {
					int cost = get<0>(now) + a;
					if (cost < dp[x][y] && visited[x][y] == 0) {
						dp[x][y] = cost;
						next.push(make_tuple(cost, x, y));
					}
				}
			}
		}
		//check for bomb
		int bombing = 0;
		for (int i = max(0LL, get<1>(now) - 1); i <= min(h - 1, get<1>(now) + 1); ++i) {
			for (int q = max(0LL, get<2>(now) - 1); q <= min(w - 1, get<2>(now) + 1); ++q) {
				if (grid[i][q] == 2) bombing = 1;
			}
		}
		if (bombing == 0) {
			for (int t = 0; t < 8; ++t) {
				int x = xe[t] + get<1>(now);
				int y = ye[t] + get<2>(now);
				if (x >= 0 && x < h&&y >= 0 && y < w) {
					int cost = get<0>(now) + a + b;
					if (t >= 4) cost += a;
					if (cost < dp[x][y] && visited[x][y] == 0) {
						dp[x][y] = cost;
						next.push(make_tuple(cost, x, y));
					}
				}
			}
		}
	}
	if (dp[end.first][end.second] == LONG_INF) {
		cout << "INF" << endl;
		return 0;
	}
	cout << dp[end.first][end.second] << endl;
	return 0;
}