You are browsing an online collection of n items numbered from 1 to n arranged on a circle. The item to the right of each item i is item i+1, and the item to the right of item n is item 1. Similarly, the item to the left of each item i is item i−1, and the item to the left of item 1 is item n.
The items have m parameters numbered from 1 to m. The value of parameter j for item i is an integer a_i,j.
While you are browsing, at any moment, there is a pointer directed at some item, called the current item.
Moreover, you can manage a set of filtering conditions. Each condition is a pair (j,v), meaning that the j-th parameter of the item must be equal to v. The current item always satisfies all conditions in the set.
To browse through the collection, you can do operations. Each operation must have one of the following four kinds:
For each ordered pair of items (i,j), answer the following question:
The first line contains two integers n and m, denoting the number of items in the collection and the number of parameters each item has (2≤n≤500; 1≤m≤5).
The i-th of the next n lines contains m integers a_i,1,a_i,2,…,a_i,m, denoting the parameter values of item i (1≤a_i,j≤n).
Print n lines containing n integers each.
In the i-th line, the j-th integer must be equal to the smallest number of operations required to move the pointer from item i to item j, starting with an empty set of filtering conditions.
In the example test, here is one possible fastest way to move from item 2 to item 5:
Here is one possible fastest way to move from item 8 to item 3: