/*
File Created: Tuesday, 17 May 2022
Author: Lukas Rimkus
*/
'use strict';

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

let data = '';
let currentLine = 0;

process.stdin.on('data', chunk => {
     data += chunk;
});
process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '').split('\n').map(str => str.replace(/\s*$/, ''));
    let testCases = parseInt(readLine());
    while(testCases--) {
        const [n,m] =  get_ints();
        const arr = [];
        for (let index = 0; index < n; index++) {
            arr.push(readLine().split(' ').map(x=>Number(x)))
        }
        console.log(solve([n,m,arr]));
    }
});
function get_ints() {
    return data[currentLine++].split(' ').map(x=>Number(x));
}

function readLine() {
    return data[currentLine++];
}

function solve(input){
    let res = 0;
    for (let row = 0; row < input[0]; row++) {
        for(let col = 0; col < input[1]; col++){
            const sum = calcDiagonalSum(input[0],input[1],row,col, input[2]);
            if(sum > res){
                res = sum;
            }
        }
    }
    return res;
}

function calcDiagonalSum(rows,cols,currRow,currCol, array){
    let sum = array[currRow][currCol];
    // console.log('rows,cols,currRow,currCol, array',array[currRow][currCol])
    let j = currCol + 1;
    for(let i = currRow + 1; i < rows; i++){
        if(!isNaN(array[i][j])) sum+=array[i][j];
        j++;
    }
    // calc right, top
    j = currCol + 1;
    for (let i = currRow - 1; i >= 0; i--) {
        if(!isNaN(array[i][j])) sum+=array[i][j];
        j++;
    }
    // calc left, botm
    j = currCol - 1;
    for(let i=currRow + 1; i < rows; i++ ){
        if(!isNaN(array[i][j])) sum+=array[i][j];
        j--;
    }
    // calc left, top
    j = currCol - 1;
    for(let i = currRow - 1; i >= 0; i--){
        if(!isNaN(array[i][j])) sum+=array[i][j];
        j--;
    }

    return sum;
}

module.exports = solve;

'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, m] = ra();
  let A = [];
  for (let i=0; i<n; i++) A.push(ra())
  LT({n, m, A});
  // PROCESSING:
  let add = (i, j)=>{
    if (i<0 || i>=n)
      return 0;
    if (j<0 || j>=m)
      return 0;
    return A[i][j]
  }
  let ch = (pi, pj)=>{
    let sum = A[pi][pj];
    for (let i=1; i<n; i++){
      sum += add(pi+i, pj+i);
      sum += add(pi+i, pj-i);
      sum += add(pi-i, pj+i);
      sum += add(pi-i, pj-i);
    }
    return sum;
  };
  let ans = 0;
  for (let i=0; i<n; i++){
    for (let j=0; j<m; j++){
      ans = Math.max(ans, ch(i, j))
    }
  }
  return ans;
};

s = parseInt(readline());
for(f = 0; f < s; f++)
{
    var n = readline().split(" ");
    n[0] = parseInt(n[0]);
    n[1] = parseInt(n[1]);
    var strings = [];
    for(i = 0; i < n[0]; i++)
    {
        strings[i] = readline().split(" ");
    }

    var max = 0;
    var sum = 0;
    for(i = 0; i < n[0]; i++)
    {
        for(j = 0; j < n[1]; j++)
        {
            sum = 0;
            sum += parseInt(strings[i][j]);
            var t = 1;
            while(i + t < n[0] && j + t < n[1])
            {
                sum += parseInt(strings[i + t][j + t]);
                t++;
            }
            t = 1;
            while(i + t < n[0] && j - t >= 0)
            {
                sum += parseInt(strings[i + t][j - t]);
                t++;
            }
            t = 1;
            while(i - t >= 0 && j + t < n[1])
            {
                sum += parseInt(strings[i - t][j + t]);
                t++;
            }
            t = 1;
            while(i - t >= 0 && j - t >= 0)
            {
                sum += parseInt(strings[i - t][j - t]);
                t++;
            }
            if(sum > max) max = sum;
        }
    }
    print(max);
}

//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], m = _a[1];
    var a = Array(n);
    for (var i = 0; i < n; i++) {
        a[i] = readline().split(' ').map(function (v) { return +v; });
    }
    var l = Array(n + m).fill(0, -m, n);
    var r = Array(n + m).fill(0, -m, n);
    for (var i = -m + 1; i < n; i++) {
        l[i] = 0;
        for (var j = Math.max(0, -i); j < Math.min(m, n - i); j++) {
            l[i] += a[i + j][j];
        }
        r[i] = 0;
        for (var j = Math.max(0, -i); j < Math.min(m, n - i); j++) {
            r[i] += a[i + j][m - j - 1];
        }
    }
    var max = 0;
    for (var i = 0; i < n; i++) {
        for (var j = 0; j < m; j++) {
            max = Math.max(max, l[i - j] + r[i - m + j + 1] - a[i][j]);
        }
    }
    print(max);
}

const { createInterface } = require('readline');
const { createWriteStream, createReadStream } = require('fs');
const { format } = require('util');

function calcDiags(t, n, m, init) {
  const { i, j } = init

  //from top left to bottom right
  let sum1 = 0
  let j1 = (j > i) ? j - i : 0
  let i1 = (j > i) ? 0 : i - j
  //console.log({ j1, i1 })

  for (let i = i1, j = j1; i < n && j < m; i++, j++) {
    sum1 += t[i][j]
  }

  //from top right to bottom left
  let sum2 = 0
  let diff_j_m = (m - 1) - j
  let diff_i_0 = i - 0
  let min_diff = Math.min(diff_j_m, diff_i_0)

  let j2 = j + min_diff
  let i2 = i - min_diff
  //console.log({ j2, i2 })

  for (let i = i2, j = j2; i < n && j >= 0; i++, j--) {
    sum2 += t[i][j]
  }

  //all

  const sum = sum1 + sum2 - t[i][j]
  //console.log({ sum1, sum2, sum })
  return sum
}

function getMax(t, n, m) {
  let max = 0
  // console.log({ n, m })
  //console.log("\n")
  //console.log(getTable(t))

  for (let i = 0; i < n; i++) {
    for (let j = 0; j < m; j++) {
      const calc = calcDiags(t, n, m, { i, j })
      if (max < calc) {
        max = calc
      }
    }
  }
  return max

}

const max = Number.MAX_SAFE_INTEGER

