Directions
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

In this problem, we assume that the Earth is a perfect sphere.

For two positions x,y on the equator, the west distance  is defined as the distance from x to y if you keep going west, the east distance  is defined as the distance from x to y if you keep going east.

We called x is to the west of y if , x is to the east of y if . Noticed that x might be neither to the west nor to the east of y.

A direction matrix D is defined as a matrix satisfying these conditions:

  • For each integer i such that , .
  • For each integer pair (i,j) such that and , .

A direction matrix D is real if there are n distinct positions on the equator satisfying these conditions:

  • All points meet the anticlockwise order when we look down at the equator from above the north pole.
  • For each integer pair (i,j) such that and , if , a_i is to the west of a_j, otherwise a_i is to the east of a_j.

Now you are given a direction matrix D', but some and are replaced by . If you can replace each by or , how many real direction matrix you can get? Print the number modulo 998244353.

输入描述:

Each test contains multiple test cases. The first line contains the number of test cases T (). Description of the test cases follows.

The first line contains a single integer n ().

Then n lines follow. The i-th of these lines contains a string D'_i of length n consisting of , describing the direction matrix D'.

It is guaranteed that the sum of n over all test cases does not exceed 500.

输出描述:

For each test case, output a single line contains a single integer, indicating the answer modulo 998244353.
示例1

输入

复制
3
3
*W?
?*?
?E*
4
*???
?*??
??*?
???*
5
*W???
?*W??
??*W?
???*?
????*

输出

复制
2
8
13

说明

Here is the explanation of the first test case when we look down at the equator from above the north pole.