#COLORCC. Colors

Colors

Given a Bipartite graph with N nodes, you have to colour each node in a way such that no two adjacent nodes have the same colour. Each node is allowed to choose colour from a subset of colours. Print the possible number of ways.

You are given a symmetric matrix i.e. matrix[i][j] is always equal to matrix[j][i]. If matrix[i][j] == 'Y' then nodes i and j are connected by an edge matrix[i][j] == 'N' then nodes i and j are not connected.

Input

T number of test cases (T test cases follow).

N number of nodes in graph. N lines corresponding to matrix. N line follows: each line contains xi — total colours ith node can take, followed by i colours.

Output

Print the possible number of ways to colour the graph.

Constraints

T will be less than 20.

0 ≤ N ≤ 13, size of matrix will be N × N, and each element of matrix would be either 'Y' or 'N'.

Number of colours a node can take would be greater than equal to 0 and less than equal to 8. Colour number would be less than 100000.

Example

Input
1
4
NYNN
YNNN
NNNY
NNYN
3 1 2 3
2 4 5
3 4 5 6
3 1 2 3

Output 54

</p>