function main() {
  const readline = createInterface({
    input: process.stdin,
    output: process.stdout
  });
  let lineNb = 0;
  let subLine = 0;
  let n;
  let isCollecting = true;
  let subN;
  let subM;
  let t = [];
  readline.on('line', line => {
    if (!lineNb) {
      lineNb = 1;
      n = parseInt(line);
    }
    else {
      const data = line.split(" ").map(function (item) {
        return parseInt(item, 10);
      })
      if (data.length == 2 && isCollecting) {
        isCollecting = false
        n--
        subLine = 0;
        t = []
        subN = data[0]
        subM = data[1]
      } else {
        subLine++;
        t.push(data)
        if (subLine == subN) {
          console.log(getMax(t, subN, subM))
          isCollecting = true
          if (!n) {
            readline.close()
          }
        }
      }
    }

  });

}

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;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var d = [[-1,-1],[-1,1],[1,-1],[1,1]];
	while(hasNext()){
		var H = nextInt();
		var W = nextInt();
		var list = new Array(H);
		for(var i = 0; i < H; i++){
			list[i] = nextIntArray(W);
		}
		var output = 0;
		for(var i = 0; i < H; i++){
			for(var j = 0; j < W; j++){
				var sum = list[i][j];
				for(var k = 0; k < d.length; k++){
					var nxY = i + d[k][0];
					var nxX = j + d[k][1];
					while(nxY >= 0 && nxY < H && nxX >= 0 && nxX < W){
						sum += list[nxY][nxX];
						nxY += d[k][0];
						nxX += d[k][1];
					}
				}
				output = Math.max(output, sum);
			}
		}
		myout(output);
	}
}

const left = (mat, fill, i, j, m, n) => {
  if ((i!=0)&&(fill[i - 1][j - 1])) return (fill[i][j] = fill[i - 1][j - 1]);
  let sum = 0,k=i,l=j;
  while (i < m && j < n) {
    sum += mat[i][j];
    i++;
    j++;
  }
  fill[k][l] = sum;
};
const right = (mat, fill, i, j, m, n) => {
  if ((i!=0)&&(fill[i - 1][j + 1])) return (fill[i][j] = fill[i - 1][j + 1]);
  let sum = 0,k=i,l=j;
  while (i < m && j >= 0) {
    sum += mat[i][j];
    i++;
    j--;
  }
  fill[k][l] = sum;
};

const solve = (m, n, mat) => {
  let lfill = Array.from({ length: m }, () =>
    Array.from({ length: n }, () => 0)
  );
  let rfill = Array.from({ length: m }, () =>
    Array.from({ length: n }, () => 0)
  );
  let max = -Infinity;
  for (let i = 0; i < m; i++) {
    for (let j = 0; j < n; j++) {
      left(mat, lfill, i, j, m, n);
      right(mat, rfill, i, j, m, n);
       max = Math.max(lfill[i][j] + rfill[i][j] - mat[i][j], max);
    }
  }
  return max;
};
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 [m,n] = readline().trim().split(" ").map(cur=>parseInt(cur));
    let mat = [];
    for(let i=0;i<m;i++){
      mat.push(readline().trim().split(" ").map(cur=>parseInt(cur)));
    }
    console.log(solve(m,n,mat));
  }
}
main();

'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) {
  let res = 0;
  const dirs = [[-1, -1], [1, 1], [-1, 1], [1, -1]];
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < m; j++) {
      let cur = a[i][j];
      for (let [di, dj] of dirs) {
        let x = i + di,
            y = j + dj;
        while (x >= 0 && x < n && y >= 0 && y < m) {
          cur += a[x][y];
          x += di;
          y += dj;
        }
      }
      res = Math.max(res, cur);
    }
  }
  return res.toString();
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const [n, m] = (await read()).split(' ').map(Number);
    const a = [];
    let tmp = n;
    while (tmp--) {
      a.push((await read()).split(' ').map(Number));
    }
    res.push(solve(n, m, a));
  }
  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);
}();

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    const [n, m] = readLine().split(" ").map(i => parseInt(i));
    let arr = [];
    for (let i = 0; i < n; i++) arr.push(readLine().split(" ").map(j => parseInt(j)));
    return findDiag(arr);
}
function findDiag(arr) {
    let max = 0;
    for (let i = 0; i < arr.length; i++) {
        for (let x = 0; x < arr[i].length; x++) {
            let temp = arr[i][x];
            //t-l
            let j = i - 1;
            let k = x - 1;
            while (j >= 0 && k >= 0) {
                temp += arr[j--][k--];
            }
            //t-r
            j = i - 1;
            k = x + 1;
            while (j >= 0 && k < arr[i].length) {
                temp += arr[j--][k++];
            }
            //b-l
            j = i + 1;
            k = x + 1;
            while (j < arr.length && k < arr[i].length) {
                temp += arr[j++][k++];
            }
            //b-r
            j = i + 1;
            k = x - 1;
            while (j < arr.length && k >= 0) {
                temp += arr[j++][k--];
            }
            max = Math.max(max, temp);
        }
    }
    return max;
}

'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++];
}

const dy = [-1, 1, -1, 1];
const dx = [-1, 1, 1, -1];

function main() {
  let tc = parseInt(input());
  while(tc--){
    const [n, m] = input().split(' ').map(Number);
    const a = Array.from(Array(n), () => Array(m));
    for(let i = 0; i < n; i++){
      const tmp = input().split(' ').map(Number);
      for(let j = 0; j < m; j++){
        a[i][j] = tmp[j];
      }
    }
    let ans = 0;
    for(let y = 0; y < n; y++){
      for(let x = 0; x < m; x++){
        ans = Math.max(ans, solve(n, m, a, y, x));
      }
    }
    console.log(ans);
  }
}

const solve = (n, m, a, sy, sx) => {
  let ret = a[sy][sx];
  for(let i = 0; i < 4; i++){
    let y = sy;
    let x = sx;
    while(true){
      y += dy[i];
      x += dx[i];
      if(y < 0 || y >= n || x < 0 || x >= m) break;
      ret += a[y][x];
    }
  }
  return ret;
}

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, m] = readline().split(' ').map((x)=>parseInt(x));
  var a = []
  for(var i=0;i<n;i++) {
    var s = readline().split(' ').map((x)=>parseInt(x));
    a.push(s);
  }
  var tar = -1;
  for(var i=0;i<n;i++) {
    for(var j=0;j<m;j++) {
      var ans = 0;
      var x = i+1, y = j+1;
      while(x<n && y<m) {
        ans += a[x][y];
        x++;
        y++;
      }
      x = i+1;
      y = j-1;
      while(x<n && y>=0) {
        ans += a[x][y];
        x++;
        y--;
      }
      x = i-1;
      y = j+1;

      while(x>=0 && y<m) {
        ans += a[x][y];
        x--;
        y++;
      }
      x = i-1;
      y = j-1;

      while(x>=0 && y>=0) {
        ans += a[x][y];
        x--;
        y--;
      }
      ans += a[i][j]
      tar = max(tar, ans);

    }
  }
  console.log(tar);
  //fs.appendFileSync('output.txt', tar+'\r\n');

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

