Codeforces separates its users into $$$4$$$ divisions by their rating:  For Division 1: $$$1900 \leq \mathrm{rating}$$$  For Division 2: $$$1600 \leq \mathrm{rating} \leq 1899$$$  For Division 3: $$$1400 \leq \mathrm{rating} \leq 1599$$$  For Division 4: $$$\mathrm{rating} \leq 1399$$$ Given a $$$\mathrm{rating}$$$, print in which division the $$$\mathrm{rating}$$$ belongs.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of testcases. The description of each test consists of one line containing one integer $$$\mathrm{rating}$$$ ($$$-5000 \leq \mathrm{rating} \leq 5000$$$).

For each test case, output a single line containing the correct division in the format "Division X", where $$$X$$$ is an integer between $$$1$$$ and $$$4$$$ representing the division for the corresponding rating.

Division 4
Division 4
Division 4
Division 4
Division 3
Division 2
Division 1

NoteFor test cases $$$1-4$$$, the corresponding ratings are $$$-789$$$, $$$1299$$$, $$$1300$$$, $$$1399$$$, so all of them are in division $$$4$$$.For the fifth test case, the corresponding rating is $$$1400$$$, so it is in division $$$3$$$.For the sixth test case, the corresponding rating is $$$1679$$$, so it is in division $$$2$$$.For the seventh test case, the corresponding rating is $$$2300$$$, so it is in division $$$1$$$.

var len = parseInt(readline());
var i=0;
var rating;
for(i=0; i < len; i++){
 rating = parseInt(readline());
if (rating >= 1900){
	print("Division 1")
}
else if (rating <= 1899 && rating >= 1600){
	print("Division 2")
}

else if (rating <= 1599 && rating >= 1400){
	print("Division 3")
}
else if(rating <= 1399){
	print("Division 4")
}
}

const linesCount = readline();

for(x = 0; x < +linesCount; x++) {
    var curLine = parseInt(readline());
    // print(curLine, typeof curLine);
    if (curLine >= 1900) {
        print('Division 1');
    } else if (curLine >= 1600) {
        print('Division 2');
    } else if (curLine >= 1400) {
        print('Division 3');
    } else {
        print('Division 4');
    }
}

var x = readline();
x = Number(x);

while (x--) {
	var a = readline(); a = Number(a);
	if (1900<=a) print('Division 1');
	if (1600<=a&&a<=1899) print('Division 2');
	if (1400<=a&&a<=1599) print('Division 3');
	if (a<=1399) print('Division 4');
}

var testCase = +readline()
for (var i = 0; i < testCase; i++) {
  var sequence = +readline()
  if (sequence >= 1900) {
    print("Division 1")
  } else if (sequence >= 1600 && sequence <= 1899) {
    print("Division 2")
  } else if (sequence >= 1400 && sequence <= 1599) {
    print("Division 3")
  } else {
    print("Division 4")
  }
}

var num=parseInt(readline());
var arr=[];
for(var i=0;i<num;i++){
    arr.push(parseInt(readline()));
}
for(var i=0;i<num;i++){
    if(arr[i]<=1399){
        print("Division 4");
    }
    else if(arr[i]<=1599){
        print("Division 3");
    }
    else if(arr[i]<=1899){
        print("Division 2");
    }
    else{
        print("Division 1");
    }
}

var a = readline();
var arr = [];
var s = 0;
for(var i = 0; i < a; i++){
    arr[i] = readline();
    if(arr[i]<=1399){
        print("Division 4");
    }else if(arr[i]>=1400 && 1599>=arr[i]){
        print("Division 3")
    }else if(arr[i]>=1600 && 1899>=arr[i]){
        print("Division 2")
    }else{
        print("Division 1")
    }
}

var t = readline();
for(var i =0 ; i < t ; i++){
    var rating = Number(readline());
    if (rating >= 1900) {
        print('Division 1');
    } else if (rating >= 1600) {
        print('Division 2');
    } else if (rating >= 1400) {
        print('Division 3');
    } else {
        print('Division 4');
    }
}

var t = readline();
for(var  i = 0 ; i < t ; i++){
    var rating  = readline();
        if(rating <= 1399 ){
            print("Division 4");
        }
        else if(rating >= 1400 && rating <= 1599){
            print("Division 3");
        }
        else if(rating >= 1600 && rating <= 1899  ){
            print("Division 2");
        }
                else if(rating >= 1900 ){
            print("Division 1");
        }
}

T = readline()
while (T--) {
   x = readline()
   ans = 0
   if(x <= 1399)
      ans = 'Division 4'
   else  if(x >= 1400 && x <= 1599)
      ans = 'Division 3'
   else  if(x >= 1600 && x <= 1899)
      ans = 'Division 2'
   else  if(x >= 1900)
      ans = 'Division 1'

   print(ans)
}

n=Number(readline())
for (i=0;i<n;++i) {
  x = Number(readline())
  if (x<=1399)
    print('Division 4');
  else if (x<=1599)
    print('Division 3');
  else if (x<=1899)
    print('Division 2');
  else
    print('Division 1')

}

var n = parseInt(readline());
for(var i = 0; i < n; i++)
{
    var points = parseInt(readline());
    if(points <= 1399) print('Division 4')
    if(points >= 1400 && points <= 1599) print('Division 3')
    if(points >= 1600 && points <= 1899) print('Division 2')
    if(points >= 1900) print('Division 1')
}

var t = readline();
while ( t -- ) {
    var n = readline();
    if ( n >= 1900 ){
        print("Division 1")
    }
    else if ( n >= 1600 ) {
        print("Division 2") ;
    }
    else if ( n >= 1400 ) {
        print("Division 3") ;
    }
    else {
        print("Division 4") ;
    }
}

var t = +readline()

for(var i = 0; i< t; i ++) {
    var a = +readline()
    print(whichDivision(a))
}

function whichDivision(n){
   if (n >= 1900){
      return 'Division 1'
   }
   else if (1600 <= n && n <= 1899){
      return 'Division 2'
   }
   else if (1400 <= n && n <= 1599){
      return 'Division 3'
   }
   else {
      return 'Division 4'
   }
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n ; j++){
        var rating = lines[j]
        if(1900 <= rating){
            console.log('Division 1')
        }else if(1600 <= rating && rating <= 1899){
            console.log('Division 2')
        }else if(1400 <= rating && rating <= 1599){
            console.log('Division 3')
        }else {
            console.log('Division 4')
        }
    }
});

let stdin = process.stdin;
stdin.setEncoding('utf8');
stdin.on('data', function (data) {
    let input = data.split('\n');
    let count = parseInt(input[0]);

    for (let i = 0; i < count; i++) {
        const number = input[i + 1];

        if (number >= 1900) {
            console.log('Division ', 1);
        }

        if (number >= 1600 && number <= 1899) {
            console.log('Division ', 2);
        }

        if (number >= 1400 && number <= 1599) {
            console.log('Division ', 3);
        }

        if (number <= 1399) {
            console.log('Division ', 4);
        }
    }
});

