## Problem

### Description

As it has been found out recently, all the Berland’s current economical state can be described using a simple table in size. ― the number of days in each Berland month, ― the number of months. Thus, a table cell corresponds to a day and a month of the Berland’s year. Each cell will contain either , or , which means the state’s gains in a particular month, on a particular day. corresponds to profits, corresponds to losses. It turned out important for successful development to analyze the data on the state of the economy of the previous year, however when the treasurers referred to the archives to retrieve the data, it turned out that the table had been substantially damaged. In some table cells the number values had faded and were impossible to be deciphered. It is known that the number of cells in which the data had been preserved is strictly less than . However, there is additional information ― the product of the numbers in each line and column equaled . Your task is to find out how many different tables may conform to the preserved data. As the answer to the task can be quite large, you have to find it modulo .

### Input

The first line contains integers and . The second line contains the integer ― the number of cells in which the data had been preserved. The next lines contain the data on the state of the table in the preserved cells. Each line is of the form a b c, where ― the number of the table row, ― the number of the column, ― the value containing in the cell ( or ). They are numbered starting from . It is guaranteed that no two lines with same and values exist. The last line contains an integer .

### Output

Print the number of different tables that could conform to the preserved data modulo .

Input #1

Output #1

Input #2

Output #2

## Code

------------- Thanks For Reading -------------
0%