//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 rows = nextInt();
    const columns = nextInt();
    const matrix = new Array(rows);
    for (let i = 0; i < rows; i++) {
        matrix[i] =  nextIntArray(columns)
    }
    let max = 0;
    for (let row = 0; row < rows; row++) {
        for (let col = 0; col < columns; col++) {
            let sum = 0;
            // top left
            for (let rowPlace = row, colPlace = col; rowPlace >= 0 && colPlace >= 0; rowPlace--, colPlace--) {
                sum+= matrix[rowPlace][colPlace];
            }
            // top right
            for (let rowPlace = row, colPlace = col; rowPlace >= 0 && colPlace < columns; rowPlace--, colPlace++) {
                sum+= matrix[rowPlace][colPlace];
            }
            // down left
            for (let rowPlace = row, colPlace = col; rowPlace < rows && colPlace >= 0; rowPlace++, colPlace--) {
                sum+= matrix[rowPlace][colPlace];
            }
            // down right
            for (let rowPlace = row, colPlace = col; rowPlace < rows && colPlace < columns; rowPlace++, colPlace++) {
                sum+= matrix[rowPlace][colPlace];
            }
            sum -= 3* matrix[row][col]

            max = Math.max(max, sum);
        }
    }

    myout(max);
    // for (let i )
}

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, m] = lines[l++].trim().split(' ').map(Number)
        const grid = lines.slice(l, l + n).map(str => str.trim().split(' ').map(Number))
        l += n
        output[i] = solve(n, m, grid)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m, grid) {
    const d1 = {}
    const d2 = {}
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            const x = grid[i][j]
            d1[i + j] = (d1[i + j] || 0) + x
            d2[i - j] = (d2[i - j] || 0) + x
        }
    }
    let ans = -Infinity
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            ans = Math.max(ans, d1[i + j] + d2[i - j] - grid[i][j])
        }
    }
    return ans
}

//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();
	var d = [[-1,-1],[-1,1],[1,-1],[1,1]];
	while(hasNext()){
		var H = nextInt();
		var W = nextInt();
		var list = new Array(H);
		for(var i = 0; i < H; i++){
			list[i] = nextIntArray(W);
		}
		var output = 0;
		for(var i = 0; i < H; i++){
			for(var j = 0; j < W; j++){
				var sum = list[i][j];
				for(var k = 0; k < d.length; k++){
					var nxY = i + d[k][0];
					var nxX = i + d[k][1];
					while(nxY >= 0 && nxY < H && nxX >= 0 && nxX < W){
						sum += list[nxY][nxX];
						nxY += d[k][0];
						nxX += d[k][1];
					}
				}
				output = Math.max(output, sum);
			}
		}
		myout(output);
	}
}


var n = +readline(), input;
var cnt = {}, x;

for(i = 1; i <= n; i++){
	cnt[i] = 0;
}

for(i = 1, x = n-1; i <= n; i++){
	input = readline().split(" ");

	for(j = i; j <= x; j++){
		switch(input[j]){
			case "0":
				break;
			case "1":
				delete cnt[i];
				break;
			case "2":
				delete cnt[j+1];
				break;
			case "3":
				delete cnt[i];
				delete cnt[j+1];
		}
	}
}

print(Object.keys(cnt).length);
if(Object.keys(cnt).length > 0){
	for(key in cnt){
		write(key + " ");
	}
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;
const ans = [];
let count = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    return;
  }

  if (!/[13]/g.test(d.replace('-1', ''))) {
    count++;
    ans.push(c);
  }

  c++;
});

rl.on('close', () => {
  console.log(count);

  if(ans.length) {
    console.log(ans.join(' '));
  }
});

process.stdin.setEncoding('ASCII');

let string = '';
process.stdin.on( 'data', (data) => string += data );

process.stdin.on('end', () => {
    const array = string.split("\n");
    let n = Number(array[0]);

    let flipped = Array(110).fill(0);

    for (let i = 1; i <= n; ++i) {
        const row = array[i].split(" ").map(Number);

        for (let j = 0; j < n; ++j) {
            if (row[j] == 0 || row[j] == -1) continue;
            if (row[j] == 1)  flipped[i]++;
            else if (row[j] == 2) flipped[j + 1]++;
            else if (row[j] == 3) flipped[i]++, flipped[j + 1 ]++;
        }
    }

    let cnt = 0, result = '';
    for (let i = 1; i <= n; ++i) if (flipped[i] == 0) cnt++, result += i + ' ';
    console.log(cnt);
    console.log(result);
});

function Reader()
{
    this.buffer = [];
    this.cur = 0;
}

Reader.prototype.next = function()
{
    if (this.cur == this.buffer.length)
    {
        this.cur = 0;
        this.buffer = readline().split(' ');
    }
    return this.buffer[this.cur++];
}

function Writer()
{
    this.buffer = "";
}

Writer.prototype.print = function(s)
{
    this.buffer += s;
}

Writer.prototype.println = function(s)
{
    this.buffer += s;
    print(this.buffer);
    this.buffer = "";
}

Writer.prototype.flush = function()
{
    if (this.buffer != "")
    print(this.buffer);
    this.buffer = "";
}

var cin = new Reader();
var cout = new Writer();

var n = +cin.next();

var ans = [];

for(var i = 0; i < n; ++i)
{
    var good = 1;
    var cur;
    for(var j = 0; j < n; ++j)
    {
        cur = +cin.next();
        if (cur == 1 || cur == 3)
            good = 0;
    }
    if (good)
        ans.push(i + 1);
}

cout.println(ans.length);

for(var i = 0; i < ans.length; ++i)
{
    cout.print(ans[i] + " ");
}

cout.flush();

function ProblemSolver() {
    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;
    this.CLEAR_ARRAY_PER_CASE = false;

    this.solveCase = function() {
        var res , i , j , fl , cn , temp ;
        res = [] ;
        for( i = 0 ; i < this.n ; i++ ) {
        	fl = 1 ;
        	for( j = 0 ; j < this.n ; j++ ) {
        		if( i != j && ( this.memo[ i ][ j ] == 1 || this.memo[ i ][ j ] == 3 ) ) {
        			fl = 0 ;
        			break ;
        		}
        	}
        	if( fl == 1 ) {
        		res.push( i + 1 ) ;
        	}
        }
        print( res.length );
        print( res.join( ' ' ) );
    };

    this.init = function() {
        this.lim1 = 100010;
        this.lim2 = 110;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
            this.n = irObj.nextInt();
            for( i = 0 ; i < this.n ; i++ ) {
            	for( j = 0 ; j < this.n ; j++ ) {
                	this.memo[ i ][ j ] = irObj.nextInt();
               	}
            }
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i;
        this.arr = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 );
            this.adj_list.push( new Array() );
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        if( this.CLEAR_ARRAY_PER_CASE == true ) {
            this.clearArraysPerCase() ;
        }
    };

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adj_list = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adj_list.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init();
}

