You might have remembered Theatre square from the problem 1A. Now it's finally getting repaved.

The square still has a rectangular shape of $n \times m$ meters. However, the picture is about to get more complicated now. Let $a_{i,j}$ be the $j$-th square in the $i$-th row of the pavement.

You are given the picture of the squares:  if $a_{i,j} = $ "*", then the $j$-th square in the $i$-th row should be black;  if $a_{i,j} = $ ".", then the $j$-th square in the $i$-th row should be white. 

The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:  $1 \times 1$ tiles — each tile costs $x$ burles and covers exactly $1$ square;  $1 \times 2$ tiles — each tile costs $y$ burles and covers exactly $2$ adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into $1 \times 1$ tiles. 

You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.

What is the smallest total price of the tiles needed to cover all the white squares?


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 500$) — the number of testcases. Then the description of $t$ testcases follow.

The first line of each testcase contains four integers $n$, $m$, $x$ and $y$ ($1 \le n \le 100$; $1 \le m \le 1000$; $1 \le x, y \le 1000$) — the size of the Theatre square, the price of the $1 \times 1$ tile and the price of the $1 \times 2$ tile.

Each of the next $n$ lines contains $m$ characters. The $j$-th character in the $i$-th line is $a_{i,j}$. If $a_{i,j} = $ "*", then the $j$-th square in the $i$-th row should be black, and if $a_{i,j} = $ ".", then the $j$-th square in the $i$-th row should be white.

It's guaranteed that the sum of $n \times m$ over all testcases doesn't exceed $10^5$.


-----Output-----

For each testcase print a single integer — the smallest total price of the tiles needed to cover all the white squares in burles.


-----Example-----
Input
4
1 1 10 1
.
1 2 10 1
..
2 1 10 1
.
.
3 3 3 7
..*
*..
.*.

Output
10
1
20
18



-----Note-----

In the first testcase you are required to use a single $1 \times 1$ tile, even though $1 \times 2$ tile is cheaper. So the total price is $10$ burles.

In the second testcase you can either use two $1 \times 1$ tiles and spend $20$ burles or use a single $1 \times 2$ tile and spend $1$ burle. The second option is cheaper, thus the answer is $1$.

The third testcase shows that you can't rotate $1 \times 2$ tiles. You still have to use two $1 \times 1$ tiles for the total price of $20$.

In the fourth testcase the cheapest way is to use $1 \times 1$ tiles everywhere. The total cost is $6 \cdot 3 = 18$.

Difficulty: interview

Starter code:

Solutions:
inp=lambda :map(int,input().split())
def sol():
    x,y,on,tw=inp()
    res=0
    for n in range(x):
        s=input()
        sm=0
        for n in s:
            if n=='.':
                sm+=1
            else:
                a=sm*on
                b=(sm//2)*tw+(sm%2)*on
                res+=min(a,b)
                sm=0
        a=sm*on
        b=(sm//2)*tw+(sm%2)*on
        res+=min(a,b)
    print(res)

for n in range(int(input())):
    sol()

t=int(input())

def solve(s):
	f=len(s)
	dp=[0]*(f+1)
	for i in range(f):
		if s[i]=='.':
			dp[i+1]=dp[i]+x
			if i>=1 and s[i-1]=='.':
				dp[i+1]=min(dp[i+1],dp[i-1]+y)
		else:
			dp[i+1]=dp[i]
	return dp[f]

for i in range(t):
	n,m,x,y=map(int,input().split())
	ans=0;
	for j in range(n):
		ans+=solve(input())
	print(ans)

def read_int():
    return int(input())


def read_ints():
    return list(map(int, input().split(' ')))


t = read_int()
for case_num in range(t):
    n, m, x, y = read_ints()
    a = []
    cost = 0
    for i in range(n):
        row = input() + '*'
        white = 0
        for c in row:
            if c == '*':
                if white > 0:
                    cost += min(white * x, white // 2 * y + white % 2 * x)
                white = 0
            else:
                white += 1
    print(cost)



def solv():
    x,y,on,tw=map(int,input().split())
    ans=0
    for n in range(x):
        s=input()
        tot=0
        for n in s:
            if n=='.':
                tot+=1
            else:
                a=tot*on
                b=(tot//2)*tw+(tot%2)*on
                ans+=min(a,b)
                tot=0
        a=tot*on
        b=(tot//2)*tw+(tot%2)*on
        ans+=min(a,b)
    print(ans)

for n in range(int(input())):
    solv()

t = int(input())

for _ in range(t):
    n, m, x, y = [int(x) for x in input().split()]
    mp = [input() for _ in range(n)]
    if y >= 2*x:
        print(x*sum(sum(1 for x in row if x == ".") for row in mp))
    else:
        tot = 0
        for row in mp:
            i = 0
            while i < m:
                if i + 1 < m and row[i] == row[i+1] == ".":
                    tot += y
                    i += 2
                elif row[i] == ".":
                    tot += x
                    i += 1
                else:
                    i += 1
        print(tot)


import sys

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
    n, m, x, y = nm()
    y = min(y, 2*x)
    ans = 0
    for _ in range(n):
        s = ns().split('*')
        for f in s:
            ans += len(f)//2*y + len(f)%2*x
    print(ans)
    return


# solve()

T = ni()
for _ in range(T):
    solve()


import sys
input = sys.stdin.readline
for f in range(int(input())):
    n,m,x,y=map(int,input().split())
    y=min(y,2*x)
    cost=0
    for i in range(n):
        r=input()
        white=False
        for j in range(m):
            if r[j]==".":
                if white:
                    cost+=y
                    cost-=x
                    white=False
                else:
                    cost+=x
                    white=True
            else:
                white=False
    print(cost)

import sys
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br


def solve():
  n, m, x, y = I()
  ans = 0
  for i in range(n):
    s = input()
    count = 0
    for j in range(m):
      if s[j] == '.':
        count += 1
      else:
        ans += min(x * count, count // 2 * y + (count % 2) * x)
        count = 0
    ans += min(x * count, count // 2 * y + (count % 2) * x)
  print(ans)

t, = I()
while t:
  t -= 1
  solve()


for _ in range(int(input())):
    n, m, x, y = list(map(int, input().split()))
    # n = int(input())
    # arr = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        s = input()
        be = s.count('.')
        ch = m - be
        if x * 2 <= y:
            ans += be * x
            continue
        j = 0
        while j < m:
            if s[j] == '*':
                j += 1
                continue
            if j + 1 == m or s[j + 1] == '*':
                ans += x
                j += 1
                continue
            ans += y
            j += 2
    print(ans)


for gfhua in range(int(input())):
    n,m,x,y = list(map(int,input().split()))
    if y > x * 2:
        y = x * 2
    ans = 0
    for i in range(n):
        s = input()
        l = 0
        for j in s:
            if j == ".":
                l += 1
            else:
                ans += l // 2 * y + l % 2 * x
                l = 0
        ans += l // 2 * y + l % 2 * x
    print(ans)


t = int(input())
for _ in range(t):
	n, m, x, y = map(int, input().split())
	ans = 0
	if y > 2*x:
		y = 2*x

	for i in range(n):
		arr = input()

		i = 0
		while i < m:
			if arr[i] == "*":
				i += 1
			else:
				if i + 1 < m and  arr[i+1] == ".":
					ans += y
					i += 2
				else:
					ans += x
					i += 1

	print(ans)

from math import *

def r1(t):
    return t(input().strip())

def r2(t):
    return [t(i) for i in input().strip().split()]

def r3(t):
    return [t(i) for i in input().strip()]

for _ in range(int(input())):
    n, m, x, y = r2(int)
    ans = 0
    cnt = 0
    for i in range(n):
        for j in input():
            if j == '.':
                cnt += 1
                if 2*x <= y:
                    ans += x
                    cnt = 0
                elif cnt == 2:
                    ans += y
                    cnt = 0
            else:
                if cnt == 1:
                    ans += x
                    cnt = 0
        if cnt == 1:
            ans += x
        cnt = 0
        
    print(ans)


for _ in range(int(input())):
    n, m, x, y = tuple(map(int, input().split()))
    y = min(y, 2 * x)

    ans = 0
    for _ in range(n):
        line = [i for i in input()]

        i = 0
        while i < m:
            if line[i] == '.':
                if i != m - 1 and line[i + 1] == '.':
                    ans += y
                    i += 2
                else:
                    ans += x
                    i += 1
            else:
                i += 1

    print(ans)


import sys
input = sys.stdin.readline

t = int(input())
for _ in range(t):
    n, m, x, y = list(map(int, input().split()))
    if y > 2 * x:
        y = 2 * x
    out = 0
    for i in range(n):
        line = input().strip()

        curr = 0
        for c in line:
            if c == '.':
                out += y * curr
                curr = 1 - curr
            else:
                out += x * curr
                curr = 0
        out += x * curr
    print(out)


def solve():
    n, m, x, y = map(int, input().split())
    y = min(y, x * 2)
    a = [input() for _ in range(n)]
    ans = 0
    for i in range(n):
        j = 0
        while j < m:
            if a[i][j] == '*':
                j += 1
                continue
            k = j
            while k < m and a[i][k] == '.':
                k += 1
            w = k - j
            ans += w // 2 * y + w % 2 * x
            j = k
    print(ans)

t = int(input())
for _ in range(t):
    solve()

T = int(input())

for t in range(T):
    N, M, x, y = [int(_) for _ in input().split()]
    answer = 0
    for i in range(N):
        row = input().split('*')
        for el in row:
            if el:
                l = len(el)
                b2 = l//2
                answer += min(2*x*b2, y*b2)
                if l % 2:
                    answer += x
    print(answer)