let stdin = process.stdin;
stdin.setEncoding('utf8');
stdin.on('data', function (data) {
    let input = data.split('\n');
    let count = parseInt(input[0]);

    for (let i = 0; i < count; i++) {
        const number = input[i + 1];

        if (number >= 1900) {
            console.log('Division 1');
        }

        if (number >= 1600 && number <= 1899) {
            console.log('Division 2');
        }

        if (number >= 1400 && number <= 1599) {
            console.log('Division 3');
        }

        if (number <= 1399) {
            console.log('Division 4');
        }
    }
});

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

let c = 0;

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

  const rating = Number(d);
  if (rating <= 1399) {
    console.log("Division 4");
  } else if (rating >= 1400 && rating <= 1599) {
    console.log("Division 3");
  } else if (rating >= 1600 && rating <= 1899) {
    console.log("Division 2");
  } else {
    console.log("Division 1");
  }

  c++;
});

rl.on("close", () => {});

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine(){
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace('\r', '');
}

function print(x) {
    console.log(x);
}

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine().split(" ").map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function getDivision(rating = Number)
{
    let rs = 4;
    if (rating >= 1900)
    {
        rs = 1;
    }
    else if (rating >= 1600 && rating < 1900)
    {
        rs = 2;
    }
    else if (rating >= 1400 && rating < 1600)
    {
        rs = 3;
    }

    return `Division ${rs}`;
}

function solve()
{
    let n = readSingleInt();
    while (n--)
    {
        let p = readSingleInt();
        console.log(getDivision(p))
    }
}

'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) {
  if (n < 1400) {
    console.log('Division 4');
  } else if (n < 1600) {
    console.log('Division 3');
  } else if (n < 1900) {
    console.log('Division 2');
  } else {
    console.log('Division 1');
  }
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    solve(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);
}();

'use strict';
 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  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;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;
const ra = ()=>readline().split(' ').map(a=>+a)

const calc = (n, m, A)=>{
  if (n<=1399)
    return 4;
  if (n<=1599)
    return 3;
  if (n<=1899)
    return 2;
    return 1
};

function main() {
    let T = +readline()
    while (T--){
      let [n, m] = ra();
      L('Ans:')
      print('Division '+calc(n, m));
    }
}

E.calc = calc;

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

let input = [];
let ans = [];
readline.on('line', line => {
    input.push(line);
}).on('close', () => {
    let cases = input.slice(1).map(Number);
    for (let i = 0; i < cases.length; i++) {
        ans.push(`Division ${cases[i] <= 1399 ? 4 : cases[i] <= 1599 ? 3 : cases[i] <= 1899 ? 2 : 1}`);
    }
    console.log(ans.join('\n'));
});

'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 = parseInt(readline(), 10);

        let o = d => output(`Division ${d}`);

        if (n <= 1399) {
            o(4);
        } else if (n <= 1599) {
            o(3);
        } else if (n <= 1899) {
            o(2);
        } else {
            o(1);
        }
    }
}

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 r = nl.num();
		let x = 1;
		if (r <= 1399){
			x = 4;
		} else if (r <= 1599){
			x = 3;
		} else if (r <= 1899){
			x = 2;
		}
		ans.push(`Division ${x}`);
	}
	console.log(ans.join('\n'));
};

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

'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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  let i = readline()
  while (i--) {
    const n = readline() | 0
    if (n >= 1900) {
      console.log('Division 1')
    } else if (n >= 1600) {
      console.log('Division 2')
    } else if (n >= 1400) {
      console.log('Division 3')
    } else {
      console.log('Division 4')
    }
  }
}

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 num = parseInt(readLine());
    if (num <= 1399) return "Division 4";
    if (num <= 1599) return "Division 3";
    if (num <= 1899) return "Division 2";
    if (num >= 1900) return "Division 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 readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const T = readline();
    for (let i = 0; i < T; i++) {
        const n = readline()
        solve(n)
    }
}
function solve(n) {
    let res = 4
    if (n >= 1900) {
        res = 1
    } else if (n >= 1600) {
        res = 2
    } else if (n >= 1400) {
        res = 3
    }

    console.log('Division ' + res)
}

/*
 * File Created: Thursday, 11th February 2021 1:42:08 pm
 * Author: Lukas Rimkus
 */
'use-strict'

process.stdin.resume();
process.stdin.setEncoding('utf8');

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(data.shift());

    while(testCases--) {

        const s = parseInt(data.shift());

        console.log(a784(s));
    }
});

function get_ints() {
    return data[currentLine++].split(' ').map(Number);
}

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

function a(n,arr){
    let k = 0;
    let j = 0;
    for(let i = 0 ; i < n; i++){
        if(arr[i] < 0){
            arr[j++] *= -1;
            arr[i] *= -1;
        }
    }
    if(isSorted(arr)) {
        return 'YES';
    } else {
        return 'NO'
    }
}

function isSorted(arr){
    for(let i = 0 ; i < arr.length - 1; i++){
        if(arr[i] > arr[i+1]) return false;
    }
    return true;
}

function b(s) {
    let arr = [];
    for(let i = 97; i <= 122; i++ ){
        for(let j = 97; j <= 122; j++){
            if(i != j) arr.push(String.fromCharCode(i,j));
        }
    }
    let count = 1;
    let index = 0;
    while(true){
        if(s != arr[index]) {
            count++;
            index++;
        } else{
            return count;
        }
    }
}

function a784(s){
    if(s >= 1900) {
        return 'Division 1';
    } else if(s >= 1600){
        return 'Division 2';
    } else if(s >= 1400){
        return 'Division 3';
    } else {
        return 'Division 4';
    }
}
module.exports = a784;

let q = '';
process.stdin.on('data', c => q += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = q.split(EOL);
    var n = lines[0];
    var e = 0;
    for(i = 1; i <= n; i++){
        var k = lines[i];
        if(1900 <= k){
            console.log('Division 1');
        }else if(1600 <= k && k <= 1899){
            console.log('Division 2');
        }else if(1400 <= k && k <= 1599){
            console.log('Division 3');
        }else if(k <= 1399){
            console.log('Division 4');
        }
    }
});

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

let lines = [];

async function main() {
  for await (let line of rl) {
	  lines.push(line);
  }

	let inputs = +lines.splice(0, 1); // dirty javascript typecasting to number

  for (let line of lines) {
    switch (true) {
      case +line <= 1399:
        console.log("Division 4");
        break;
      case +line <= 1599:
        console.log("Division 3");
        break;
      case +line <= 1899:
        console.log("Division 2");
        break;
      default:
        console.log("Division 1");
        break;
    }
  }
}

main();

var stdin_input = "";
var stdin_input_itr;
process.stdin.resume();
process.stdin.setEncoding("ascii");
process.stdin.on("data", function (input) { stdin_input += input; });
process.stdin.on("end", function () { stdin_input_itr = stdin_input.split('\n').values(); main(); });

const rl = () => stdin_input_itr.next().value.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const rating = rn();
		let ans;
		if (rating >= 1900) ans = 1;
		else if (rating >= 1600) ans = 2;
		else if (rating >= 1400) ans = 3;
		else ans = 4;

		console.log('Division', ans);
	}
}

const getDivison = (n) => {
    if (n >= 1900) {
        return 1
    }
    if (n >= 1600) {
        return 2
    }
    if (n>= 1400) {
        return 3
    }
    return 4;
}

