##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
2 2 3 2 1 18 2 4 8 3 3 1 3 5 7 11 13 17 19 23
166 0

Root wanted to buy a nice New Year gift for AmShZ. Unfortunately, Hamed stole all of Root’s money! Root wished that Santa would bring him some money, but Hamed managed to steal Santa’s money as well! So, Root asked Santacci for help. Santacci appears only in emergencies and is famous for giving extremely large gifts.
This time, Santacci gave Root an grid of integers.
A path is a sequence of cells that starts at and ends at . In each step, the path moves either one cell to the right or one cell down.
Each path visits exactly cells and defines a sequence of values written in the visited cells. For a fixed path, define its score as follows:
For every unordered pair of positions on the path, let and be the values at those positions.
If is a perfect square, add to the score.
Otherwise, add .
The Fibonacci function is defined as:
The value of the grid is defined as the sum of scores over all valid paths.
Root is too tired to compute this value by himself and wants to know how much money he can get from Santacci’s gift in order to buy a proper New Year present for AmShZ.
Since the answer can be very large, output it modulo .
In the second case, the product of the values in any two cells is not a perfect square, so the score of all paths is .