function InputReader() {
    var self = this ;
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;
    this.callBackFunction = null ;
    this.parentContext = null ;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    };

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    };

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    };

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        this.allLines = [] ;
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            res = "";
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );
                }
            }
            this.currrentCharacterIndex = endIdx;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        return this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCases = function() {
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {
                    environmentType = 'local-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    };

    this.configureStreamsAndReadInput = function() {
        var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino();
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
    };

    this.configureStreamsAndReadInput();
}

new CodeExecutioner();

function toi(x){return parseInt(x);}
var n=toi(readline());
var res=[];
var num=0;
for(var i=0;i<n;i++){
    var a=readline().split(" ").map(toi);
    if(a.every(function(x){return x!=1&&x!=3;})){
	res.push((i+1));
	num++;
    }
}
print(num==0?num:""+num+"\n"+res.join(" "));

var n = parseInt( readline() ),
	index = [];
for (var i=0; i<n; i++) {
	readline().split( ' ' ).every( function(el) {
		return el != 1 && el != 3;
	} ) && index.push( i+1 );
}

print( index.length );
index.length && print( index.join( ' ' ) );

// 545A     Игрушечные машинки

var n = parseInt(readline());

// var input_line = readline().split(' ').map(Number);

var arr = [];
var arrTmp = [];

for (var i = 0; i < n; i++) {
    arr[i] = [];
    arr[i] = readline().split(' ').map(Number);
};

Array.prototype.in_array = function(p_val) {
    for(var i = 0, l = this.length; i < l; i++)  {
        if(this[i] == p_val) {
            return true;
        }
    }
    return false;
}

var arrTest = [1, 3];
var flagGood;
var count = n;
var out = '';

for (var i = 0; i < n; i++) {

    flagGood = true;

    for (var j = 0; j < n; j++) {
        if (arrTest.in_array(arr[i][j])) {
            flagGood = false;
        };
    };

    if (!flagGood) {
        count --;
    } else {
        out += (i + 1) + ' ';
    }
};

out = count + '\n' + out + '\n';

print(out);

var n = parseInt( readline() ),
	index = [];
for (var i=0; i<n; i++) {
	readline().split( ' ' ).every( function(el) {
		return el != 1 && el != 3;
	} ) && index.push( i );
}

print( index.length );
print( index.join( ' ' ) );


var T = parseInt(readline());

var n, d, result, y;

for (var i = 0; i < T; i++) {

  y = readline().split(" ").map(x => parseInt(x));

  n = y[0];
  d = y[1];

  if (n >= d) {
    print("YES");
    continue;
  }

  var pass = false;

  for (var x = 1; x <= n; x++) {
    result = Math.ceil(d/(x+1)) + x;

    if (result <= n) {
        print("YES");
        pass = true;
        break;
    }
  }

  if (!pass) print('NO');
}

let input = ''
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
  const { EOL } = require('os');
  const lines = input.split(EOL);
  main(lines);
});

function main(lines) {
  lines.pop();
  lines.shift();
  const tests = lines
    .map(t => t.split(' ').map(v => +v));
  for (const [n, d] of tests) {
    solve(n, d);
  }
}

function solve(n, d) {
  for (let x = 0; x <= n; x++) {
    const f = x + Math.ceil(d / (x + 1));
    if (f <= n) {
      console.log("YES");
      return;
    }
  }
  console.log("NO");
}

// main(["3", "1 1", "4 5", "5 11"])

var t = readline();
var a = [];
var i = 0;
while (i < t) {
    a = readline().split(" ").map((a) => parseInt(a));
    var ans = 0;
    for (var j = 0; j < a[0]; j++) {
        ans = j + Math.ceil(a[1]/(j+1))
        if (ans <= a[0]) {
            print('YES');
            break;
        }
    }
    if (ans > a[0]) print("NO");
    i++;
}

var t = parseInt(readline(), 10),
    n = [],
    time = 0,
    mid1 = 0,
    mid2 = 0;

for(var i=1; i<=t; i++) {
    n = readline().split(' ').map(el => parseInt(el, 10));

    if(n[0] >= n[1]) print('YES');
    else {
        mid1 = Math.ceil(n[0]/2);
        mid2 = Math.floor(n[0]/2);
        time = (mid1 + Math.ceil(n[1]/(mid1+1))) < (mid2 + Math.ceil(n[1]/(mid2+1))) ? mid1 + Math.ceil(n[1]/(mid1+1)) : mid2 + Math.ceil(n[1]/(mid2+1));
        print(time <= n[0] ? 'YES' : 'NO');
    }
}

var inputString = '';
var currentLine = 0;

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

process.stdin.on('end', function() {
    inputString = inputString.split('\n');
    main();
});

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

function main() {
    const t = Number(readLine());
    for (var i = 0; i < t; i++){
        const [n, d] = readLine().split(' ').map(Number);
        let mn = 1000000009;
        for (var x = 0; x <= Math.min(d, 40000); x++){
            mn = Math.min(mn, (x + Math.ceil(d/(x+1))));
        }
        console.log(mn <= n ? "YES": "NO");
    }
}

// Q: https://codeforces.com/contest/1288/problem/A

const readline = require('readline');

let input = [];

const rl = readline.createInterface({
	input: process.stdin,
	output: process.stdout,
});

rl.on('line', lineInput => {
	input.push(lineInput);
});

rl.on('close', () => {
	const test = parseInt(input[0]);
	for (let t=0; t < test; t++) {
		let inputData = input[t+1].split(' ').map((a) => {return parseInt(a)});
		console.log(solution(inputData[0], inputData[1]));
	}
});

function solution(n, d) {
	for (let j = 0; j < n; j++) {
		if (j + Math.ceil(d/(j+1)) <= n) {
			return 'YES';
		}
	}
	return 'NO';
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const t = readInt(arr)

  for(let i = 0; i < t; i++) {
    const [n, d] = readInts(arr, i)

    let x = Math.sqrt(d)
    let x1 = Math.floor(x)
    let x2 = x1 - 1
    let x3 = x2 - 1
    // wr(x1, x2)
    if(d <= n || (x1 + Math.ceil(d / (x1 + 1)) <= n) || (x2 + Math.ceil(d / (x2 + 1)) <= n) || (x3 + Math.ceil(d / (x3 + 1)) <= n)) wr('YES')
    else wr('NO')
  }
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}
function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

'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++];
}

function main() {
    var T = Number(readline());
    var n, d, j;
    for (let i = 0; i < T; i++) {
        var line = readline().split(' ');
        n = parseInt(line[0]);
        d = parseInt(line[1]);
        for (j = 0; j < n; j++)
            if (j + Math.ceil(d / (j + 1)) <= n) {
                console.log("YES");
                break;
            }
        if (j === n)
            console.log("NO");
    }
    return 0;
}

