Tour Counting#1103

Tour Counting

1 second
128 megabytes
Very easy

Given a directed graph , determine the number of distinct cycles of length less than . Since this number can be large, output it modulo .

A cycle is a nonempty sequence of vertices (not necessarily distinct) such that there is an edge from each vertex to the next one and an edge from the last vertex to the first one. The length of a cycle is the number of vertices in this sequence. Two cycles are considered distinct if their sequences are different.

Input

The first line contains three integers , and m~(1 \le n \le 35, 1 \le k \le 10^6, 1 \le m \le 10^9) — the number of vertices in the graph, the bound on the cycle length, and the modulus.

The next lines contain the adjacency matrix of the graph, each consisting of characters. The -th character of the -th line is 'Y' if there is an edge from vertex to vertex , and 'N' otherwise.

Output

Print the number of distinct cycles in of length less than , taken modulo .

Examples

Example 1

Loading
Loading