const processData = (lines) => {
    let n = +lines[0];
    for (let i=1; i<=n; i++) {
        let num = +lines[i]
        console.log(`Division ${getDivison(num)}`)
    }

}

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

//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 rating = nextInt();
		var S = "Division ";
		if(rating <= 1399){
			S += 4;
		}else if(1400 <= rating && rating <= 1599){
			S += 3;
		}else if(1600 <= rating && rating <= 1899){
			S += 2;
		}else{
			S += 1;
		}
		myout(S);
	}
}

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;
function readline() {
    return lines[rli++];
}

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

function div(val, by){
    return (val - val % by) / by;
}

const calc = (a)=>{
    if (a >= 1900) return 1;
    if (a >= 1600) return 2;
    if (a >= 1400) return 3;
    return 4;
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let a = +readline();

        console.log(`Division ${calc(a)}`);
    }
}

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 = +lines[l++]
        output[i] = solve(n)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n) {
    if (n >= 1900) {
        return 'Division 1'
    } else if (n >= 1600) {
        return 'Division 2'
    } else if (n >= 1400) {
        return 'Division 3'
    } else {
        return 'Division 4'
    }
}

var len = parseInt(readline());
var i=0;
var rating;
for(i=0; i < len; i++){
 rating = parseInt(readline());
if (rating >= 1900){
	print("Divison 1")
}
else if (rating <= 1899 && rating >= 1600){
	print("Divison 2")
}

else if (rating <= 1599 && rating >= 1400){
	print("Divison 3")
}
else if(rating <= 1399){
	print("Divison 4")
}
}

var len = parseInt(readline());
var i=0;
var rating;
for(i=0; i < len; i++){
 rating = parseInt(readline());
if (rating >= 1900){
	print("Divison 1")
}
else if (rating <= 1899 || rating >= 1600){
	print("Divison 2")
}

else if (rating <= 1599 || rating >= 1400){
	print("Divison 3")
}
else if(rating <= 1399){
	print("Divison 4")
}
}

var len = parseInt(readline());
var i=0;
var rating;
for(i=0; i < len; i++){
 rating = parseInt(readline());
if (rating >= 1900){
	print("Divison 1")
}
else if (rating <= 1899 && rating >= 1600){
	print("Divison 2")
}

else if (rating <= 1599 && rating >= 1400){
	print("Divison 3")
}
else{
	print("Divison 4")
}
}

var len = parseInt(readline());
var i=0;
var rating;
for(i=0; i < len; i++){
 rating = parseInt(readline());
if (rating <= 1900){
	print("Divison 1")
}
else if (rating <= 1899 && rating >= 1600){
	print("Divison 2")
}

else if (rating <= 1599 && rating >= 1400){
	print("Divison 3")
}
else{
	print("Divison 4")
}
}

const linesCount = readline();

for(x = 0; x < +linesCount; x++) {
    var curLine = parseInt(readline());
    print(curLine, typeof curLine);
    if (curLine >= 1900) {
        print('Division 1');
    } else if (curLine >= 1600) {
        print('Division 2');
    } else if (curLine >= 1400) {
        print('Division 3');
    } else {
        print('Division 4');
    }
}

var testCase = +readline()
for (var i = 0; i < testCase; i++) {
  var sequence = +readline()
  if (sequence > 1900) {
    print("Division 1")
  } else if (sequence >= 1600 && sequence <= 1899) {
    print("Division 2")
  } else if (sequence >= 1400 && sequence <= 1599) {
    print("Division 3")
  } else {
    print("Division 4")
  }
}

var num=parseInt(readline());
var arr=[];
for(var i=0;i<num;i++){
    arr.push(parseInt(readline()));
}
for(var i=0;i<num;i++){
    switch(arr[i]){
        case arr[i]<=1399:
            print("Division 4");
            break;
        case arr[i]<=1599:
            print("Division 3");
            break;
        case arr[i]<=1899:
            print("Division 2");
            break;
        default:
            print("Division 1");
    }
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var rating = lines[j]
        if(1900 < rating){
            console.log('Division 1')
        }else if(1600 < rating && rating < 1899){
            console.log('Division 2')
        }else if(1400 < rating && rating < 1599){
            console.log('Division 3')
        }else if(rating < 1399){
            console.log('Division 4')
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var rating = lines[j]
        if(1900 < rating){
            console.log('Division 1')
        }else if(1600 < rating && rating < 1899){
            console.log('Division 2')
        }else if(1400 < rating < 1599){
            console.log('Division 3')
        }else if(rating < 1399){
            console.log('Division 4')
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var rating = lines[j]
        if(1900 < rating){
            console.log('Division 1')
        }else if(1600 < rating && rating < 1899){
            console.log('Division 2')
        }else if(1400 < rating < 1599){
            console.log('Division 3')
        }else if(1399 > rating){
            console.log('Division 4')
        }
    }
});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j++){
        var rating = lines[j]
        if(1900 < rating){
            console.log('Division 1')
        }else if(1600 < rating && rating < 1899){
            console.log('Division 1')
        }else if(1400 < rating < 1599){
            console.log('Division 1')
        }else if(1399 > rating){
            console.log('Division 1')
        }
    }
});

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

let c = 0;

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

  const rating = Number(d);
  if (rating <= 1399) {
    console.log("Division 4");
  } else if (rating >= 1400 && rating <= 1599) {
    console.log("Divison 3");
  } else if (rating >= 1600 && rating <= 1899) {
    console.log("Division 2");
  } else {
    console.log("Division 1");
  }

  c++;
});

rl.on("close", () => {});

'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) {
  if (n < 1400) {
    console.log('Division4');
  } else if (n < 1600) {
    console.log('Division3');
  } else if (n < 1900) {
    console.log('Division2');
  } else {
    console.log('Division1');
  }
}

async function main(read) {
  const t = Number(await read());
  for (let i = 0; i < t; i++) {
    const n = Number(await read());
    solve(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);
}();

'use strict';
 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  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;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;
const ra = ()=>readline().split(' ').map(a=>+a)

const calc = (n, m, A)=>{
  if (n<=1399)
    return 4;
  if (n<=1599)
    return 3;
  if (n<=1899)
    return 2;
    return 1
};

function main() {
    let T = +readline()
    while (T--){
      let [n, m] = ra();
      L('Ans:')
      print(calc(n, m));
    }
}

E.calc = calc;


You are wandering in the explorer space of the 2050 Conference.The explorer space can be viewed as an undirected weighted grid graph with size $$$n\times m$$$. The set of vertices is $$$\{(i, j)|1\le i\le n, 1\le j\le m\}$$$. Two vertices $$$(i_1,j_1)$$$ and $$$(i_2, j_2)$$$ are connected by an edge if and only if $$$|i_1-i_2|+|j_1-j_2|=1$$$.At each step, you can walk to any vertex connected by an edge with your current vertex. On each edge, there are some number of exhibits. Since you already know all the exhibits, whenever you go through an edge containing $$$x$$$ exhibits, your boredness increases by $$$x$$$.For each starting vertex $$$(i, j)$$$, please answer the following question: What is the minimum possible boredness if you walk from $$$(i, j)$$$ and go back to it after exactly $$$k$$$ steps?You can use any edge for multiple times but the boredness on those edges are also counted for multiple times. At each step, you cannot stay on your current vertex. You also cannot change direction while going through an edge. Before going back to your starting vertex $$$(i, j)$$$ after $$$k$$$ steps, you can visit $$$(i, j)$$$ (or not) freely.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2\leq n, m\leq 500, 1\leq k\leq 20$$$). The $$$j$$$-th number ($$$1\le j \le m - 1$$$) in the $$$i$$$-th line of the following $$$n$$$ lines is the number of exibits on the edge between vertex $$$(i, j)$$$ and vertex $$$(i, j+1)$$$.  The $$$j$$$-th number ($$$1\le j\le m$$$) in the $$$i$$$-th line of the following $$$n-1$$$ lines is the number of exibits on the edge between vertex $$$(i, j)$$$ and vertex $$$(i+1, j)$$$.  The number of exhibits on each edge is an integer between $$$1$$$ and $$$10^6$$$.