const calc = (d, x) => Math.ceil( d / (x + 1) + x)

const processData = (lines) => {
  const num = +lines[0]

  for (let j=1; j<=num; j++){
    const [n, d] = lines[j].split(' ').map(x => +x)
    const extremum = Math.round(Math.sqrt(d) - 1)
    const minPoint = calc(d, extremum)
    if (minPoint <=  n && extremum <= n) {
      console.log('YES')
    } else {
      console.log('NO')
    }
  }
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
  const {EOL} = require('os')
  const lines = i.split(EOL) /*your input text, split by lines*/
  processData(lines)
})

var T = parseInt(readline());

print(T);

var n, d, result, y;

for (var i = 0; i < T; i++) {

  y = readline().split(" ").map(x => parseInt(x));

  n = y[0];
  d = y[1];

  if (n >= d) {
    print("YES");
    continue;
  }

  result = Math.ceil(d / 2);

  if (result <= n) {
    print("YES");
  } else {
    print("NO");
  }
}

var T = parseInt(readline());

print(T);

var n, d, result, y;

for (var i = 0; i < T; i++) {

  y = readline().split(" ").map(x => parseInt(x));

  n = y[0];
  d = y[1];

  if (n >= d) {
    print("YES");
    continue;
  }

  result = Math.ceil(d / 2) + 1;

  if (result <= n) {
    print("YES");
  } else {
    print("NO");
  }
}

var T = parseInt(readline());

var n, d, result, y;

for (var i = 0; i < T; i++) {

  y = readline().split(" ").map(x => parseInt(x));

  n = y[0];
  d = y[1];

  if (n >= d) {
    print("YES");
    continue;
  }

  result = Math.ceil(d / 2);

  if (result <= n) {
    print("YES");
  } else {
    print("NO");
  }
}

var T = parseInt(readline());

var n, d, result, y;

for (var i = 0; i < T; i++) {

  y = readline().split(" ").map(x => parseInt(x));

  n = y[0];
  d = y[1];

  if (n >= d) {
    print("YES");
    continue;
  }

  var pass = false;

  for (var x = 1; x <= n; x++) {
    result = Math.ceil(d/(x+1));

    if (result <= n) {
        print("YES");
        pass = true;
        break;
    }
  }
  if (!pass) print('NO');
}

var T = parseInt(readline());

var n, d, result, y;

for (var i = 0; i < T; i++) {

  y = readline().split(" ").map(x => parseInt(x));

  n = y[0];
  d = y[1];

  if (n >= d) {
    print("YES");
    continue;
  }

  result = Math.ceil(d / 2) + 1;

  if (result <= n) {
    print("YES");
  } else {
    print("NO");
  }
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const t = readInt(arr)

  for(let i = 0; i < t; i++) {
    const [n, d] = readInts(arr, i)

    let x = Math.sqrt(d)
    let x1 = Math.ceil(x)
    let x2 = Math.floor(x)
    if(d <= n || (x1 + Math.ceil(d / (x1 + 1)) <= n) || (x2 + Math.ceil(d / (x2 + 1)) <= n)) wr('YES')
    else wr('NO')
  }
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}
function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

let input = ''
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    const { EOL } = require('os');
    const lines = input.split(EOL);
    main(lines);
});

function main(lines) {
  const tests = lines.slice(1).map(t => t.split(' ').map(v => +v));
  for (const [n, d] of tests) {
    solve(n, d);
  }
}

function solve(n, d) {
  for (let x = 0; x <= n; x++) {
    const f = x + Math.ceil(d / (x + 1));
    if (f <= n) {
      console.log("YES");
      return;
    }
  }
  console.log("NO");
}

// main(["3", "1 1", "4 5", "5 11"])

let input = ''
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    const { EOL } = require('os');
    const lines = input.split(EOL);
    lines.forEach((l) => console.log(l + '\\\\'));
    main(lines);
});

function main(lines) {
  const tests = lines.slice(1).map(t => t.split(' ').map(v => +v));
  for (const [n, d] of tests) {
    solve(n, d);
  }
}

function solve(n, d) {
  for (let x = 0; x <= n; x++) {
    const f = x + Math.ceil(d / (x + 1));
    if (f <= n) {
      console.log("YES");
      return;
    }
  }
  console.log("NO");
}

// main(["3", "1 1", "4 5", "5 11"])

let input = ''
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    const { EOL } = require('os');
    const lines = input.split(EOL);
    main(lines);
});

function main(lines) {
  const n = +lines[0];
  const tests = lines.slice(1).map(t => t.split(' ').map(v => +v));
  for (const [n, d] of tests) {
    solve(n, d);
  }
}

function solve(n, d) {
  for (let x = 0; x <= n; x++) {
    const f = x + Math.ceil(d / (x + 1));
    if (f <= n) {
      console.log("YES");
      return;
    }
  }
  console.log("NO");
}

// main(["3", "1 1", "4 5", "5 11"])

var t = readline();
var a = [];
var i = 0;
var x;
var d;
while (i < t) {
  a = readline()
    .split(" ")
    .map((a) => parseInt(a));
    // print("math",Math.ceil(a[1]/a[0]))

  x = Math.ceil(a[1] / a[0]) - 1;
  d=x+1
//   print("d",d)
  if (x+Math.ceil(a[1]/d)<=a[0])
  print("YES");
  else print("NO");
//   print("nf",x+Math.ceil(a[1]/d))
//   print("n",a[0])
//   print("d",a[1])
  i++;
}

var t = readline();
var a = [];
var i = 0;
var x;
var d;
while (i < t) {
  a = readline()
    .split(" ")
    .map((a) => parseInt(a));
    print("math",Math.ceil(a[1]/a[0]))

  x = Math.ceil(a[1] / a[0]) - 1;
  d=x+1
//   print("d",d)
  if (x+Math.ceil(a[1]/d)<=a[0])
  print("YES");
  else print("NO");
//   print("nf",x+Math.ceil(a[1]/d))
//   print("n",a[0])
//   print("d",a[1])
  i++;
}

var t = readline();
var a = [];
var i = 0;
var x;
var d;
while (i < t) {
  a = readline()
    .split(" ")
    .map((a) => parseInt(a));
    // print("math",Math.ceil(a[1]/a[0]))

  x = Math.ceil(a[1] / a[0]) - 1;
  d=x+1
//   print("d",d)
  if (x+a[0]<=a[0])
  print("YES");
  else print("NO");
//   print("nf",x+Math.ceil(a[1]/d))
//   print("n",a[0])
//   print("d",a[1])
  i++;
}


var potential_victims = readline().split(' ');
var n = parseInt(readline());
var tmp_answer = [];

tmp_answer.push(potential_victims.join(' ')); // push initial potential victims

for(var i = 0; i < n; i++) {

    var substitute = readline().split(' ');
    var dead_index = potential_victims.indexOf(substitute[0]);

    potential_victims[dead_index] = substitute[1];
    tmp_answer.push(potential_victims.join(' '));
}

print(tmp_answer.join('\n'));

var h = readline().split(' ');
var n = parseInt(readline());
var story = [];

story.push(h.join(' '));

for(var i = 0; i < n; i++){
   var v = readline().split(' ');
   var ind = h.indexOf(v[0]);
   h[ind] = v[1];
   story.push(h.join(' '));
}

print(story.join('\n'));

var input = readline().split(" ");
var n = parseInt(readline());

print(input[0] + ' ' + input[1]);

for (var i = 0; i < n; i++) {

	var next = readline().split(" ");

	var j = next.indexOf(input[0]) === -1 ? 1 : 0;
	var k = next.indexOf(input[j]);

	print(input[(j + 1) % 2] + ' ' + next[(k + 1) % 2]);
	input[j] = next[(k + 1) % 2];
}

/**
 *
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day.
 Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.

The killer starts with two potential victims on his first day, selects one of these two,
kills selected victim and replaces him with a new person. He repeats this procedure each day.
This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims.
Also, he knows the murder that happened on a particular day and the new person who replaced this victim.

You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.

Input
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims.
Next line contains integer n (1 ≤ n ≤ 1000), the number of days.

Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day
and the second being the one who replaced that person.

The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time.
Also, all the names are guaranteed to be distinct and consists of lowercase English letters.

Output
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder.
The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line,
the two names can be printed in any order.

input
ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler

output
ross rachel
joey rachel
joey phoebe
joey monica
joey chandler

input
icm codeforces
1
codeforces technex

output
icm codeforces
icm technex

 */

let inputString = '';

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

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

    let initialVictims = inputString[0]
    let numberOfDays = Number(inputString[1]);
    let victims = inputString.slice(2)

    solution(initialVictims, numberOfDays, victims);

});

function solution(initialVictims, numberOfDays, victims) {

    let initialVictimOne = initialVictims.split(" ")[0]
    let initialVictimTwo = initialVictims.split(" ")[1]
    let solutionArray = [];
    //console.log(initialVictimOne , initialVictimTwo);
    solutionArray.push(initialVictimOne);
    solutionArray.push(" ");
    solutionArray.push(initialVictimTwo);
    solutionArray.push("\n");

    for (let index = 0; index < numberOfDays; index++) {

        let element = victims[index];
        let vicitimOne = element.split(" ")[0];
        let vicitimTwo = element.split(" ")[1];

        if (vicitimOne == initialVictimOne) {
            solutionArray.push(initialVictimTwo);
            solutionArray.push(" ");
            initialVictimOne = initialVictimTwo;
            initialVictimTwo = vicitimTwo;

        }

        if (vicitimOne == initialVictimTwo) {
            solutionArray.push(initialVictimOne);
            solutionArray.push(" ");
            initialVictimTwo = initialVictimOne;
            initialVictimOne = vicitimTwo;
        }

        solutionArray.push(vicitimTwo);
        solutionArray.push("\n");
    }

    console.log(solutionArray.join(""));

}


const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
let x =0
let y= 0
let n =0
rl.on('line', (input) => {
    if (l === 0) {
        let arr = input.split(" ").map(x=>parseInt(x))
        x = arr[1]
        y = arr[2]
    } else {
        rl.close();
        let arr = input.split(" ").map(p=>parseInt(p))
        if(x>y){
          console.log(arr.length)
           return
        }
        let c=0
        for(let i=0;i<arr.length;i++){
        if(arr[i]<=x){
            c++;
        }
        }
        console.log(Math.ceil(c/2)+"")
        return
    }
    l++
})

function main(r) {
    var n = r().split(' ');
    var x = +n[1], y = +n[2];
    n = +n[0];

    var a =r().split(' ');

    if(x > y) {
        print(a.length);
        return;
    }
    var c = a.filter(function(i){
        return x >= +i
    }).length;

    print(Math.ceil(c / 2));

}

main(readline);

function calc(n, x, y, a) {
  if (x <= y) {
    return Math.ceil(a.filter(elem => elem <= x).length / 2);
  }

  if (x > y) {
    return n;
  }
}

var nxy = readline().split(" ");
var n = parseInt(nxy[0]);
var x = parseInt(nxy[1]);
var y = parseInt(nxy[2]);

var a = readline().split(" ").map(elem => parseInt(elem));

print(calc(n, x, y, a));

var nxy = readline().split(' ').map(a => +a);
n = nxy[0];
x = nxy[1];
y = nxy[2];

var a = readline().split(' ').map(a => +a);

if (x > y)
	print (n);
else {
	var kol = 0;
	a.forEach(function(number){
		if (number <= x) kol++;
	});

	print (Math.ceil(kol/2));
}

var tmp = readline().split(' ').map(Number);
var n = tmp[0];
var x = tmp[1];
var y = tmp[2];

var arr = readline().split(' ').map(Number);

var cnt = 0;

arr.forEach( i => {
    if( i <= x ) {
        cnt++;
    }
});
if( x <= y ) {
    print(Math.ceil(cnt/2));

} else print( n );

function main(r) {
    var n = r().split(' ');
    var x = n[1], y = n[2];
    n = n[0];

    var a =r().split(' ');

    if(x > y) {
        print(a.length);
        return;
    }

    var c = a.filter(function(i){
        return i < x;
    }).length;

    print(Math.ceil(c / 2));
}

main(readline)

function main(r) {
    var n = r().split(' ');
    var x = +n[1], y = +n[2];
    n = +n[0];

    var a =r().split(' ');

    if(x > y) {
        print(a.length);
        return;
    }

    var c = a.filter(function(i){
        return +i < x;
    }).length;

    print(Math.ceil(c / 2));
}

main(readline);

function main(r) {
    var n = r().split(' ');
    var x = n[1], y = n[2];
    n = n[0];

    var a =r().split(' ');

    if(x > y) {
        print(a.length);
        return;
    }

    var c = a.filter(function(i){
        return i <= x;
    }).length;

    print(Math.ceil(c / 2));
}

main(readline)

function calc(n, x, y, a) {
  if (x <= y) {
    return Math.ceil(a.filter(elem => elem <= x).length / 2);
  }

  if (x > y) {
    return n;
  }
}

var nxy = readline().split(" ");
var n = nxy[0];
var x = nxy[1];
var y = nxy[2];

var a = readline().split(" ");

print(calc(n, x, y, a));

