You are given a connected, undirected and unweighted graph with $$$n$$$ vertices and $$$m$$$ edges. Notice the limit on the number of edges: $$$m \le n + 2$$$.Let's say we color some of the edges red and the remaining edges blue. Now consider only the red edges and count the number of connected components in the graph. Let this value be $$$c_1$$$. Similarly, consider only the blue edges and count the number of connected components in the graph. Let this value be $$$c_2$$$.Find an assignment of colors to the edges such that the quantity $$$c_1+c_2$$$ is minimised.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$n-1 \leq m \leq \min{\left(n+2,\frac{n \cdot (n-1)}{2}\right)}$$$) — the number of vertices and the number of edges respectively. $$$m$$$ lines follow. The $$$i$$$-th line contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i,v_i \le n$$$, $$$u_i \ne v_i$$$) denoting that the $$$i$$$-th edge goes between vertices $$$u_i$$$ and $$$v_i$$$. The input is guaranteed to have no multiple edges or self loops. The graph is also guaranteed to be connected. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$. It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$2 \cdot 10^6$$$.

For each test case, output a binary string of length $$$m$$$. The $$$i$$$-th character of the string should be 1 if the $$$i$$$-th edge should be colored red, and 0 if it should be colored blue. If there are multiple ways to assign colors to edges that give the minimum answer, you may output any.

Note The corresponding graph of the first test case is:  $$$c_1 + c_2 = 1 + 2 = 3$$$ The corresponding graph of the second test case is:  $$$c_1 + c_2 = 2 + 2 = 4$$$

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

const N = 2 * 10 ** 5 + 10,
      M = N * 2;
const h = new Array(N).fill(-1),
      e = new Array(M),
      ne = new Array(M),
      vis = new Array(N),
      res = new Array(M);
let idx = 0;
const add = (i, j) => (e[idx] = j, ne[idx] = h[i], h[i] = idx++);
function solve(read) {
  const rns = () => {
    return read().split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = rns();
  idx = 0;
  for (let i = 0; i < n; i++) {
    h[i] = -1;
    vis[i] = 0;
  }
  for (let i = 0; i < m; i++) {
    res[i] = 0;
    let [u, v] = read().split(' ').map(Number);
    u--, v--;
    add(u, v);
    add(v, u);
  }
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, i, p]);
      } else {
        vis[v] = 1;
        res[i >> 1] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j >> 1] = 1;
          res[p >> 1] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      if (t < 100) {
        process.stdout.write(solve(r));
        process.stdout.write('\n');
      } else {
        res[i] = solve(r);
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

const inputs = fs__default["default"].readFileSync(0, 'utf8').split('\n');
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
let h = new Array(N).fill(-1),
    e = new Array(M),
    ne = new Array(M),
    vis = new Array(N),
    res = new Array(M);
let idx = 0;
const add = (i, j) => (e[idx] = j, ne[idx] = h[i], h[i] = idx++);
let m, n;
async function main() {
  let t = Number(await read());
  new Date().valueOf();
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    for (let i = 0; i < n; i++) {
      h[i] = -1;
      vis[i] = 0;
    }
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v);
      add(v, u);
    }
    if (tt < 1000) {
      console.log(solve());
    } else output.push(solve());
  }
  if (tt >= 1000) console.log(output.join('\n'));
}
main();
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, i, p]);
      } else {
        vis[v] = 1;
        res[i >> 1] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j >> 1] = 1;
          res[p >> 1] = 0;
          break;
        }
      }
    }
  }
  return res.slice(0, m).join('');
}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

const inputs = fs__default["default"].readFileSync(0, 'utf8').split('\n');
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
let h = new Array(N).fill(-1),
    e = new Array(M),
    ne = new Array(M),
    vis = new Array(N),
    res = new Array(M);
let idx = 0;
const add = (i, j) => (e[idx] = j, ne[idx] = h[i], h[i] = idx++);
let m, n;
async function main() {
  let t = Number(await read());
  new Date().valueOf();
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    for (let i = 0; i < n; i++) {
      h[i] = -1;
      vis[i] = 0;
    }
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v);
      add(v, u);
    }
    if (tt < 1000) {
      console.log(solve());
    } else output.push(solve());
  }
  if (tt >= 1000) console.log(output.join('\n'));
}
main();
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, i, p]);
      } else {
        vis[v] = 1;
        res[i >> 1] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j >> 1] = 1;
          res[p >> 1] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

const inputs = fs__default["default"].readFileSync(0, 'utf8').split('\n');
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
let h = new Array(N).fill(-1),
    e = new Array(M),
    ne = new Array(M),
    vis = new Array(N),
    res = new Array(M);
let idx = 0;
const add = (i, j) => (e[idx] = j, ne[idx] = h[i], h[i] = idx++);
let m, n;
async function main() {
  let t = Number(await read());
  new Date().valueOf();
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    h = new Array(n).fill(-1);
    vis = new Array(n).fill(0);
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v);
      add(v, u);
    }
    if (tt < 1000) {
      process.stdout.write(solve());
      process.stdout.write('\n');
    } else output.push(solve());
  }
  if (tt >= 1000) process.stdout.write(output.join('\n'));
}
main();
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, i, p]);
      } else {
        vis[v] = 1;
        res[i >> 1] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j >> 1] = 1;
          res[p >> 1] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

const inputs = fs__default["default"].readFileSync(0, 'utf8').split('\n');
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
let h = new Array(N).fill(-1),
    e = new Array(M),
    ne = new Array(M),
    vis = new Array(N),
    res = new Array(M);
let idx = 0;
const add = (i, j) => (e[idx] = j, ne[idx] = h[i], h[i] = idx++);
let m, n;
async function main() {
  let t = Number(await read());
  new Date().valueOf();
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    for (let i = 0; i < n; i++) {
      h[i] = -1;
      vis[i] = 0;
    }
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v);
      add(v, u);
    }
    if (tt < 1000) {
      process.stdout.write(solve());
      process.stdout.write('\n');
    } else output.push(solve());
  }
  if (tt >= 1000) process.stdout.write(output.join('\n'));
}
main();
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, i, p]);
      } else {
        vis[v] = 1;
        res[i >> 1] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j >> 1] = 1;
          res[p >> 1] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

const inputs = fs__default["default"].readFileSync(0, 'utf8').split('\n');
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
let h = new Array(N).fill(-1),
    e = new Array(M),
    ne = new Array(M),
    vis = new Array(N),
    res = new Array(M);