Output $$$n$$$ lines with $$$m$$$ numbers each. The $$$j$$$-th number in the $$$i$$$-th line, $$$answer_{ij}$$$, should be the minimum possible boredness if you walk from $$$(i, j)$$$ and go back to it after exactly $$$k$$$ steps. If you cannot go back to vertex $$$(i, j)$$$ after exactly $$$k$$$ steps, $$$answer_{ij}$$$ should be $$$-1$$$.

NoteIn the first example, the answer is always $$$10$$$ no matter how you walk.In the second example, $$$answer_{21} = 10$$$, the path is $$$(2,1) \to (1,1) \to (1,2) \to (2,2) \to (2,1)$$$, the boredness is $$$4 + 1 + 2 + 3 = 10$$$.

"use strict";

// start below this line
var line = readline().split(" ");
var n = parseInt(line[0], 10);
var m = parseInt(line[1], 10);
var bigK = parseInt(line[2], 10);

if (bigK % 2 === 1) {
  for (var _ = 0; _ < n; ++_) {
    print(new Array(m).fill(-1).join(" "));
  }
} else {
  var a = new Array(n);

  for (var _2 = 0; _2 < n; ++_2) {
    a[_2] = readline()
      .split(" ")
      .map(function (v) {
        return parseInt(v, 10);
      });
  }

  var b = new Array(n - 1);

  for (var _3 = 0; _3 < n - 1; ++_3) {
    b[_3] = readline()
      .split(" ")
      .map(function (v) {
        return parseInt(v, 10);
      });
  }

  var x = new Array(n).fill(0).map(function () {
    return new Array(m).fill(0);
  });
  bigK >>= 1;

  for (var k = 1; k <= bigK; ++k) {
    var y = new Array(n).fill(0).map(function () {
      return new Array(m).fill(1e8);
    });

    for (var i = 0; i < n; ++i) {
      for (var j = 0; j < m; ++j) {
        if (i > 0) {
          y[i][j] = x[i - 1][j] + 2 * b[i - 1][j];
        }

        if (i < n - 1) {
          y[i][j] = Math.min(y[i][j], x[i + 1][j] + 2 * b[i][j]);
        }

        if (j > 0) {
          y[i][j] = Math.min(y[i][j], x[i][j - 1] + 2 * a[i][j - 1]);
        }

        if (j < m - 1) {
          y[i][j] = Math.min(y[i][j], x[i][j + 1] + 2 * a[i][j]);
        }
      }
    }

    x = y;
  }

  for (var _i = 0; _i < n; ++_i) {
    print(x[_i].join(" "));
  }
}

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    writeArray(arr) {
        arr.forEach((a) => {
            this.write(a);
        });
        this.writeLine('');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
function make2dArray(a, b, fill) {
    return Array.from({ length: a }).map(() => Array.from({ length: b }).map(() => fill));
}
//////////// LIBS
const io = new IO();
function solve() { }
function main() {
    try {
        let n = io.nextNum();
        let m = io.nextNum();
        let k = io.nextNum();
        let rightCost = [];
        let downCost = [];
        for (let i = 0; i < n; i++) {
            rightCost.push([]);
            for (let j = 0; j < m - 1; j++) {
                rightCost[i][j] = io.nextNum();
            }
        }
        for (let i = 0; i < n - 1; i++) {
            downCost.push([]);
            for (let j = 0; j < m; j++) {
                downCost[i][j] = io.nextNum();
            }
        }
        if (k % 2 === 1) {
            let arr = Array.from({ length: m }).fill(-1);
            for (let i = 0; i < n; i++) {
                io.writeArray(arr);
            }
            io.flush();
            return;
        }
        let dp = [];
        const printStep = (step, mul = 1) => {
            for (let i = 0; i < n; i++) {
                for (let j = 0; j < m; j++) {
                    io.write(dp[i][j][step] * mul);
                }
                io.writeLine('');
            }
            io.writeLine('');
        };
        const getXCost = (i, j) => {
            var _a, _b;
            return (_b = (_a = rightCost[i]) === null || _a === void 0 ? void 0 : _a[j]) !== null && _b !== void 0 ? _b : Infinity;
        };
        const getYCost = (i, j) => {
            var _a, _b;
            return (_b = (_a = downCost[i]) === null || _a === void 0 ? void 0 : _a[j]) !== null && _b !== void 0 ? _b : Infinity;
        };
        // console.log({ rightCost, downCost });
        for (let i = 0; i < n; i++) {
            dp[i] = [];
            for (let j = 0; j < m; j++) {
                dp[i][j] = [];
                dp[i][j][1] = Math.min(getXCost(i, j), getXCost(i, j - 1), getYCost(i, j), getYCost(i - 1, j));
                // console.log({
                //   i,
                //   j,
                //   right: getXCost(i, j),
                //   left: getXCost(i - 1, j),
                //   down: getYCost(i, j),
                //   up: getYCost(i, j - 1),
                //   min: dp[i][j][1],
                // });
            }
        }
        const getDp = (i, j, l) => {
            var _a, _b, _c;
            return (_c = (_b = (_a = dp[i]) === null || _a === void 0 ? void 0 : _a[j]) === null || _b === void 0 ? void 0 : _b[l]) !== null && _c !== void 0 ? _c : Infinity;
        };
        // printStep(1);
        let target = k / 2;
        // console.log(dp);
        for (let l = 2; l <= target; l++) {
            for (let i = 0; i < n; i++) {
                for (let j = 0; j < m; j++) {
                    dp[i][j][l] = Math.min(getDp(i, j - 1, l - 1) + getXCost(i, j - 1), getDp(i, j + 1, l - 1) + getXCost(i, j), getDp(i - 1, j, l - 1) + getYCost(i - 1, j), getDp(i + 1, j, l - 1) + getYCost(i, j));
                }
            }
        }
        // for (let j = 0; j < m; j++) {
        //   for (let i = 0; i < n; i++) {
        //     io.write(dp[i][j][2]);
        //   }
        //   io.writeLine('');
        // }
        // io.writeLine('');
        printStep(target, 2);
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    writeArray(arr) {
        arr.forEach((a) => {
            this.write(a);
        });
        this.writeLine('');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
function make2dArray(a, b, fill) {
    return Array.from({ length: a }).map(() => Array.from({ length: b }).map(() => fill));
}
//////////// LIBS
const io = new IO();
function solve() { }
function main() {
    try {
        let n = io.nextNum();
        let m = io.nextNum();
        let k = io.nextNum();
        let rightCost = [];
        let downCost = [];
        for (let i = 0; i < n; i++) {
            rightCost.push([]);
            for (let j = 0; j < m - 1; j++) {
                rightCost[i][j] = io.nextNum();
            }
        }
        for (let i = 0; i < n - 1; i++) {
            downCost.push([]);
            for (let j = 0; j < m; j++) {
                downCost[i][j] = io.nextNum();
            }
        }
        if (k % 2 === 1) {
            let arr = Array.from({ length: m }).fill(-1);
            for (let i = 0; i < n; i++) {
                io.writeArray(arr);
            }
            io.flush();
            return;
        }
        let dp = [];
        const printStep = (step, mul = 1) => {
            for (let i = 0; i < n; i++) {
                for (let j = 0; j < m; j++) {
                    io.write(dp[i][j][step] * mul);
                }
                io.writeLine('');
            }
            io.writeLine('');
        };
        const getXCost = (i, j) => {
            if (!rightCost[i]) {
                return Infinity;
            }
            return rightCost[i][j] || Infinity;
        };
        const getYCost = (i, j) => {
            if (!downCost[i]) {
                return Infinity;
            }
            return downCost[i][j] || Infinity;
        };
        // console.log({ rightCost, downCost });
        for (let i = 0; i < n; i++) {
            dp[i] = [];
            for (let j = 0; j < m; j++) {
                dp[i][j] = [];
                dp[i][j][1] = Math.min(getXCost(i, j), getXCost(i, j - 1), getYCost(i, j), getYCost(i - 1, j));
                // console.log({
                //   i,
                //   j,
                //   right: getXCost(i, j),
                //   left: getXCost(i - 1, j),
                //   down: getYCost(i, j),
                //   up: getYCost(i, j - 1),
                //   min: dp[i][j][1],
                // });
            }
        }
        const getDp = (i, j, l) => {
            if (!dp[i]) {
                return Infinity;
            }
            if (!dp[i][j]) {
                return Infinity;
            }
            return dp[i][j][l];
        };
        // printStep(1);
        let target = k / 2;
        // console.log(dp);
        for (let l = 2; l <= target; l++) {
            for (let i = 0; i < n; i++) {
                for (let j = 0; j < m; j++) {
                    dp[i][j][l] = Math.min(getDp(i, j - 1, l - 1) + getXCost(i, j - 1), getDp(i, j + 1, l - 1) + getXCost(i, j), getDp(i - 1, j, l - 1) + getYCost(i - 1, j), getDp(i + 1, j, l - 1) + getYCost(i, j));
                }
            }
        }
        // for (let j = 0; j < m; j++) {
        //   for (let i = 0; i < n; i++) {
        //     io.write(dp[i][j][2]);
        //   }
        //   io.writeLine('');
        // }
        // io.writeLine('');
        printStep(target, 2);
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    writeArray(arr) {
        arr.forEach((a) => {
            this.write(a);
        });
        this.writeLine('');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
function make2dArray(a, b, fill) {
    return Array.from({ length: a }).map(() => Array.from({ length: b }).map(() => fill));
}
//////////// LIBS
const io = new IO();
function solve() { }
function main() {
    try {
        let n = io.nextNum();
        let m = io.nextNum();
        let k = io.nextNum();
        let rightCost = [];
        let downCost = [];
        for (let i = 0; i < n; i++) {
            rightCost.push([]);
            for (let j = 0; j < m - 1; j++) {
                rightCost[i][j] = io.nextNum();
            }
        }
        for (let i = 0; i < n - 1; i++) {
            downCost.push([]);
            for (let j = 0; j < m; j++) {
                downCost[i][j] = io.nextNum();
            }
        }
        if (k % 2 === 1) {
            let arr = Array.from({ length: m }).fill(-1);
            for (let i = 0; i < n; i++) {
                io.writeArray(arr);
            }
            io.flush();
            return;
        }
        let dp = [];
        const printStep = (step) => {
            for (let i = 0; i < n; i++) {
                for (let j = 0; j < m; j++) {
                    io.write(dp[i][j][step]);
                }
                io.writeLine('');
            }
            io.writeLine('');
        };
        const getXCost = (i, j) => {
            if (!rightCost[i]) {
                return Infinity;
            }
            return rightCost[i][j] || Infinity;
        };
        const getYCost = (i, j) => {
            if (!downCost[i]) {
                return Infinity;
            }
            return downCost[i][j] || Infinity;
        };
        // console.log({ rightCost, downCost });
        for (let i = 0; i < n; i++) {
            dp[i] = [];
            for (let j = 0; j < m; j++) {
                dp[i][j] = [];
                dp[i][j][1] = Math.min(getXCost(i, j), getXCost(i, j - 1), getYCost(i, j), getYCost(i - 1, j));
                // console.log({
                //   i,
                //   j,
                //   right: getXCost(i, j),
                //   left: getXCost(i - 1, j),
                //   down: getYCost(i, j),
                //   up: getYCost(i, j - 1),
                //   min: dp[i][j][1],
                // });
            }
        }
        const getDp = (i, j, l) => {
            if (!dp[i]) {
                return Infinity;
            }
            if (!dp[i][j]) {
                return Infinity;
            }
            return dp[i][j][l];
        };
        // printStep(1);
        let target = k / 2;
        // console.log(dp);
        for (let l = 2; l <= target; l++) {
            for (let i = 0; i < n; i++) {
                for (let j = 0; j < m; j++) {
                    dp[i][j][l] = Math.min(getDp(i, j - 1, l - 1) + getXCost(i, j - 1), getDp(i, j + 1, l - 1) + getXCost(i, j), getDp(i - 1, j, l - 1) + getYCost(i - 1, j), getDp(i + 1, j, l - 1) + getYCost(i, j));
                }
            }
        }
        // for (let j = 0; j < m; j++) {
        //   for (let i = 0; i < n; i++) {
        //     io.write(dp[i][j][2]);
        //   }
        //   io.writeLine('');
        // }
        // io.writeLine('');
        printStep(target);
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = __importDefault(require("fs"));
//////////// LIBS
class IO {
    constructor() {
        this.i = 0;
        this.out = '';
        this.text = require('fs').readFileSync(0, 'utf8');
    }
    nextToken() {
        let ret = '';
        while (this.text[this.i].charCodeAt(0) <= 32) {
            this.i++;
        }
        while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
            ret += this.text[this.i];
            this.i++;
        }
        return ret;
    }
    nextNum() {
        return Number(this.nextToken());
    }
    nextNumArray(n) {
        let ret = [];
        while (n--) {
            ret.push(this.nextNum());
        }
        return ret;
    }
    _write(x) {
        this.out += x;
    }
    write(x) {
        this._write(x + ' ');
    }
    writeLine(x) {
        this._write(x + '\n');
    }
    writeArray(arr) {
        arr.forEach((a) => {
            this.write(a);
        });
        this.writeLine('');
    }
    flush() {
        fs_1.default.writeFileSync(1, this.out);
        this.out = '';
    }
}
function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        }
        else {
            lo = mi;
        }
    }
    return hi;
}
function lowerBound(array, item) {
    return binarySearch(array, (j) => item <= j);
}
function upperBound(array, item) {
    return binarySearch(array, (j) => item < j);
}
function make2dArray(a, b, fill) {
    return Array.from({ length: a }).map(() => Array.from({ length: b }).map(() => fill));
}
//////////// LIBS
const io = new IO();
function solve() { }
function main() {
    try {
        let n = io.nextNum();
        let m = io.nextNum();
        let k = io.nextNum();
        let rightCost = make2dArray(n - 1, m, 0);
        let downCost = make2dArray(n, m - 1, 0);
        for (let i = 0; i < n - 1; i++) {
            for (let j = 0; j < m; j++) {
                rightCost[i][j] = io.nextNum();
            }
        }
        for (let i = 0; i < n; i++) {
            for (let j = 0; j < m - 1; j++) {
                downCost[i][j] = io.nextNum();
            }
        }
        if (k % 2 === 1) {
            let arr = Array.from({ length: m }).fill(-1);
            for (let i = 0; i < n; i++) {
                io.writeArray(arr);
            }
            io.flush();
            return;
        }
        let dp = [];
        const getXCost = (i, j) => {
            if (i < 0 || j < 0 || i >= n - 1 || j >= m) {
                return Infinity;
            }
            return rightCost[i][j];
        };
        const getYCost = (i, j) => {
            if (i < 0 || j < 0 || i >= n || j >= m - 1) {
                return Infinity;
            }
            return downCost[i][j] || Infinity;
        };
        // console.log({ rightCost, downCost });
        for (let i = 0; i < n; i++) {
            dp[i] = [];
            for (let j = 0; j < m; j++) {
                dp[i][j] = [];
                dp[i][j][1] = Math.min(getXCost(i, j), getXCost(i - 1, j), getYCost(i, j), getYCost(i, j - 1));
                // console.log({
                //   i,
                //   j,
                //   right: getXCost(i, j),
                //   left: getXCost(i - 1, j),
                //   down: getYCost(i, j),
                //   up: getYCost(i, j - 1),
                //   min: dp[i][j][1],
                // });
            }
        }
        const getDp = (i, j, l) => {
            if (!dp[i]) {
                return Infinity;
            }
            if (!dp[i][j]) {
                return Infinity;
            }
            return dp[i][j][l];
        };
        let target = k / 2;
        // console.log(dp);
        for (let l = 2; l <= target; l++) {
            for (let i = 0; i < n; i++) {
                for (let j = 0; j < m; j++) {
                    dp[i][j][l] = Math.min(getDp(i - 1, j, l - 1) + getXCost(i - 1, j), getDp(i + 1, j, l - 1) + getXCost(i, j), getDp(i, j - 1, l - 1) + getYCost(i, j - 1), getDp(i, j + 1, l - 1) + getYCost(i, j));
                }
            }
        }
        // for (let j = 0; j < m; j++) {
        //   for (let i = 0; i < n; i++) {
        //     io.write(dp[i][j][2]);
        //   }
        //   io.writeLine('');
        // }
        // io.writeLine('');
        for (let j = 0; j < m; j++) {
            for (let i = 0; i < n; i++) {
                io.write(dp[i][j][target] * 2);
            }
            io.writeLine('');
        }
        io.flush();
    }
    catch (e) {
        console.log(e.stack);
    }
}
main();


A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.The town where Laurenty lives in is not large. The houses in it are located in two rows, n houses in each row. Laurenty lives in the very last house of the second row. The only shop in town is placed in the first house of the first row.The first and second rows are separated with the main avenue of the city. The adjacent houses of one row are separated by streets.Each crosswalk of a street or an avenue has some traffic lights. In order to cross the street, you need to press a button on the traffic light, wait for a while for the green light and cross the street. Different traffic lights can have different waiting time.The traffic light on the crosswalk from the j-th house of the i-th row to the (j + 1)-th house of the same row has waiting time equal to aij (1 ≤ i ≤ 2, 1 ≤ j ≤ n - 1). For the traffic light on the crossing from the j-th house of one row to the j-th house of another row the waiting time equals bj (1 ≤ j ≤ n). The city doesn't have any other crossings.The boy wants to get to the store, buy the products and go back. The main avenue of the city is wide enough, so the boy wants to cross it exactly once on the way to the store and exactly once on the way back home. The boy would get bored if he had to walk the same way again, so he wants the way home to be different from the way to the store in at least one crossing.    Figure to the first sample. Help Laurenty determine the minimum total time he needs to wait at the crossroads.

The first line of the input contains integer n (2 ≤ n ≤ 50) — the number of houses in each row.  Each of the next two lines contains n - 1 space-separated integer — values aij (1 ≤ aij ≤ 100).  The last line contains n space-separated integers bj (1 ≤ bj ≤ 100).

Print a single integer — the least total time Laurenty needs to wait at the crossroads, given that he crosses the avenue only once both on his way to the store and on his way back home.

NoteThe first sample is shown on the figure above. In the second sample, Laurenty's path can look as follows:   Laurenty crosses the avenue, the waiting time is 3;  Laurenty uses the second crossing in the first row, the waiting time is 2;  Laurenty uses the first crossing in the first row, the waiting time is 1;  Laurenty uses the first crossing in the first row, the waiting time is 1;  Laurenty crosses the avenue, the waiting time is 1;  Laurenty uses the second crossing in the second row, the waiting time is 3.  In total we get that the answer equals 11.In the last sample Laurenty visits all the crossings, so the answer is 4.

n = +readline();
a = [];
a[0] = readline().split(" ").map(Number);
a[1] = readline().split(" ").map(Number);
b = readline().split(" ").map(Number);

sum1 = [];
sum1[0] = 0;
for (var i = 1; i < n; i++) {
	sum1[i] = sum1[i-1] + a[0][i-1];
}

sum2 = [];
sum2[n-1] = 0;
for (var i = n-1; i >= 1; --i) {
	sum2[i-1] = sum2[i] + a[1][i-1];
}

path = [];
for (var i = 0; i < n; i++) {
	// leave only i bridge
	path[i] = b[i] + sum1[i] + sum2[i];
}
path.sort( function(a,b) {return a-b;});
write(path[0] + path[1]);

n = +readline();

a0 = readline().split(" ").map(Number);
a0_ = [0];
for (var i = 0; i < a0.length; i++) {
	a0_.push( a0_[i] + a0[i] );
}

a1 = readline().split(" ").map(Number);
a1_ = []; a1_[n-1] = 0;
for (var i = n-2; i >= 0; --i) {
	a1_[i] = a1_[i+1] + a1[i];
}

b = readline().split(" ").map(Number);
d = [];
for (var i = 0; i < b.length; i++) {
	d.push( b[i] + a0_[i] + a1_[i] );
}

d.sort();

write(d);

n = +readline();
a = [];
a[0] = readline().split(" ").map(Number);
a[1] = readline().split(" ").map(Number);
b = readline().split(" ").map(Number);

sum1 = [];
sum1[0] = 0;
for (var i = 1; i < n; i++) {
	sum1[i] = sum1[i-1] + a[0][i-1];
}

sum2 = [];
sum2[n-1] = 0;
for (var i = n-1; i>= 1; --i) {
	sum2[i-1] = sum2[i] + a[1][i-1];
}

path = [];
for (var i = 0; i < n; i++) {
	// leave only i bridge
	path[i] = b[i] + sum1[i] + sum2[i];
}

path.sort();

write(path[0] + path[1]);


Petya is preparing for his birthday. He decided that there would be $$$n$$$ different dishes on the dinner table, numbered from $$$1$$$ to $$$n$$$. Since Petya doesn't like to cook, he wants to order these dishes in restaurants.Unfortunately, all dishes are prepared in different restaurants and therefore Petya needs to pick up his orders from $$$n$$$ different places. To speed up this process, he wants to order courier delivery at some restaurants. Thus, for each dish, there are two options for Petya how he can get it:  the dish will be delivered by a courier from the restaurant $$$i$$$, in this case the courier will arrive in $$$a_i$$$ minutes,  Petya goes to the restaurant $$$i$$$ on his own and picks up the dish, he will spend $$$b_i$$$ minutes on this. Each restaurant has its own couriers and they start delivering the order at the moment Petya leaves the house. In other words, all couriers work in parallel. Petya must visit all restaurants in which he has not chosen delivery, he does this consistently.For example, if Petya wants to order $$$n = 4$$$ dishes and $$$a = [3, 7, 4, 5]$$$, and $$$b = [2, 1, 2, 4]$$$, then he can order delivery from the first and the fourth restaurant, and go to the second and third on your own. Then the courier of the first restaurant will bring the order in $$$3$$$ minutes, the courier of the fourth restaurant will bring the order in $$$5$$$ minutes, and Petya will pick up the remaining dishes in $$$1 + 2 = 3$$$ minutes. Thus, in $$$5$$$ minutes all the dishes will be at Petya's house.Find the minimum time after which all the dishes can be at Petya's home.

The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case begins with a line containing one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of dishes that Petya wants to order. The second line of each test case contains $$$n$$$ integers $$$a_1 \ldots a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the time of courier delivery of the dish with the number $$$i$$$. The third line of each test case contains $$$n$$$ integers $$$b_1 \ldots b_n$$$ ($$$1 \le b_i \le 10^9$$$) — the time during which Petya will pick up the dish with the number $$$i$$$. The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case output one integer — the minimum time after which all dishes can be at Petya's home.

function C1443(a1, b1) {
  var n = a1.length;
  var c = [];

  for (var i = 0; i < n; i++) {
    c.push([a1[i], b1[i]]);
  }

  c.sort(function (p, q) {
    return p[0] - q[0];
  });

  for (var _i = n - 2; _i >= 0; _i--) {
    c[_i][1] += c[_i + 1][1];
  }

  var ans = Math.min(c[n - 1][0], c[0][1]);

  for (var _i2 = n - 2; _i2 >= 0; _i2--) {
    ans = Math.min(ans, Math.max(c[_i2][0], c[_i2 + 1][1]));
  }

  return ans;
}

function execute(readline, print) {
  var iter = {
    next: function next() {
      return readline().trim();
    }
  };

  var split = function split(string) {
    return string.split(' ').map(Number);
  };

  var t = Number(iter.next());

  while (t--) {
    iter.next();
    var arr1 = split(iter.next());
    var arr2 = split(iter.next());
    print(C1443(arr1, arr2));
  }
}

execute(readline, print)

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const other = readLine().split(" ").map(Number);
    const own = readLine().split(" ").map(Number);
    const data = [];
    for (let i = 0; i < len; i++) {
      data.push([other[i], own[i]]);
    }
    data.sort((a, b) => b[0] - a[0]);
    let [ownTime, otherTime] = [0, 0];

    for (let i = 0; i < len; i++) {
      let [r, p] = data[i];
      if (ownTime + p < r) ownTime += p;
      else {
        otherTime = r;
        break;
      }
    }
    console.log(Math.max(ownTime, otherTime));
  }
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let s=0;s<t;++s){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const s=n(r(747));let o="",i=[],u=0,l="";const a="local"===process.argv[2],p=t=>{if(a){if(i=s.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),s.default.writeFileSync("output.txt",l),console.log(l),s.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{i=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function h(){return i[u++]}function f(){return h().split(" ").map((t=>parseFloat(t)))}function c(){return h().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(f());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=f();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){a&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const s=n(r(312));s.default.runEachTest((function(){let[t]=s.default.nextNumbers(),e=s.default.nextNumbersMatrix(2).transpose(),[r,n]=e.sort(((t,e)=>e[0]-t[0])).transpose(),o=0,i=r[0];for(let e=0;e<t&&o+n[e]<r[e];++e)o+=n[e],i=[o,r[e+1]||0].max();s.default.puts(i)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,r),s.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//
//   let x = io.nextNumbersMatrix(2).transpose()
//
//   let [a, b] = x.sort((a, b) => b[0] - a[0]).transpose()
//
//   let s = 0
//   let best = a[0]
//
//   // io.debug(a)
//   // io.debug(b)
//
//   for (let i = 0; i < n; ++i) {
//     if (s + b[i] < a[i]) {
//       s += b[i]
//       best = [s, a[i + 1] || 0].max()
//     } else {
//       break
//     }
//   }
//
//   io.puts(best)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let s=0;s<t;++s){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const s=n(r(747));let o="",i=[],u=0,l="";const a="local"===process.argv[2],p=t=>{if(a){if(i=s.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),s.default.writeFileSync("output.txt",l),console.log(l),s.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{i=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function h(){return i[u++]}function f(){return h().split(" ").map((t=>parseFloat(t)))}function c(){return h().split("")}e.default={runMain:p,runEachTest:t=>{p((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:h,nextNumbers:f,nextBigNumbers:function(){return h().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(f());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=f();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){a&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const s=n(r(312));s.default.runEachTest((function(){let[t]=s.default.nextNumbers(),e=s.default.nextNumbersMatrix(2).transpose(),[r,n]=e.sort(((t,e)=>e[0]-t[0])).transpose(),o=0,i=r[0];for(let e=0;e<t&&o+n[e]<r[e];++e)o+=n[e],i=Math.max(o,r[e+1]||0);s.default.puts(i)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var s=e[n]={exports:{}};return t[n].call(s.exports,s,s.exports,r),s.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let [n] = io.nextNumbers()
//
//   let x = io.nextNumbersMatrix(2).transpose()
//
//   let [a, b] = x.sort((a, b) => b[0] - a[0]).transpose()
//
//   let s = 0
//   let best = a[0]
//
//   // io.debug(a)
//   // io.debug(b)
//
//   for (let i = 0; i < n; ++i) {
//     if (s + b[i] < a[i]) {
//       s += b[i]
//       best = Math.max(s, a[i + 1] || 0)
//     } else {
//       break
//     }
//   }
//
//   io.puts(best)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

let input = ''

process.stdin.on('data', (x) => input += x)

process.stdin.on('end', () => {
  const lines = input.trim().split('\n')
  let curLine = 0
  const T = parseInt(lines[curLine++])
  for (let t = 0; t < T; t++) {
    const n = parseInt(lines[curLine++])
    const a = parseIntArray(lines[curLine++])
    const b = parseIntArray(lines[curLine++])
    const restaurant = [...new Array(n)]
      .map((_, idx) => [a[idx], b[idx]])
      .sort(([xa, xb], [ya, yb]) => {
        if (xa !== ya) {
          if (xa < ya) return -1
          if (xa > ya) return 1
          return 0
        }
        if (xb < yb) return -1
        if (xb > yb) return 1
        return 0
      })

    let accSum = b.reduce((x, y) => x + y, 0n)
    let ans = accSum

    restaurant.forEach(([ra, rb]) => {
      accSum -= rb
      const cand = ra > accSum ? ra : accSum
      ans = ans < cand ? ans: cand
    })

    console.log(ans.toString())
  }
})

const parseIntArray = (line) => line.split(' ').map((x) => BigInt(x))

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

    C();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let x = n;
        let res = [4*n];
        let num = 4*n;
        n -= 1;
        let i = 3;
        let f = 2;
        while(n > 0){
                num -= 2;
                let flag = false;
                for(let j = res.length-1; j >= 0; j--){
                    if(res[j] % num === 0){
                        flag = true;
                        break;
                    }
                }
                if(!flag){
                    res.push(num);
                    n--;
                }
        }

        console.log(res.join(' '));
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [a,b] = ti(readline().split(' '));
        let s = readline().split('');
        //console.log(s.length);
        let x = [];
        let i = 0;
        while(i < s.length && s[i] !== '1'){
            i++;
        }

        while(i < s.length){
            if(s[i] === '1')
                x.push(a);
            while(i < s.length && s[i] === '1'){
                i++;
            }

            if(i < s.length && s[i] === '0'){
                x.push(s[i]);
            }
            i++;
        }

        i = 0;
        let sum = x.length !== 0 ? a : 0;
        while(i < x.length){
            if(pi(x[i]) === a){
                let count = 0;
                i++;
                while(i < x.length && pi(x[i]) === 0){
                    count += b;
                    i++;
                }

                if(i < x.length){
                    sum = Math.min(sum+a, sum+count);
                }
            }
        }

        console.log(sum);
    }
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        let b = ti(readline().split(' '));
        let pair = new Array(n);
        for(let i = 0; i < n; i++){
            pair[i] = [a[i],b[i]];
        }
        pair.sort((a,b) => a[0]-b[0]);
        let x = new Array(n);
        for(let i = n-1; i >= 0; i--){
            if(i === n-1){
                x[i] = pair[i][1];
            }else{
                x[i] = x[i+1] + pair[i][1];
            }
        }

        let min = 9999999999999;
        for(let i = 0; i < n-1; i++){
            min = Math.min(min, Math.max(pair[i][0], x[i+1]));
        }

        console.log(Math.min(min, pair[n-1][0], x[0]));
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const other = readLine().split(" ").map(Number);
    const own = readLine().split(" ").map(Number);
    let [ownTime, otherTime] = [0, 0];

    for (let i = 0; i < len; i++) {
      let [r, p] = [other[i], own[i]];
      if (ownTime + p < Math.max(otherTime, r)) {
        ownTime += p;
      } else {
        otherTime = r;
      }
    }
    console.log(Math.max(ownTime, otherTime));
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const other = readLine().split(" ").map(Number);
    const own = readLine().split(" ").map(Number);
    let [ownTime, otherTime] = [0, 0];

    for (let i = 0; i < len; i++) {
      let [r, p] = [other[i], own[i]];
      if (ownTime + p < Math.max(otherTime, r)) {
        ownTime += p;
      } else {
        otherTime = Math.max(otherTime, r);
      }
    }
    console.log(Math.max(ownTime, otherTime));
  }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (a, b) => mod(mod(a) + mod(b));
const sub = (a, b) => mod(mod(a) - mod(b));
function mul() {
  for (var a = arguments, r = a[0], i = a.length; --i; )
    r = ((((r >> 16) * a[i]) % MOD) * 65536 + (r & 65535) * a[i]) % MOD;
  return r;
}
function inv(b) {
  for (var a = MOD, u = 0, v = 1, t; b; v = t)
    (t = (a / b) | 0), (a -= t * b), (u -= t * v), (t = a), (a = b), (b = t), (t = u), (u = v);
  u %= MOD;
  return u < 0 ? u + MOD : u;
}
function pow(base, n) {
  if (n === 0) return 1;
  let p = pow(base, Math.floor(n / 2));
  let res = mul(mod(p), mod(p));
  if (n % 2 === 1) res = mul(mod(res), base);
  return res;
}
function highestOneBit(i) {
  i |= i >> 1;
  i |= i >> 2;
  i |= i >> 4;
  i |= i >> 8;
  i |= i >> 16;
  return i - (i >>> 1);
}
function permutation(arr, len, store = "", permutations = []) {
  if (store.length === len) {
    permutations.push(store);
    return;
  }
  for (let i = 0; i < arr.length; i++) {
    const newArr = [...arr];
    const newChar = newArr.splice(i, 1);
    permutation(newArr, len, store.concat(newChar), permutations);
  }
  return permutations;
}

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const other = readLine().split(" ").map(Number);
    const own = readLine().split(" ").map(Number);
    let [ownTime, otherTime] = [0, 0];

    for (let i = 0; i < len; i++) {
      let [r, p] = [other[i], own[i]];
      if (ownTime + p < Math.max(otherTime, r)) {
        ownTime += p;
      } else {
        otherTime = r;
      }
    }
    const res = Math.max(ownTime, otherTime);
    let ownCount = 0;
    for (let i = 0; i < len; i++) {
      ownCount += own[i];
    }

    console.log(Math.min(res, ownCount, Math.max(...other)));
  }
}

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

    C();
});

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

function pi(a) {
    return parseInt(a);
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let x = n;
        let res = [4*n];
        let num = 4*n;
        n -= 1;
        let i = 3;
        let f = 2;
        while(n > 0){
                num -= 2;
                let flag = false;
                for(let j = res.length-1; j >= 0; j--){
                    if(res[j] % num === 0){
                        flag = true;
                        break;
                    }
                }
                if(!flag){
                    res.push(num);
                    n--;
                }
        }

        console.log(res.join(' '));
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [a,b] = ti(readline().split(' '));
        let s = readline().split('');
        //console.log(s.length);
        let x = [];
        let i = 0;
        while(i < s.length && s[i] !== '1'){
            i++;
        }

        while(i < s.length){
            if(s[i] === '1')
                x.push(a);
            while(i < s.length && s[i] === '1'){
                i++;
            }

            if(i < s.length && s[i] === '0'){
                x.push(s[i]);
            }
            i++;
        }

        i = 0;
        let sum = x.length !== 0 ? a : 0;
        while(i < x.length){
            if(pi(x[i]) === a){
                let count = 0;
                i++;
                while(i < x.length && pi(x[i]) === 0){
                    count += b;
                    i++;
                }

                if(i < x.length){
                    sum = Math.min(sum+a, sum+count);
                }
            }
        }

        console.log(sum);
    }
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        let b = ti(readline().split(' '));
        a.sort((a,b) => a-b);
        for(let i = n-2; i >= 0; i--)
            b[i] += b[i+1];

        let min = 9999999999999;
        for(let i = 0; i < n-1; i++){
            min = Math.min(min, Math.max(a[i], b[i+1]));
        }

        console.log(Math.min(min, a[n-1], b[0]));
    }
}