Weird Competition

All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef is attending a chess competition. There are n people take part in. Each pair of people compete once. Winner earns 1 point, loser earns 0 point. A game never ends with a draw. After all games are over, Organizer decide to award prize to each participant. The prize of each participant is the square of his points. What is all possible total money the organizer will pay for all participants? Given k, determine if there is at least one scenario that the total money the organizers will pay is exactly k? If there's any, output one of them.
Input
First line contains an integer T denotes the number of test cases. The T following lines, each line contains two integers n, k.
Output
For each test case, if there isn't a such scenario, output 1.
otherwise print n lines, each line contains n characters. jth character in ith line is "1" if ith participant wins jth participant, otherwise "0". (ith character in ith line is always "0")
Constraints
 1 ≤ T ≤ 100
 1 ≤ n ≤ 10^{3}
 The sum of n over all test cases is at most 10^{4}
 1 ≤ k ≤ 10^{9}
Subtasks:
 Subtask #1 (10 points): n ≤ 5
 Subtask #2 (30 points): n ≤ 50
 Subtask #3 (60 points): original constrains
Example
Input: 3 2 1 3 6 4 10 Output: 01 00 1 0100 0011 1001 1000
Author:  chemthan 
Tester:  melfice 
Editorial  https://discuss.codechef.com/problems/WEICOM 
Tags  chemthan, constructive, ltime53, mediumhard 
Date Added:  23082017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 