let idx = 0;
const add = (i, j) => (e[idx] = j, ne[idx] = h[i], h[i] = idx++);
let m, n;
async function main() {
  new Date().valueOf();
  let t = Number(await read());
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    h = new Array(n).fill(-1);
    vis = new Array(n).fill(0);
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v);
      add(v, u);
    }
    {
      if (tt < 1000) {
        process.stdout.write(solve());
        process.stdout.write('\n');
      } else output.push(solve());
    }
  }
  if (tt >= 1000) process.stdout.write(output.join('\n'));
}
main();
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, i, p]);
      } else {
        vis[v] = 1;
        res[i >> 1] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j >> 1] = 1;
          res[p >> 1] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

const inputs = [];
const rl = readline__default["default"].createInterface({
  input: process.stdin
});
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', () => {
  main();
});
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
let h = new Array(N).fill(-1),
    e = new Array(M),
    ne = new Array(M),
    vis = new Array(N),
    res = new Array(M);
let idx = 0;
const add = (i, j) => (e[idx] = j, ne[idx] = h[i], h[i] = idx++);
let m, n;
async function main() {
  new Date().valueOf();
  let t = Number(await read());
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    h = new Array(n).fill(-1);
    vis = new Array(n).fill(0);
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v);
      add(v, u);
    }
    {
      if (tt < 1000) {
        process.stdout.write(solve());
        process.stdout.write('\n');
      } else output.push(solve());
    }
  }
  if (tt >= 1000) process.stdout.write(output.join('\n'));
}
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, i, p]);
      } else {
        vis[v] = 1;
        res[i >> 1] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j >> 1] = 1;
          res[p >> 1] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

const inputs = fs__default["default"].readFileSync(0, 'utf8').split('\n');
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
const p = new Array(N),
      edges = new Array(M),
      res = new Array(M);
const find = i => i === p[i] ? i : p[i] = find(p[i]);
const union = (i, j) => {
  const ri = find(i),
        rj = find(j);
  if (ri === rj) return false;
  p[rj] = ri;
  return true;
};
let m, n;
async function main() {
  let t = Number(await read());
  new Date().valueOf();
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    for (let i = 0; i < m; i++) {
      let [u, v] = (await read()).split(' ').map(Number);
      edges[i] = [u - 1, v - 1, i];
    }
    while (1) {
      for (let i = 0; i < n; i++) p[i] = i;
      for (let i = m - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [edges[i], edges[j]] = [edges[j], edges[i]];
      }
      let tmp = [];
      for (let i = 0; i < m; i++) {
        const [u, v, j] = edges[i];
        if (union(u, v)) {
          res[j] = 1;
        } else {
          res[j] = 0;
          tmp.push(u, v);
        }
      }
      if (tmp.length !== 3 || new Set(tmp).size !== 3) break;
    }
    if (tt < 1000) {
      console.log(res.slice(0, m).join(''));
    } else output.push(res.slice(0, m).join(''));
  }
  if (tt >= 1000) console.log(output.join('\n'));
}
main();

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

const inputs = fs__default["default"].readFileSync(0, 'utf8').split('\n');
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
const p = new Array(N),
      edges = new Array(M),
      res = new Array(M);
const find = i => i === p[i] ? i : p[i] = find(p[i]);
const union = (i, j) => {
  const ri = find(i),
        rj = find(j);
  if (ri === rj) return false;
  p[rj] = ri;
  return true;
};
let m, n;
async function main() {
  let t = Number(await read());
  new Date().valueOf();
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    for (let i = 0; i < m; i++) {
      let [u, v] = (await read()).split(' ').map(Number);
      edges[i] = [u - 1, v - 1, i];
    }
    while (1) {
      for (let i = 0; i < n; i++) p[i] = i;
      for (let i = m - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1));
        [edges[i], edges[j]] = [edges[j], edges[i]];
      }
      let tmp = [];
      for (let i = 0; i < m; i++) {
        const [u, v, j] = edges[i];
        if (union(u, v)) {
          res[j] = 1;
        } else {
          res[i] = 0;
          tmp.push(u, v);
        }
      }
      if (tmp.length !== 3 || new Set(tmp).size !== 3) break;
    }
    if (tt < 1000) {
      console.log(res.slice(0, m).join(''));
    } else output.push(res.slice(0, m).join(''));
  }
  if (tt >= 1000) console.log(output.join('\n'));
}
main();

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

const inputs = fs__default["default"].readFileSync(0, 'utf8').split('\n');
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
let h = new Array(N).fill(-1),
    e = new Array(M),
    ne = new Array(M),
    vis = new Array(N),
    res = new Array(M);
let idx = 0;
const add = (i, j) => (e[idx] = j, ne[idx] = h[i], h[i] = idx++);
let m, n;
async function main() {
  let t = Number(await read());
  const time = new Date().valueOf();
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    for (let i = 0; i < n; i++) {
      h[i] = -1;
      vis[i] = 0;
    }
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v);
      add(v, u);
    }
    if (tt < 1000) {
      process.stdout.write(solve());
      process.stdout.write('\n');
    } else output.push(solve());
  }
  if (tt >= 1000) process.stdout.write(output.join('\n'));
  console.log(new Date().valueOf() - time);
}
main();
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, i, p]);
      } else {
        vis[v] = 1;
        res[i >> 1] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j >> 1] = 1;
          res[p >> 1] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

const inputs = [];
const rl = readline__default["default"].createInterface({
  input: process.stdin
});
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', () => {
  main();
});
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
const h = new Array(N).fill(-1),
      e = new Array(M),
      ne = new Array(M);
const vis = new Array(N),
      res = new Array(M);
let idx = 0;
const add = (i, j) => (e[idx] = j, ne[idx] = h[i], h[i] = idx++);
let m, n;
async function main() {
  new Date().valueOf();
  let t = Number(await read());
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    for (let i = 0; i < m; i++) {
      h[i] = -1;
      vis[i] = 0;
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v);
      add(v, u);
    }
    if (m === n - 1) {
      h[n - 1] = -1;
      vis[n - 1] = 0;
    }
    {
      if (tt < 1000) {
        process.stdout.write(solve());
        process.stdout.write('\n');
      } else output.push(solve());
    }
  }
  if (tt >= 1000) process.stdout.write(output.join('\n'));
}
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, i, p]);
      } else {
        vis[v] = 1;
        res[i >> 1] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j >> 1] = 1;
          res[p >> 1] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

