Hide

Problem E
Determinant of the matrix

A determinant is a real number associated with every square matrix. The determinant is the information that can be used to identify the characteristics of square matrices. Determinant of the matrix has many important and interesting applications. For example, to give formula to compute the inverse matrix of an invertible matrix, to construct the Cramer’s Rule to solve systems of linear equations, to give formulas to compute area of a triangle and volume of a tetrahedron, to test for collinear points in the plane, etc.

Given an integer number $k$, your task is to find the matrix of size $n \times n$ such that its determinant equals to $k$ and its elements must be integers between $1$ and $k-1$, inclusive.

Input

The input consists of several data sets. The first line of the input contains the number of data sets, which is a positive number and is not greater than 20. The following lines describe the data sets. Each data set is described by one line containing two integers $n$ and $k$ ($2 \leq n \leq 100$, $2 \leq k \leq 10^9$) which are the dimension of the matrix and the value of the determinant, respectively.

Output

For each data set, write out the result in the following format.

  • If you can find a required matrix, write out on the first line the string “YES” and then write out $n$ lines such that each line consists of $n$ integers. Elements of the matrix must be within [1, $k$-1] and its determinant must equal to $k$. If there are many such matrices, write out any of them.

  • Otherwise, write out on one line the string “NO”.

Sample Input 1 Sample Output 1
1
3 5

YES
3 1 1
1 2 2
3 1 2

Please log in to submit a solution to this problem

Log in