Problem:
Score : 1100 points

Problem Statement

We have an H \times W grid, where each square is painted white or black in the initial state.
Given are strings A_1, A_2, ..., A_H representing the colors of the squares in the initial state.
For each pair (i, j) (1 \leq i \leq H, 1 \leq j \leq W), if the j-th character of A_i is ., the square at the i-th row and j-th column is painted white; if that character is #, that square is painted black.

Among the 2^{HW} ways for each square in the grid to be painted white or black, how many can be obtained from the initial state by performing the operations below any number of times (possibly zero) in any order? Find this count modulo 998,244,353.

Choose one row, then paint all the squares in that row white.

Choose one row, then paint all the squares in that row black.

Choose one column, then paint all the squares in that column white.

Choose one column, then paint all the squares in that column black.

Constraints

1 \leq H, W \leq 10

|A_i| = W (1 \leq i \leq H)

All strings A_i consist of . and #.

H and W are integers.

Input

Input is given from Standard Input in the following format:

H W
A_1
A_2
\vdots
A_H

Output

Print the answer.

Sample Input 1

2 2
#.
.#

Sample Output 1

15

For example, if we paint the second row black, the grid becomes:

#.
##

Sample Input 2

3 3
...
...
...

Sample Output 2

230

Sample Input 3

2 4
#...
...#

Sample Output 3

150

Sample Input 4

6 7
.......
.......
.#.....
..#....
.#.#...
.......

Sample Output 4

203949910

Solution in PyPy3 (2.4.0) (judge verdict: Time Limit Exceeded)

import sys
input = sys.stdin.readline

H,W=map(int,input().split())
A=[input().strip() for i in range(H)]

mod=998244353

# factorial,facotiralの逆数を事前計算.
FACT=[1]
for i in range(1,30+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(30,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod
    else:
        return 0

M=max(H,W)+1
RA=[[-1]*M for i in range(M)]
def rect(H,W):
    if H==W==0:
        return 1
    if RA[H][W]!=-1:
        return RA[H][W]
    
    DP=[[[0,0] for j in range(W+1)] for i in range(H+1)] # (h,w)の最後に進んだ向きが縦/横のときの場合の数
    DP[0][0][0]=1
    DP[0][0][1]=1

    for h in range(H+1):
        for w in range(W+1):
            for nexth in range(h+1,H+1):
                DP[nexth][w][0]+=DP[h][w][1]*FACT_INV[nexth-h]
                DP[nexth][w][0]%=mod

            for nextw in range(w+1,W+1):
                DP[h][nextw][1]+=DP[h][w][0]*FACT_INV[nextw-w]
                DP[h][nextw][1]%=mod

    RA[H][W]=RA[W][H]=sum(DP[H][W])*FACT[H]*FACT[W]%mod

    return RA[H][W]

CA=[[-1]*(W+1) for i in range(H+1)]
def calc(h,w):
    if CA[h][w]!=-1:
        return CA[h][w]
    
    RET=0
    
    for bh in range(h+1):
        for bw in range(w+1):
            RET+=rect(bh,w-bw)*rect(h-bh,bw)*Combi(h,bh)*Combi(w,bw)
            #print(bh,bw,w-bw,h-bh,rect(bh,w-bw),rect(h-bh,bw),Combi(h,bh),Combi(w,bw))
            RET%=mod

    CA[h][w]=RET%mod
    return CA[h][w]

ANS=0

for i in range(1<<H):
    HR=[0]*H

    for h in range(H):
        if i & (1<<h)!=0:
            HR[h]=1

    for j in range(1<<W):
        
        WR=[0]*W

        for w in range(W):
            if j & (1<<w)!=0:
                WR[w]=1

        #print(HR,WR)

        okflag=1
        for h in range(H):
            if HR[h]==1:
                continue
            coinc=0
            dif=0
            for w in range(W):
                if WR[w]==1:
                    continue

                if coinc==0:
                    coinc=A[h][w]
                elif A[h][w]!=coinc:
                    dif=1
                    break

            if dif==0:
                okflag=0
                break

        if okflag==0:
            continue

        okflag=1
        for w in range(W):
            if WR[w]==1:
                continue
            coinc=0
            dif=0
            for h in range(H):
                if HR[h]==1:
                    continue

                if coinc==0:
                    coinc=A[h][w]
                elif A[h][w]!=coinc:
                    dif=1
                    break
                
            if dif==0:
                okflag=0
                break

        if okflag==0:
            continue

        # HR,WRのうち、0の部分だけを見る.

        H0=HR.count(1)
        W0=WR.count(1)

        #print(H0,W0,HR,WR,ANS)

        if H0==H and W0==W:
            ANS+=rect(H,W)
        else:
            ANS+=calc(H0,W0)
            
        ANS%=mod

        
print(ANS)