const inputs = [];
const rl = readline__default["default"].createInterface({
  input: process.stdin
});
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', () => {
  main();
});
const read = ((i = 0) => () => inputs[i++])();
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
const h = new Array(N).fill(-1),
      e = new Array(M),
      ne = new Array(M),
      w = new Array(M);
const vis = new Array(N),
      res = new Array(M);
let idx = 0;
const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
let m, n;
async function main() {
  const time = new Date().valueOf();
  let t = Number(await read());
  let tt = t;
  let output = [];
  let flag = false;
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    if (tt === 10 && n === 100000 && m === 100002) {
      flag = true;
    }
    idx = 0;
    for (let i = 0; i < n; i++) {
      h[i] = -1;
      vis[i] = 0;
    }
    for (let i = 0; i < m; i++) res[i] = 0;
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v, i);
      add(v, u, i);
    }
    if (!flag) output.push(solve());
  }
  if (!flag) console.log(output.join('\n'));
  if (flag) console.log(new Date().valueOf() - time);
}
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, w[i], p]);
      } else {
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j] = 1;
          res[w[p]] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

const inputs = [];
const rl = readline__default["default"].createInterface({
  input: process.stdin
});
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', () => {
  main();
});
const r = ((i = 0) => () => inputs[i++])();
async function read() {
  return r();
}
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
const h = new Array(N).fill(-1),
      e = new Array(M),
      ne = new Array(M),
      w = new Array(M);
const vis = new Array(N),
      res = new Array(M);
let idx = 0;
const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
let m, n;
async function main() {
  const time = new Date().valueOf();
  let t = Number(await read());
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    for (let i = 0; i < n; i++) {
      h[i] = -1;
      vis[i] = 0;
    }
    for (let i = 0; i < m; i++) res[i] = 0;
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v, i);
      add(v, u, i);
    }
    if (tt !== 100000) output.push(solve());
  }
  if (tt !== 100000) console.log(output.join('\n'));
  if (tt === 100000) console.log(new Date().valueOf() - time);
}
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, w[i], p]);
      } else {
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j] = 1;
          res[w[p]] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

const inputs = fs__default["default"].readFileSync(0, 'utf8').split('\n');
const r = ((i = 0) => () => inputs[i++])();
async function read() {
  return r();
}
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
const h = new Array(N).fill(-1),
      e = new Array(M),
      ne = new Array(M),
      w = new Array(M);
const vis = new Array(N),
      res = new Array(M);
let idx = 0;
const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
let m, n;
void async function () {
  const time = new Date().valueOf();
  let t = Number(await read());
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    for (let i = 0; i < n; i++) {
      h[i] = -1;
      vis[i] = 0;
    }
    for (let i = 0; i < m; i++) res[i] = 0;
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v, i);
      add(v, u, i);
    }
    if (tt !== 100000) output.push(solve());
  }
  if (tt !== 100000) console.log(output.join('\n'));
  if (tt === 100000) console.log(new Date().valueOf() - time);
}();
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, w[i], p]);
      } else {
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j] = 1;
          res[w[p]] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var stream = require('stream');
var string_decoder = require('string_decoder');

const matcher = /\r?\n/;
let last = '';
const docker = new string_decoder.StringDecoder('utf8');
const split = new stream.Transform({
  readableObjectMode: true,
  transform(chunk, encoding, callback) {
    var _list$pop;
    last += docker.write(chunk);
    const list = last.split(matcher);
    last = (_list$pop = list.pop()) !== null && _list$pop !== void 0 ? _list$pop : '';
    for (let line of list) {
      this.push(line);
    }
    callback();
  },
  flush(cb) {
    last += docker.end();
    if (last) this.push(last);
    cb();
  }
});
const fsread = process.stdin;
fsread.pause();
const readableStream = fsread.pipe(split);
const createReadAsyncGenerator = (() => {
  const endPromise = new Promise(function (resolve, reject) {
    readableStream.once('end', resolve);
  });
  return async function* () {
    while (!readableStream.readableEnded) {
      while (readableStream.readable) {
        const val = readableStream.read();
        if (val) yield val;else break;
      }
      const readablePromise = new Promise(resolve => {
        readableStream.once('readable', resolve);
      });
      await Promise.race([endPromise, readablePromise]);
    }
  };
})();
const r = createReadAsyncGenerator();
async function read() {
  return (await r.next()).value;
}
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
const h = new Array(N).fill(-1),
      e = new Array(M),
      ne = new Array(M),
      w = new Array(M);
const vis = new Array(N),
      res = new Array(M);
let idx = 0;
const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
let m, n;
void async function () {
  const time = new Date().valueOf();
  let t = Number(await read());
  let tt = t;
  let output = [];
  while (t--) {
    [n, m] = (await read()).split(' ').map(Number);
    idx = 0;
    for (let i = 0; i < n; i++) {
      h[i] = -1;
      vis[i] = 0;
    }
    for (let i = 0; i < m; i++) res[i] = 0;
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await read()).split(' ').map(Number);
      u--, v--;
      add(u, v, i);
      add(v, u, i);
    }
    if (tt !== 100000) output.push(solve());
  }
  if (tt !== 100000) console.log(output.join('\n'));
  if (tt === 100000) console.log(new Date().valueOf() - time);
}();
function solve() {
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, w[i], p]);
      } else {
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (m - n === 2) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      for (let [x, y, j, p] of tmp) {
        if (p !== -1) {
          res[j] = 1;
          res[w[p]] = 0;
          break;
        }
      }
    }
  }
  let s = '';
  for (let i = 0; i < m; i++) {
    s += res[i];
  }
  return s;
}

'use strict';

var stream = require('stream');
var string_decoder = require('string_decoder');

process.argv[2];
const matcher = /\r?\n/;
let last = '';
const docker = new string_decoder.StringDecoder('utf8');
const split = new stream.Transform({
  readableObjectMode: true,
  transform(chunk, encoding, callback) {
    var _list$pop;
    last += docker.write(chunk);
    const list = last.split(matcher);
    last = (_list$pop = list.pop()) !== null && _list$pop !== void 0 ? _list$pop : '';
    for (let line of list) {
      this.push(line);
    }
    callback();
  },
  flush(cb) {
    last += docker.end();
    if (last) this.push(last);
    cb();
  }
});
const fsread = process.stdin;
fsread.pause();
const readableStream = fsread.pipe(split);
const createReadAsyncGenerator = (() => {
  const endPromise = new Promise(function (resolve, reject) {
    readableStream.once('end', resolve);
  });
  return async function* () {
    while (!readableStream.readableEnded) {
      while (readableStream.readable) {
        const val = readableStream.read();
        if (val) yield val;else break;
      }
      const readablePromise = new Promise(resolve => {
        readableStream.once('readable', resolve);
      });
      await Promise.race([endPromise, readablePromise]);
    }
  };
})();
const read = createReadAsyncGenerator();
async function readline() {
  return (await read.next()).value;
}
const N = 2 * 10 ** 5 + 10,
      M = N * 2;
