Problem: A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it!

You are given integers n,k. Construct a grid A with size n × n consisting of integers 0 and 1. The very important condition should be satisfied: the sum of all elements in the grid is exactly k. In other words, the number of 1 in the grid is equal to k.

Let's define:

  * A_{i,j} as the integer in the i-th row and the j-th column. 
  * R_i = A_{i,1}+A_{i,2}+...+A_{i,n} (for all 1 ≤ i ≤ n). 
  * C_j = A_{1,j}+A_{2,j}+...+A_{n,j} (for all 1 ≤ j ≤ n). 
  * In other words, R_i are row sums and C_j are column sums of the grid A. 
  * For the grid A let's define the value f(A) = (max(R)-min(R))^2 + (max(C)-min(C))^2 (here for an integer sequence X we define max(X) as the maximum value in X and min(X) as the minimum value in X). 



Find any grid A, which satisfies the following condition. Among such grids find any, for which the value f(A) is the minimum possible. Among such tables, you can find any.

Input

The input consists of multiple test cases. The first line contains a single integer t (1 ≤ t ≤ 100) — the number of test cases. Next t lines contain descriptions of test cases.

For each test case the only line contains two integers n, k (1 ≤ n ≤ 300, 0 ≤ k ≤ n^2).

It is guaranteed that the sum of n^2 for all test cases does not exceed 10^5.

Output

For each test case, firstly print the minimum possible value of f(A) among all tables, for which the condition is satisfied.

After that, print n lines contain n characters each. The j-th character in the i-th line should be equal to A_{i,j}.

If there are multiple answers you can print any.

Example

Input


4
2 2
3 8
1 0
4 16


Output


0
10
01
2
111
111
101
0
0
0
1111
1111
1111
1111

Note

In the first test case, the sum of all elements in the grid is equal to 2, so the condition is satisfied. R_1 = 1, R_2 = 1 and C_1 = 1, C_2 = 1. Then, f(A) = (1-1)^2 + (1-1)^2 = 0, which is the minimum possible value of f(A).

In the second test case, the sum of all elements in the grid is equal to 8, so the condition is satisfied. R_1 = 3, R_2 = 3, R_3 = 2 and C_1 = 3, C_2 = 2, C_3 = 3. Then, f(A) = (3-2)^2 + (3-2)^2 = 2. It can be proven, that it is the minimum possible value of f(A).

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1},
          dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
bool sort_pair_da(const pair<long long int, long long int>& a,
                  const pair<long long int, long long int>& b) {
  if (a.first != b.first) {
    return (a.first > b.first);
  } else
    return (a.second < b.second);
}
bool sort_pair_ad(const pair<long long int, long long int>& a,
                  const pair<long long int, long long int>& b) {
  if (a.first != b.first) {
    return (a.first < b.first);
  } else
    return (a.second > b.second);
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  if (!v.empty()) {
    copy(v.begin(), v.end(), ostream_iterator<T>(out, " "));
    out << "\n";
  }
  return out;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  for (auto it : v) {
    os << it;
    if (it != *v.rbegin()) os << " ";
  }
  os << "\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const multiset<T>& v) {
  for (auto it : v) {
    os << it;
    if (it != *v.rbegin()) os << " ";
  }
  os << "\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const pair<T, S>& v) {
  os << v.first << " " << v.second << "\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const map<T, S>& v) {
  for (auto it : v) os << it.first << " : " << it.second << "\n";
  return os;
}
template <typename T, typename S>
ostream& operator<<(ostream& os, const unordered_map<T, S>& v) {
  for (auto it : v) os << it.first << " : " << it.second << "\n";
  return os;
}
vector<int> sieve(long long int n) {
  vector<int> prime(n + 1, 0);
  vector<int> primes(n + 1, 0);
  int index = 0;
  for (int i = 2; i <= n; i++) {
    if (prime[i] == 0) {
      prime[i] = i;
      primes[index] = i;
      index++;
    }
    for (int j = 0; j < index && primes[j] <= prime[i] && i * primes[j] <= n;
         j++) {
      prime[primes[j] * i] = primes[j];
      if (i % primes[j] == 0) break;
    }
  }
  return prime;
}
long long int power(long long int a, long long int n) {
  long long int p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
    }
    n >>= 1;
    a *= a;
  }
  return p;
}
long long int powermodulo(long long int a, long long int n, long long int mod) {
  long long int p = 1;
  while (n > 0) {
    if (n % 2) {
      p = p * a;
      p %= mod;
    }
    n >>= 1;
    a *= a;
    a %= mod;
  }
  return p % mod;
}
class DSU {
 public:
  long long int n;
  vector<long long int> parent;
  vector<long long int> size;
  void init(long long int x) {
    n = x;
    for (long long int i = 0; i < x + 1; i++) {
      parent.push_back(i);
      size.push_back(1);
    }
  }
  long long int root(long long int x) {
    if (parent[x] == x) return x;
    return parent[x] = root(parent[x]);
  }
  void Union(long long int x, long long int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (size[x] < size[y]) swap(x, y);
      size[x] += size[y];
      parent[y] = x;
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    vector<vector<long long int> > a(n);
    long long int ones = 0;
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < n; j++) {
        if (i == j) {
          if (ones < k) {
            ones++;
            a[i].push_back(1);
          } else {
            a[i].push_back(0);
          }
        } else {
          a[i].push_back(0);
        }
      }
    }
    if (ones < k) {
      for (long long int i = 1; i < n; i++) {
        long long int col = i;
        for (long long int j = 0; j < n && col < n; j++) {
          if (a[j][col] == 0) {
            if (ones < k) {
              ones++;
              a[j][col] = 1;
            }
          }
          col++;
          col = col % n;
        }
      }
      for (long long int i = 1; i < n; i++) {
        long long int row = i;
        for (long long int j = 0; j < n && row < n; j++) {
          if (a[row][j] == 0) {
            if (ones < k) {
              ones++;
              a[row][j] = 1;
            }
          }
          row++;
          row = row % n;
        }
      }
    }
    long long int minr, maxr, maxc, minc;
    minr = minc = 100000000000;
    maxr = maxc = 0;
    for (long long int i = 0; i < n; i++) {
      long long int sumr = 0;
      for (long long int j = 0; j < n; j++) {
        sumr += a[i][j];
      }
      maxr = max(maxr, sumr);
      minr = min(minr, sumr);
    }
    for (long long int j = 0; j < n; j++) {
      long long int sumc = 0;
      for (long long int i = 0; i < n; i++) {
        sumc += a[i][j];
      }
      maxc = max(maxc, sumc);
      minc = min(minc, sumc);
    }
    long long int ans = 0;
    ans += ((maxc - minc) * (maxc - minc));
    ans += ((maxr - minr) * (maxr - minr));
    cout << ans << "\n";
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < n; j++) {
        cout << a[i][j];
      }
      cout << "\n";
    }
  }
}