function calc(n, x, y, a) {
  if (x <= y) {
    return Math.ceil(a.filter(elem => elem <= x).length / 2);
  }

  if (x > y) {
    return n;
  }
}

var nxy = readline().split(" ");
var n = nxy[0];
var x = nxy[1];
var y = nxy[2];

var a = readline().split(" ").map(elem => parseInt(elem));

print(calc(n, x, y, a));

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
let x =0
let y= 0
let n =0
rl.on('line', (input) => {
    if (l === 0) {
        let arr = input.split(" ").map(x=>parseInt(x))
        x = arr[1]
        y = arr[2]
    } else {
        rl.close();
        let arr = input.split(" ").map(p=>parseInt(p))
        if(x>y){
           return
        }
        let c=0
        for(let i=0;i<arr.length;i++){
        if(arr[i]<=x){
            c++;
        }
        }
        console.log(Math.ceil(c/2))
    }
    l++
})

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

let l = 0;
let x =0
let y= 0
let n =0
rl.on('line', (input) => {
    if (l === 0) {
        let arr = input.split(" ").map(x=>parseInt(x))
        x = arr[1]
        y = arr[2]
    } else {
        rl.close();
        let arr = input.split(" ").map(p=>parseInt(p))
        if(x>y){
           return
        }
        let c=0
        for(let i=0;i<arr.length;i++){
        if(arr[i]<=x){
            c++;
        }
        }
        console.log(Math.ceil(c/2)+"")
    }
    l++
})


(function main() {
    var l = readline();
    if (l.match(/9\./)) {
        print('GOTO Vasilisa.');
    } else {
        l = l.replace(/([0-8])\.([0-9]).*$/,
                function(str, p1, p2, offset, s) {
                    if (p2.match(/[0-4]/))
                        return p1;
                    else
                        return String.fromCharCode(p1.charCodeAt(0) + 1);
                });
        print(l);
    }
})();

var inpStr = readline();

var i=0, l = inpStr.length, n = 0, flag = 0, outStr="";

for(i=0; i<l; i++)
{
  if(inpStr[i] == "." && flag == 0)
  {
    n = i;

    if(inpStr[i-1]=="9")
    {
      flag = 3; // GoTo
    }
    else if(inpStr[i+1]<"5")
    {
      flag = 2; // down
    }
    else
    {
      flag = 1; // up
    }
  }
}

if(flag == 3)
{
  outStr = "GOTO Vasilisa.";
}

if(flag == 2)
{
  outStr = inpStr.slice(0,n);
}

if(flag == 1)
{
  var s = inpStr[n-1], sn = s.charCodeAt(0), ss = String.fromCharCode(sn+1);

  outStr = inpStr.slice(0,n-1);
  outStr = outStr + ss;
}

print(outStr);

var input = readline().split('.'), main = input[0], rest = input[1];
if (main[main.length-1] == '9') write('GOTO Vasilisa.');
else if (rest[0] < 5) write(main);
else if (rest[0] >= 5) {
    var mainArr = main.split('');
    mainArr[main.length - 1] = parseInt(mainArr[main.length - 1]) + 1;
    write(mainArr.join(''));
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

rl.on('line', (str) => {
  const dotIdx = str.indexOf('.');

  if (str[dotIdx - 1] === '9') {
    console.log('GOTO Vasilisa.');
  }
  else if (+str[dotIdx + 1] < 5) {
    console.log(str.split('.')[0]);
  }
  else {
    const [a, b] = str.split('.');

    console.log((BigInt(a) + 1n).toString());
  }
});

var inpStr = readline();

var i=0, l = inpStr.length, n = 0, flag = 0, outStr="";

for(i=0; i<l; i++)
{
  if(inpStr[i] == "." && flag == 0)
  {
    n = i;

    if(inpStr[i-1]=="9")
    {
      flag = 3; // GoTo
    }
    else if(inpStr[i+1]<"5")
    {
      flag = 2; // down
    }
    else
    {
      flag = 1; // up
    }
  }
}

if(flag == 3)
{
  outStr = "GOTO Vasilisa.";
}

if(flag == 2)
{
  outStr = inpStr.slice(0,n);
}

if(flag == 1)
{
  outStr = inpStr.slice(0,n);
  outStr = outStr + (inpStr[n+1]+1);
}

print(outStr);

var inpStr = readline();

var i=0, l = inpStr.length, n = 0, flag = 0, outStr="";

for(i=0; i<l; i++)
{
  if(inpStr[i] == "." && flag == 0)
  {
    n = i;

    if(inpStr[i-1]=="9")
    {
      flag = 3; // GoTo
    }
    else if(inpStr[i+1]<"5")
    {
      flag = 2; // down
    }
    else
    {
      flag = 1; // up
    }
  }
}

if(flag == 3)
{
  outStr = "GOTO Vasilisa.";
}

if(flag == 2)
{
  outStr = inpStr.slice(0,n);
}

if(flag == 1)
{
  var s = inpStr[n-1], sn = s.charCodeAt(0), ss = String.fromCharCode(sn+1);

  outStr = inpStr.slice(0,n);
  outStr = outStr + ss;
}

print(outStr);


'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

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

    for (let test = 0; test < N; test++) {
        let [n, k] = readline().split(' ').map(Number);
        let arr = readline().split(' ').map(Number);
        let brr = readline().split(' ').map(Number);

        let shops = arr.map((v, i) => ({
            pay: arr[i],
            get: brr[i]
        }));

        shops.sort((a, b) => a.pay - b.pay);

        let i = 0;
        while (i < n) {
            if (shops[i].pay <= k) {
                k += shops[i].get;
            } else {
                break;
            }
            i++;
        }

        output(k);
    }
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let j = inputReader.readNumber();
	while (j--) {
	  let [n, k] = inputReader.readNumberArray();
	  let a = [];
	  let b = inputReader.readNumberArray();
	  for (let i = 0; i < n; i++)
	    a[i] = { ff: b[i] };
	  b = inputReader.readNumberArray();
	  for (let i = 0; i < n; i++)
	    a[i].ss = b[i];
	  a.sort((a, b) => a.ff - b.ff);
	  for (let i = 0; i < n; i++)
	    if (a[i].ff <= k) k += a[i].ss;
	  console.log(k);
	}

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

//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 K = nextInt();
		var list = new Array(N);
		for(var i = 0; i < N; i++){
			list[i] = {
				A : nextInt(),
				B : 0
			};
		}
		for(var i = 0; i < N; i++){
			list[i].B = nextInt();
		}
		list.sort(function(a,b){
			return a.A - b.A;
		});
		for(var i = 0; i < N; i++){
			if(list[i].A <= K){
				K += list[i].B;
			}else{
				break;
			}
		}
		myout(K);
	}
}

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});
process.stdin.on("end", (chunk) => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0]);
  let i = 1;
  while (t--) {
    let [n, k] = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    let a = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    let b = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    let software = [];
    for (let j = 0; j < n; j++) {
      software.push([a[j], b[j]]);
    }
    software.sort((a, b) => a[0] - b[0]);
    for (let j = 0; j < n; j++) {
      if (software[j][0] <= k) {
        k += software[j][1];
      }
    }
    console.log(k);
  }
});