const h = new Array(N).fill(-1),
      e = new Array(M),
      ne = new Array(M),
      w = new Array(M);
const vis = new Array(N),
      res = new Array(M);
let idx = 0;
const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
let m, n;
void async function () {
  let t = Number(await readline());
  let tt = t;
  let output = '';
  while (t--) {
    [n, m] = (await readline()).split(' ').map(Number);
    idx = 0;
    for (let i = 0; i < n; i++) {
      h[i] = -1;
      vis[i] = 0;
    }
    for (let i = 0; i < m; i++) res[i] = 0;
    for (let i = 0; i < m; i++) {
      res[i] = 0;
      let [u, v] = (await readline()).split(' ').map(Number);
      u--, v--;
      add(u, v, i);
      add(v, u, i);
    }
    output += solve() + '\n';
  }
  console.log(output);
  function solve() {
    if (tt === 100000) return '';
    const queue = [[0, -1]];
    vis[0] = 1;
    let tmp = [];
    for (let [u, p] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (p ^ 1)) continue;
        const v = e[i];
        if (vis[v]) {
          tmp.push([u, v, w[i], p]);
        } else {
          vis[v] = 1;
          res[w[i]] = 1;
          queue.push([v, i]);
        }
      }
    }
    if (m - n === 2) {
      const nums = new Set();
      for (let [x, y] of tmp) {
        nums.add(x);
        nums.add(y);
      }
      if (nums.size === 3) {
        for (let [x, y, j, p] of tmp) {
          if (p !== -1) {
            res[j] = 1;
            res[w[p]] = 0;
            break;
          }
        }
      }
    }
    let s = '';
    for (let i = 0; i < m; i++) {
      s += res[i];
    }
    return s;
  }
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
{
  const N = 2 * 10 ** 5 + 10,
        M = N * 2;
  const h = new Array(N).fill(-1),
        e = new Array(M),
        ne = new Array(M),
        w = new Array(M);
  const vis = new Array(N),
        res = new Array(M);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  let i = -2,
      n,
      m;
  rl.on('line', line => {
    if (i === -2) ; else if (i === -1) {
      [n, m] = line.split(' ').map(Number);
      idx = 0;
      for (let i = 0; i < n; i++) {
        h[i] = -1;
        vis[i] = 0;
      }
      for (let i = 0; i < m; i++) res[i] = 0;
    } else {
      let [u, v] = line.split(' ').map(Number);
      u--, v--;
      add(u, v, i);
      add(v, u, i);
      if (i === m - 1) {
        solve();
        i = -2;
      }
    }
    i++;
  });
  rl.on('close', async () => {
  });
  function solve() {
    const queue = [[0, -1]];
    vis[0] = 1;
    let tmp = [];
    for (let [u, p] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (p ^ 1)) continue;
        const v = e[i];
        if (vis[v]) {
          tmp.push([u, v, w[i], p]);
        } else {
          vis[v] = 1;
          res[w[i]] = 1;
          queue.push([v, i]);
        }
      }
    }
    if (m - n === 2) {
      const nums = new Set();
      for (let [x, y] of tmp) {
        nums.add(x);
        nums.add(y);
      }
      if (nums.size === 3) {
        for (let [x, y, j, p] of tmp) {
          if (p !== -1) {
            res[j] = 1;
            res[w[p]] = 0;
            break;
          }
        }
      }
    }
    let s = '';
    for (let i = 0; i < m; i++) {
      s += res[i];
    }
    console.log(s);
  }
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
{
  const N = 2 * 10 ** 5 + 10,
        M = N * 2;
  const h = new Array(N).fill(-1),
        e = new Array(M),
        ne = new Array(M),
        w = new Array(M);
  const vis = new Array(N),
        res = new Array(M);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  let i = 0,
      j = -1,
      n,
      m;
  rl.on('line', line => {
    if (i === 0) ;else if (j === -1) {
      [n, m] = line.split(' ').map(Number);
      j = 0;
      idx = 0;
      for (let i = 0; i < n; i++) {
        h[i] = -1;
        vis[i] = 0;
      }
      for (let i = 0; i < m; i++) res[i] = 0;
    } else if (j < m) {
      let [u, v] = line.split(' ').map(Number);
      u--, v--;
      add(u, v, j);
      add(v, u, j);
      j++;
      if (j === m) {
        solve();
        j = -1;
      }
    }
    i++;
  });
  rl.on('close', async () => {
  });
  function solve() {
    const queue = [[0, -1]];
    vis[0] = 1;
    let tmp = [];
    for (let [u, p] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (p ^ 1)) continue;
        const v = e[i];
        if (vis[v]) {
          tmp.push([u, v, w[i], p]);
        } else {
          vis[v] = 1;
          res[w[i]] = 1;
          queue.push([v, i]);
        }
      }
    }
    if (m - n === 2) {
      const nums = new Set();
      for (let [x, y] of tmp) {
        nums.add(x);
        nums.add(y);
      }
      if (nums.size === 3) {
        for (let [x, y, j, p] of tmp) {
          if (p !== -1) {
            res[j] = 1;
            res[w[p]] = 0;
            break;
          }
        }
      }
    }
    let s = '';
    for (let i = 0; i < m; i++) {
      s += res[i];
    }
    console.log(s);
  }
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
{
  const N = 2 * 10 ** 5 + 10,
        M = N * 2;
  const h = new Array(N).fill(-1),
        e = new Array(M),
        ne = new Array(M),
        w = new Array(M);
  const vis = new Array(N),
        res = new Array(M);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  let i = 0,
      j = -1,
      n,
      m;
  rl.on('line', line => {
    if (i === 0) ;else if (j === -1) {
      [n, m] = line.split(' ').map(Number);
      j = 0;
      idx = 0;
      for (let i = 0; i < n; i++) {
        h[i] = -1;
        vis[i] = 0;
      }
      for (let i = 0; i < m; i++) res[i] = 0;
    } else if (j < m) {
      let [u, v] = line.split(' ').map(Number);
      u--, v--;
      add(u, v, j);
      add(v, u, j);
      j++;
      if (j === m) {
        solve();
        j = -1;
      }
    }
    i++;
  });
  rl.on('close', async () => {
  });
  function solve() {
    const queue = [[0, -1]];
    vis[0] = 1;
    let tmp = [];
    for (let [u, p] of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        if (i === (p ^ 1)) continue;
        const v = e[i];
        if (vis[v]) {
          tmp.push([u, v, w[i], p]);
        } else {
          vis[v] = 1;
          res[w[i]] = 1;
          queue.push([v, i]);
        }
      }
    }
    if (m - n === 2) {
      const nums = new Set();
      for (let [x, y] of tmp) {
        nums.add(x);
        nums.add(y);
      }
      if (nums.size === 3) {
        for (let [x, y, j, p] of tmp) {
          if (p !== -1) {
            res[j] = 1;
            res[w[p]] = 0;
            break;
          }
        }
      }
    }
    let s = '' + '';
    for (let i = 0; i < m; i++) {
      s += res[i];
    }
    process.stdout.write(s + '\n');
  }
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = new Array(2 * m + 10),
        ne = new Array(2 * m + 10),
        w = new Array(2 * m + 10);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  for (let i = 0; i < m; i++) {
    let [u, v] = await rns();
    u--, v--;
    add(u, v, i);
    add(v, u, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, w[i]]);
      } else {
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (tmp.length === 6) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      out: for (let [x, y, j] of tmp) {
        for (let i = h[y]; ~i; i = ne[i]) {
          const v = e[i];
          if (nums.has(v)) continue;
          res[j] = 1;
          res[w[i]] = 0;
          break out;
        }
      }
    }
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = new Array(2 * m + 10),
        ne = new Array(2 * m + 10),
        w = new Array(2 * m + 10);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  for (let i = 0; i < m; i++) {
    let [u, v] = await rns();
    u--, v--;
    add(u, v, i);
    add(v, u, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const queue = [[0, -1]];
  vis[0] = 1;
  let tmp = [];
  for (let [u, p] of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      if (i === (p ^ 1)) continue;
      const v = e[i];
      if (vis[v]) {
        tmp.push([u, v, w[i]]);
      } else {
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push([v, i]);
      }
    }
  }
  if (tmp.length === 6) {
    const nums = new Set();
    for (let [x, y] of tmp) {
      nums.add(x);
      nums.add(y);
    }
    if (nums.size === 3) {
      out: for (let [x, y, j] of tmp) {
        for (let i = h[x]; ~i; i = ne[i]) {
          const v = e[i];
          if (nums.has(v)) continue;
          res[j] = 1;
          res[w[i]] = 0;
          break out;
        }
      }
    }
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = new Array(2 * m + 10),
        ne = new Array(2 * m + 10),
        w = new Array(2 * m + 10);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  const map = new Array(m);
  for (let i = 0; i < m; i++) {
    let [u, v] = await rns();
    u--, v--;
    map[i] = idx;
    add(u, v, i);
    add(v, u, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const queue = [0];
  vis[0] = 1;
  for (let u of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      const v = e[i];
      if (vis[v]) continue;
      vis[v] = 1;
      res[w[i]] = 1;
      queue.push(v);
    }
  }
  for (let i = 0; i < m; i++) {
    if (!res[i]) {
      e[map[i]];
            e[map[i] ^ 1];
    }
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = new Array(2 * m + 10),
        ne = new Array(2 * m + 10),
        w = new Array(2 * m + 10);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  const map = new Array(m);
  for (let i = 0; i < m; i++) {
    let [u, v] = await rns();
    u--, v--;
    map[i] = idx;
    add(u, v, i);
    add(v, u, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const queue = [0];
  vis[0] = 1;
  for (let u of queue) {
    for (let i = h[u]; ~i; i = ne[i]) {
      const v = e[i];
      if (vis[v]) continue;
      vis[v] = 1;
      res[w[i]] = 1;
      queue.push(v);
    }
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = new Array(2 * m + 10),
        ne = new Array(2 * m + 10),
        w = new Array(2 * m + 10),
        d = new Array(n).fill(0);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++, d[j]++);
  for (let i = 0; i < m; i++) {
    const [u, v] = await rns();
    add(u - 1, v - 1, i);
    add(v - 1, u - 1, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const bfs = i => {
    const queue = [i];
    vis[i] = 1;
    for (let u of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push(v);
      }
    }
  };
  const idxs = [...new Array(n).keys()].sort((a, b) => d[b] - d[a]);
  for (let i of idxs) {
    if (!vis[i]) bfs(i);
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const res = new Array(m).fill(0);
  const p = [...new Array(n).keys()];
  const find = i => i === p[i] ? i : p[i] = find(p[i]);
  for (let i = 0; i < m; i++) {
    let [u, v] = await rns();
    u--, v--;
    if (find(u) !== find(v)) {
      p[find(v)] = find(u);
      res[i] = 1;
    }
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = new Array(2 * m + 10),
        ne = new Array(2 * m + 10),
        w = new Array(2 * m + 10);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  for (let i = 0; i < m; i++) {
    const [u, v] = await rns();
    add(u - 1, v - 1, i);
    add(v - 1, u - 1, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const bfs = i => {
    const queue = [i];
    for (let u of queue) {
      vis[u] = 1;
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push(v);
      }
    }
  };
  for (let i = n - 1; i >= 0; i--) {
    if (!vis[i]) bfs(i);
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), ne.push(h[i]), w.push(c), h[i] = ne.length - 1);
  for (let i = 0; i < m; i++) {
    const [u, v] = await rns();
    add(u - 1, v - 1, i);
    add(v - 1, u - 1, i);
  }
  const vis = [],
        res = new Array(m).fill(0);
  const bfs = i => {
    const queue = [i];
    vis[i] = 1;
    for (let u of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push(v);
      }
    }
  };
  for (let i = 0; i < n; i++) {
    if (!vis[i]) bfs(i);
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), ne.push(h[i]), w.push(c), h[i] = ne.length - 1);
  for (let i = 0; i < m; i++) {
    const [u, v] = await rns();
    add(u - 1, v - 1, i);
    add(v - 1, u - 1, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const bfs = i => {
    const queue = [i];
    vis[i] = 1;
    for (let u of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push(v);
      }
    }
  };
  for (let i = 0; i < n; i++) {
    if (!vis[i]) bfs(i);
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = new Array(2 * m + 10),
        ne = new Array(2 * m + 10),
        w = new Array(2 * m + 10);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  for (let i = 0; i < m; i++) {
    const [u, v] = await rns();
    add(u - 1, v - 1, i);
    add(v - 1, u - 1, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const bfs = i => {
    const queue = [i];
    for (let u of queue) {
      vis[u] = 1;
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push(v);
      }
    }
  };
  for (let i = 0; i < n; i++) {
    if (!vis[i]) bfs(i);
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), w.push(c), ne.push(h[i]), h[i] = ne.length - 1);
  for (let i = 0; i < m; i++) {
    const [u, v] = await rns();
    add(u - 1, v - 1, i);
    add(v - 1, u - 1, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const bfs = i => {
    const queue = [i];
    vis[i] = 1;
    for (let u of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push(v);
      }
    }
  };
  for (let i = 0; i < n; i++) {
    if (!vis[i]) bfs(i);
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = new Array(2 * m + 10),
        ne = new Array(2 * m + 10),
        w = new Array(2 * m + 10);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  for (let i = 0; i < m; i++) {
    const [u, v] = await rns();
    add(u - 1, v - 1, i);
    add(v - 1, u - 1, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const bfs = i => {
    const queue = [i];
    vis[i] = 1;
    for (let u of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push(v);
      }
    }
  };
  for (let i = 0; i < n; i++) {
    if (!vis[i]) bfs(i);
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
let inputs = [];
let i = 0;
function read() {
  return inputs[i++];
}
rl.on('line', line => {
  inputs.push(line);
});
rl.on('close', async () => {
  const output = await main(read);
  process.stdout.write(output);
});

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = new Array(2 * m + 10),
        ne = new Array(2 * m + 10),
        w = new Array(2 * m + 10);
  let idx = 0;
  const add = (i, j, c) => (e[idx] = j, ne[idx] = h[i], w[idx] = c, h[i] = idx++);
  for (let i = 0; i < m; i++) {
    const [u, v] = await rns();
    add(u - 1, v - 1, i);
    add(v - 1, u - 1, i);
  }
  const vis = new Array(n),
        res = new Array(m).fill(0);
  const bfs = i => {
    const queue = [i];
    vis[i] = 1;
    for (let u of queue) {
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push(v);
      }
    }
  };
  for (let i = 0; i < n; i++) {
    if (!vis[i]) bfs(i);
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
void async function () {
  let idx = 0;
  const read = () => inputs[idx++];
  const output = await main(read);
  process.stdout.write(output);
}();

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

async function solve(read) {
  const rns = async () => {
    return (await read()).split(' ').filter(s => s !== '').map(Number);
  };
  const [n, m] = await rns();
  const h = new Array(n).fill(-1),
        e = [],
        ne = [],
        w = [];
  const add = (i, j, c) => (e.push(j), ne.push(h[i]), w.push(c), h[i] = ne.length - 1);
  for (let i = 0; i < m; i++) {
    const [u, v] = await rns();
    add(u - 1, v - 1, i);
  }
  const vis = [],
        res = new Array(m).fill(0);
  const bfs = i => {
    const queue = [i];
    for (let u of queue) {
      vis[u] = 1;
      for (let i = h[u]; ~i; i = ne[i]) {
        const v = e[i];
        if (vis[v]) continue;
        vis[v] = 1;
        res[w[i]] = 1;
        queue.push(v);
      }
    }
  };
  for (let i = 0; i < n; i++) {
    if (!vis[i]) bfs(i);
  }
  return res.join('');
}

async function main(r) {
  try {
    let t = Number(await r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      res[i] = await solve(r);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
const it = rl[Symbol.asyncIterator]();
async function read() {
  return (await it.next()).value;
}
void async function () {
  const output = await main(read);
  process.stdout.write(output);
}();


You are given four positive integers $$$n$$$, $$$m$$$, $$$a$$$, $$$b$$$ ($$$1 \le b \le n \le 50$$$; $$$1 \le a \le m \le 50$$$). Find any such rectangular matrix of size $$$n \times m$$$ that satisfies all of the following conditions:  each row of the matrix contains exactly $$$a$$$ ones;  each column of the matrix contains exactly $$$b$$$ ones;  all other elements are zeros. If the desired matrix does not exist, indicate this.For example, for $$$n=3$$$, $$$m=6$$$, $$$a=2$$$, $$$b=1$$$, there exists a matrix satisfying the conditions above:$$$$$$ \begin{vmatrix} 0 & 1 & 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 & 0 \end{vmatrix} $$$$$$

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case is described by four positive integers $$$n$$$, $$$m$$$, $$$a$$$, $$$b$$$ ($$$1 \le b \le n \le 50$$$; $$$1 \le a \le m \le 50$$$), where $$$n$$$ and $$$m$$$ are the sizes of the matrix, and $$$a$$$ and $$$b$$$ are the number of ones for rows and columns, respectively.

For each test case print:   "YES" (without quotes) and the required matrix (if there are several answers, print any) if it exists, or  "NO" (without quotes) if it does not exist.  To print the matrix $$$n \times m$$$, print $$$n$$$ rows, each of which consists of $$$m$$$ numbers $$$0$$$ or $$$1$$$ describing a row of the matrix. Numbers must be printed without spaces.

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2

**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

function main() {
    let range = readline();

    for(let r=0;r<range;r++) {
        let [n, m, a, b] = readline().split(" ").map(Number);

        if(n * a !== m * b) {
            console.log('No');
            continue;
        }

        const solution = [];
        for(let i=0;i<n;i++) {
            solution[i] = [];
            for(let j=0;j<m;j++) {
                solution[i][j] = 0;
            }
        }
        let pos = 0;
        for(let i=0;i<n;i++) {
            for(let j=0;j<a;j++) {
                pos++;
                if(pos === m) {
                    pos = 0;
                }

                solution[i][pos] = 1;
            }
        }

        console.log('YES');
        for(let i=0;i<solution.length;i++) {
            console.log(solution[i].join(""));
        }

    }
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2

**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

function main() {
    let range = readline();

    for(let r=0;r<range;r++) {
        let [n, m, a, b] = readline().split(" ").map(Number);

        if(n * a !== m * b) {
            console.log('No');
            continue;
        }

        const row = new Array(n).fill(a);
        const column = new Array(m).fill(b);
        const solution = [];

        for(let i=0;i<n;i++) {
            solution[i] = [];
            for(let j=0;j<m;j++) {
                if(row[i] && column[j]) {
                    solution[i][j] = 1;
                    row[i]--;
                    column[j]--;
                } else {
                    solution[i][j] = 0;
                }
            }
        }

        console.log('YES');
        for(let i=0;i<solution.length;i++) {
            console.log(solution[i].join(""));
        }

    }
}


Timur has $$$n$$$ candies. The $$$i$$$-th candy has a quantity of sugar equal to $$$a_i$$$. So, by eating the $$$i$$$-th candy, Timur consumes a quantity of sugar equal to $$$a_i$$$.Timur will ask you $$$q$$$ queries regarding his candies. For the $$$j$$$-th query you have to answer what is the minimum number of candies he needs to eat in order to reach a quantity of sugar greater than or equal to $$$x_j$$$ or print -1 if it's not possible to obtain such a quantity. In other words, you should print the minimum possible $$$k$$$ such that after eating $$$k$$$ candies, Timur consumes a quantity of sugar of at least $$$x_j$$$ or say that no possible $$$k$$$ exists.Note that he can't eat the same candy twice and queries are independent of each other (Timur can use the same candy in different queries).

The first line of input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$)  — the number of test cases. The description of test cases follows. The first line contains $$$2$$$ integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 1.5\cdot10^5$$$) — the number of candies Timur has and the number of queries you have to print an answer for respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^4$$$) — the quantity of sugar in each of the candies respectively. Then $$$q$$$ lines follow.  Each of the next $$$q$$$ lines contains a single integer $$$x_j$$$ ($$$1 \leq x_j \leq 2 \cdot 10^9$$$) – the quantity Timur wants to reach for the given query. It is guaranteed that the sum of $$$n$$$ and the sum of $$$q$$$ over all test cases do not exceed $$$1.5 \cdot 10^5$$$.

For each test case output $$$q$$$ lines. For the $$$j$$$-th line output the number of candies Timur needs to eat in order to reach a quantity of sugar greater than or equal to $$$x_j$$$ or print -1 if it's not possible to obtain such a quantity.

NoteFor the first test case:For the first query, Timur can eat any candy, and he will reach the desired quantity.For the second query, Timur can reach a quantity of at least $$$10$$$ by eating the $$$7$$$-th and the $$$8$$$-th candies, thus consuming a quantity of sugar equal to $$$14$$$.For the third query, there is no possible answer.For the fourth query, Timur can reach a quantity of at least $$$14$$$ by eating the $$$7$$$-th and the $$$8$$$-th candies, thus consuming a quantity of sugar equal to $$$14$$$.For the second test case:For the only query of the second test case, we can choose the third candy from which Timur receives exactly $$$3$$$ sugar. It's also possible to obtain the same answer by choosing the fourth candy.

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
var _loop_1 = function () {
    var _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], q = _a[1];
    var a = readline().split(' ').map(function (v) { return +v; });
    a.sort(function (a, b) { return b - a; }).reduce(function (sum, _, i) { return a[i] += sum; });
    loop: for (var i = 0; i < q; i++) {
        var k = +readline();
        var l = 0, r = n;
        while (l < r) {
            var m = Math.trunc((l + r) / 2);
            if (a[m] < k) {
                l = m + 1;
            }
            else {
                r = m;
            }
        }
        print(l === n ? -1 : l + 1);
    }
};
while (t--) {
    _loop_1();
}

const mergeSort = arr=>{
  const merge = (arr1,arr2)=>{
    let res = [],i=0,j=0;
    while(i<arr1.length && j<arr2.length){
      if(arr1[i]>=arr2[j]) res.push(arr1[i++]);
      else res.push(arr2[j++]);
    }
    while(i<arr1.length) res.push(arr1[i++]);
    while(j<arr2.length) res.push(arr2[j++]);
    return res;
  }
  const helper = (start,end,arr)=>{
    if(start===end) return [arr[start]];
    let mid = Math.floor((start+end)/2);
    return merge(helper(start,mid,arr),helper(mid+1,end,arr));
  }
  return helper(0,arr.length-1,arr);
}
const solve = (start, end, arr, q) => {
  if (start === end) return start + 1;
  let mid = Math.floor((start + end) / 2);
  if (q > arr[mid]) return solve(mid + 1, end, arr, q);
  else if (q < arr[mid]) return solve(start, mid, arr, q);
  else return mid + 1;
};
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for (let i = 0; i < t; i++) {
    let [n, q] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = mergeSort(readline().trim().split(" ").map(cur=>parseInt(cur)));
    for(let i=1;i<n;i++) arr[i]+=arr[i-1];
    for(let i=0;i<q;i++){
      let s = parseInt(readline());
      if(s>arr[n-1]) console.log(-1);
      else if(s<=arr[0]) console.log(1);
      else console.log(solve(0,n-1,arr,s));
    }
  }
}
main();

const solve = (start, end, arr, q) => {
  if (start === end) return start + 1;
  let mid = Math.floor((start + end) / 2);
  if (q > arr[mid]) return solve(mid + 1, end, arr, q);
  else if (q < arr[mid]) return solve(start, mid, arr, q);
  else return mid + 1;
};
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for (let i = 0; i < t; i++) {
    let [n, q] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
    arr.sort((a,b)=>b-a);
    for(let i=1;i<n;i++) arr[i]+=arr[i-1];
    for(let i=0;i<q;i++){
      let s = parseInt(readline());
      if(s>arr[n-1]) console.log(-1);
      else if(s<=arr[0]) console.log(1);
      else console.log(solve(0,n-1,arr,s));
    }
  }
}
main();

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	// console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

function Main(){
    // test case in nodeJs
	var t = nextInt();
	while(hasNext()){
		solve();
	}
}

function solve() {
    const num = nextInt();
    const queryNo = nextInt();
    const arr = nextIntArray(num);
    const queries = nextIntArray(queryNo);
    arr.sort((a, b) => b - a)
    let sum = 0;
    const prefixSumArr = arr.map(ele => {
        sum += ele;
        return sum;
    });
    // console.log(prefixSumArr);

    for (let i = 0; i < queries.length; i++) {
        const q = queries[i];
        if (q > prefixSumArr[prefixSumArr.length - 1]) {
            myout(-1)
        } else {
            myout(bsearch(prefixSumArr, q))
            // for (let index = 0; index < prefixSumArr.length; index++) {
            //     if (q <= prefixSumArr[index]){
            //         myout(index + 1);
            //         break;
            //     }
            // }
        }
    }
}

function bsearch (prefixSumArr, q) {
    let left = 0;
    let right = prefixSumArr.length - 1;
    while (left < right) {
        const mid = Math.floor(left + (right - left )/ 2);
        if (prefixSumArr[mid] === q) {
            return mid + 1;
        } else if (prefixSumArr[mid] < q) {
            left = mid + 1;
        } else {
            right = mid;
        }
    }
    return left + 1;
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  main();
});

function input() {
  return inputString[currentLine++];
}

function main() {
  let tc = parseInt(input());
  while(tc--){
    const [n, q] = input().split(' ').map(Number);
    const a = input().split(' ').map(Number);
    a.sort((a, b) => {
      if(a > b) return -1;
      else return 1;
    });
    for(let i = 1; i < n; i++){
      a[i] += a[i-1];
    }
    for(let i = 0; i < q; i++){
      let x = parseInt(input());
      let j = lower_bound(a, x);
      if(j === n) console.log(-1);
      else console.log(j+1);
    }
  }
}

const lower_bound = (a, key) => {
  let m = 0;
  let l = 0;
  let r = a.length-1;
  while(l <= r){
    m = Math.floor((l+r)/2);
    if(key <= a[m]) r = m-1;
    else l = m+1;
  }
  if(key > a[m]) return m+1;
  else return m;
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, m, a, b) {
  a.sort((a, b) => b - a);
  const query = b.map((num, i) => [num, i]).sort((a, b) => a[0] - b[0]);
  let cur = 0,
      res = [];
  let j = 0;
  for (let i = 0; i < n && j < m; i++) {
    cur += a[i];
    while (j < m && query[j][0] <= cur) {
      res[query[j][1]] = i + 1;
      j++;
    }
  }
  while (j < m) {
    res[query[j][1]] = -1;
    j++;
  }
  return res.join('\n');
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const [n, m] = (await read()).split(' ').map(Number);
    const a = (await read()).split(' ').map(Number);
    const b = [];
    let tmp = m;
    while (tmp--) {
      b.push(Number(await read()));
    }
    res.push(solve(n, m, a, b));
  }
  console.log(res.join('\n'));
}

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\r\n');
let currentline = 0;
function readline(){
      return input[currentline++];
}

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
var T = readline();
for(var q=1;q<=T;q++) {
  var [n, qu] = readline().split(' ').map((x)=>parseInt(x));
  var a = readline().split(' ').map((x)=>parseInt(x));
  a.sort(function(r,t) { return t-r });
  var pref = [];
  pref[0] = a[0];
  var sum = a[0];
  for(var i=1;i<n;i++) {
    pref[i] = pref[i-1]+a[i];
    sum += a[i];
  }
  for(var i=0;i<qu;i++) {
    var s =  readline();
    var ans = bin(s);
    //fs.appendFileSync('output.txt', ans+'\r\n');
    console.log(ans)
  }
  function bin(x) {
    var l=0, r=n-1;
    while(l<=r) {
      var mid = l+Math.floor((r-l)/2);
      if(pref[mid] >= x) r = mid-1;
      else l = mid+1;
    }
    return l>n-1 || l<0 ? -1 : l+1;
  }
  //console.log(q);
  //fs.appendFileSync('output.txt', tar+'\r\n');

  //os.EOL
}
//fs.writeFileSync('output.txt', f.join(' '));

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, q] = lines[l++].trim().split(' ').map(Number)
        const arr = lines[l++].trim().split(' ').map(Number)
        const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))
        l += q
        output[i] = solve(n, arr, qs)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr, qs) {
    arr.sort((a, b) => b - a)
    const sum = []
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        sum[i] = i ? sum[i - 1] + x : x
    }
    return qs.map(q => {
        const need = binarySearch(0, n - 1, x => {
            return sum[x] < q
        }) + 1
        return need < n ? need + 1 : -1
    }).join('\n')
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var Q = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return b - a;
		});
		var max = 0;
		var sum = new Array(N + 1);
		sum[0] = 0;
		for(var i = 0; i < N; i++){
			sum[i + 1] = sum[i] + list[i];
		}
		max = sum[N];
		for(var i = 0; i < Q; i++){
			var xi = nextInt();
			if(max < xi){
				myout(-1);
				continue;
			}
			var index = binarySearch(sum, xi, "ceiling");
			myout(index);
		}
	}
}
function binarySearch(list, search, method){
	var ng = 0;
	var ok = list.length - 1;
	var center;
	while(Math.abs(ok - ng) > 1){
		center = Math.floor((ok + ng) / 2);
		switch(method){
			case "floor":
				if(list[center] > search){
					ok = center;
				}else{
					ng = center;
				}
				break;
			case "ceiling":
				if(list[center] < search){
					ng = center;
				}else{
					ok = center;
				}
				break;
			case "lower":
				if(list[center] >= search){
					ok = center;
				}else{
					ng = center;
				}
				break;
			case "higher":
				if(list[center] <= search){
					ng = center;
				}else{
					ok = center;
				}
				break;
		}
	}
	if(method == "floor" || method == "lower"){
		return ng;
	}else{
		return ok;
	}
}

'use strict';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

const lines = [];
const rl = require('readline').createInterface({
   input: process.stdin, output: process.stdout});
rl.on('line', line=>{
  lines.push(line);
});
rl.on('close', main);
let rli = 0;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`Test #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let [n, q] = ra();
  let A = ra();
  LT({n, q, A});
  // PROCESSING:
  let S = new Array(n).fill(0)
  A.sort((a, b)=>b-a);
  for (let i=0; i<n; i++){
    S[i] = (i ? S[i-1] : 0)+A[i];
  }
  let ans = (cnt)=>{
    if (S[n-1]<cnt)
      return -1;
    let l = 0, r = n;
    while (l<r){
      let m = Math.floor((l+r)/2);
      if (S[m]>=cnt){
        r = m;
      } else {
        l = m+1;
      }
    }
    return l+1;
  };
  for (let i=0; i<q; i++){
    print(ans(+readline()));
  };
};

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    var _a = readline().split(' ').map(function (v) { return +v; }), n = _a[0], q = _a[1];
    var a = readline().split(' ').map(function (v) { return +v; });
    a.sort();
    loop: for (var i = 0; i < q; i++) {
        var k = +readline();
        var sum = 0;
        var j = n;
        while (j--) {
            sum += a[j];
            if (sum >= k) {
                print(n - j);
                continue loop;
            }
        }
        print(-1);
    }
}