| <p>There has been a war between the digits in the kingdom of numbers and it is King Infinity's job to restore balance. In search of peace he came up with a new number system which only allows those numbers to exist in which: | |
| </p> | |
| <p> | |
| 1. None of the consecutive digits are at war against each other. | |
| </p> | |
| <p> | |
| 2. No two digits that have only one digit in between them are at war. | |
| </p> | |
| <p>For example, if 4 is at war with 5, then 45, 405, and 574 are all forbidden.</p> | |
| <p> | |
| A digit can be at war with itself. You are given a 10 x 10 binary matrix <strong>M</strong> (0 index based), where <strong>M</strong>[i][j] denotes whether there is a war between digit i and digit j. If <strong>M</strong>[i][j] = 1 then they are at war and <strong>M</strong>[i][j] = 0 means they are not. <strong>M</strong>[i][j] will always be equal to <strong>M</strong>[j][i]. | |
| </p> | |
| <p> | |
| Your task is to find the count of positive numbers that can exist in this number system with number of digits ≤ <strong>K</strong>. No number in the number system can have leading zeroes. | |
| </p> | |
| <p> | |
| <h2 id="limits">Limits</h2> | |
| 1 ≤ <strong>K</strong> ≤ 10<sup>18</sup></h2> | |
| </p> | |
| <p> | |
| <h2 id="input">Input</h2> | |
| Input consists of <strong>T</strong> test cases, with <strong>T</strong> ≤ 25. Each test case begins with the value of <strong>K</strong> followed by a 10x10 binary matrix. | |
| </p> | |
| <p> | |
| <h2 id="output">Output</h2> | |
| For every test case output the result modulo 10<sup>9</sup> +7 | |
| </p> | |