let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}

let nl = nextLine();

nl.elem = function(funParse) {
		return funParse(this.next().value);
	};

nl.array = function(funParse) {
		return this.next().value.split(/\s/g).map(funParse||(x => x));
	};

nl.num = function() {
		return nl.elem(Number);
	};

nl.nums = function() {
		return nl.array(Number);
	};

nl.line = function() {
		return this.next().value;
	};

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let [n, k] = nl.nums();
		let a = nl.nums();
		let b = nl.nums();
		let ab = a.map((e, i) => [e, b[i]]);
		ab.sort((a, b) => a[0] - b[0]);
		for(let  j = 0; j < n && ab[j][0] <= k; j++){
			k += ab[j][1];
		}
		ans.push(k);
	}
	console.log(ans.join('\n'));
};

process.stdin.on('end', sol);

// Common Template Starts //
//*
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++];
}
// Common Template Ends //

// LIBRARY START //

const isOdd = (x) => {
  return x & 1;
};
const isEven = (x) => {
  return !(x & 1);
};

const reverseText = (s) => {
  return s.split("").reverse().join("");
};
const hasDuplicates = (str) => /([a-z])\1/i.test(str);

const hasDuplicateChar = (str, char) =>
  str.indexOf(char) !== str.lastIndexOf(char);

const isSorted = (arr) => arr.every((v, i, a) => !i || a[i - 1] <= v);

const findAllIndicesOfChar = (str, char) => {
  str = str.split("");
  let indices = [];
  for (let i = 0; i < str.length; i++) {
    if (str[i] === char) indices.push(i);
  }
  return indices;
};

const splitAt = (index) => (x) => [x.slice(0, index), x.slice(index)];

const isUpper = (str) => !/[a-z]/.test(str) && /[A-Z]/.test(str);

const escapeRegExp = (string) =>
  string.replace(/[.*+\-?^$$${}()|[\]\\]/g, "$$$&");

const replaceAll = (str, find, replace) =>
  str.replace(new RegExp(escapeRegExp(find), "g"), replace);

const findUnique = (str) => {
  return [...str].reduce((acc, curr) => {
    return acc.includes(curr) ? acc : acc + curr;
  }, "");
};

const unique = (str) => {
  const cleanStr = str.replace(/ /gi, "");
  const set = [...new Set(cleanStr)];
  return set;
};

const sortASC = (array) => {
  // var numArray = new Uint32Array(array)
  // var numArray = new Int32Array(array)
  var numArray = new Float64Array(array);
  numArray = numArray.sort();
  return numArray;
};

const removeDuplicates = (array) => [...new Set(array)];

// LIBRARY END

function solve() {
  let [n, k] = readline().split(" ").map(Number);
  let ram = new Array(n);
  a = readline().split(" ").map(Number);
  b = readline().split(" ").map(Number);
  for (let i = 0; i < n; i++) {
    ram[i] = new Array(2);
    ram[i][0] = a[i];
    ram[i][1] = b[i];
  }
  ram.sort(function (a, b) {
    return a[0] - b[0];
  });
  for (let i = 0; i < n; i++) {
    if (ram[i][0] <= k) {
      k += ram[i][1];
    }
  }
  console.log(k);
}

function main() {
  let tc = +readline();
  while (tc--) {
    solve();
  }
}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var [n,k] = readline().split(" ").map(w => parseInt(w))
            var a = readline().split(" ").map(w => parseInt(w))
            var b = readline().split(" ").map(w => parseInt(w))
            var nw = []
            for(var i=0;i<a.length;i++) {
            	var f = [a[i], b[i]]
            	nw.push(f)
            }
            nw.sort(function(ar,br) { return ar[0]-br[0] })
            var sum = k;
            for(var i=0;i<nw.length;i++) {
            	if(sum >= nw[i][0]) {
            		sum+= nw[i][1]
            	}
            }
            console.log(sum)
}

var total = +readline();
while (total--) {
    var RAM = +readline().split(" ")[1];
    var requireRams = readline().split(" ").map(function (x) {
        return +x;
    });
    var acquireRams = readline().split(" ").map(function (x) {
        return +x;
    });
    var rams = [];
    for (var i = 0; i < requireRams.length; i++) {
        rams.push({
            requireRams: requireRams[i],
            acquireRams: acquireRams[i]
        });
    }
    rams.sort(function (a, b) {
        return a.requireRams - b.requireRams;
    });
    var count = 0;
    while (count < rams.length && rams[count].requireRams <= RAM) {
        RAM += rams[count].acquireRams;
        count++;
    }
    print(RAM);
}

var t = +readline();

while(t--) {
  var line = readline().split(' ');
  var n = +line[0], k = +line[1];
  var arrA = readline().split(' ').map(function(n) { return +n; });
  var arrB = readline().split(' ').map(function(n) { return +n; });
  var arrAB = [];

  for (var i = 0; i < n; i++) {
    arrAB.push([arrA[i], arrB[i]]);
  }

  arrAB.sort(function(a, b) { return a[0] - b[0]; });

  var res = k;

  for (var i = 0; i < n; i++) {
    if (arrAB[i][0] <= res) {
      res += arrAB[i][1];
    }
  }

  print(res);
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	while (n--) {
	  let [s1, ss] = inputReader.readNumberArray();
	  const used = {};
	  let a = new Array(s1);
	  for (let j = 0; j < 2; j++) {
	    let b = inputReader.readNumberArray();
	    a = a.concat(b);
	  }
	  while (true) {
	    let check = false;
	    for (let i = 0; i < a.length; i++) {
	      if (!used[i % s1] && ss >= a[i]) {
	        check = true;
	        used[i % s1] = true;
	        ss += a[i];
	      }
	    }
	    if (!check) break;
	  }
	}

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	let n = inputReader.readNumber();
	while (n--) {
	  let [s1, ss] = inputReader.readNumberArray();
	  const used = {};
	  let a = new Array(s1);
	  for (let j = 0; j < 2; j++) {
	    let b = inputReader.readNumberArray();
	    a = a.concat(b);
	  }
	  while (true) {
	    let check = false;
	    for (let i = 0; i < a.length; i++) {
	      if (!used[i % s1] && ss >= a[i]) {
	        check = true;
	        used[i % s1] = true;
	        ss += a[i];
	      }
	    }
	    if (!check) break;
	  }
	  console.log(ss);
	}

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}