A permutation is a sequence of integers from $$$1$$$ to $$$n$$$ of length $$$n$$$ containing each number exactly once. For example, $$$[1]$$$, $$$[4, 3, 5, 1, 2]$$$, $$$[3, 2, 1]$$$ — are permutations, and $$$[1, 1]$$$, $$$[4, 3, 1]$$$, $$$[2, 3, 4]$$$ — no.Permutation $$$a$$$ is lexicographically smaller than permutation $$$b$$$ (they have the same length $$$n$$$), if in the first index $$$i$$$ in which they differ, $$$a[i] < b[i]$$$. For example, the permutation $$$[1, 3, 2, 4]$$$ is lexicographically smaller than the permutation $$$[1, 3, 4, 2]$$$, because the first two elements are equal, and the third element in the first permutation is smaller than in the second.The next permutation for a permutation $$$a$$$ of length $$$n$$$ — is the lexicographically smallest permutation $$$b$$$ of length $$$n$$$ that lexicographically larger than $$$a$$$. For example:   for permutation $$$[2, 1, 4, 3]$$$ the next permutation is $$$[2, 3, 1, 4]$$$;  for permutation $$$[1, 2, 3]$$$ the next permutation is $$$[1, 3, 2]$$$;  for permutation $$$[2, 1]$$$ next permutation does not exist. You are given the number $$$n$$$ — the length of the initial permutation. The initial permutation has the form $$$a = [1, 2, \ldots, n]$$$. In other words, $$$a[i] = i$$$ ($$$1 \le i \le n$$$).You need to process $$$q$$$ queries of two types:   $$$1$$$ $$$l$$$ $$$r$$$: query for the sum of all elements on the segment $$$[l, r]$$$. More formally, you need to find $$$a[l] + a[l + 1] + \ldots + a[r]$$$.  $$$2$$$ $$$x$$$: $$$x$$$ times replace the current permutation with the next permutation. For example, if $$$x=2$$$ and the current permutation has the form $$$[1, 3, 4, 2]$$$, then we should perform such a chain of replacements $$$[1, 3, 4, 2] \rightarrow [1, 4, 2, 3] \rightarrow [1, 4, 3, 2]$$$. For each query of the $$$1$$$-st type output the required sum.

The first line contains two integers $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) and $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$), where $$$n$$$ — the length of the initial permutation, and $$$q$$$ — the number of queries. The next $$$q$$$ lines contain a single query of the $$$1$$$-st or $$$2$$$-nd type. The $$$1$$$-st type query consists of three integers $$$1$$$, $$$l$$$ and $$$r$$$ $$$(1 \le l \le r \le n)$$$, the $$$2$$$-nd type query consists of two integers $$$2$$$ and $$$x$$$ $$$(1 \le x \le 10^5)$$$. It is guaranteed that all requests of the $$$2$$$-nd type are possible to process.

For each query of the $$$1$$$-st type, output on a separate line one integer — the required sum.

let input = ''

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

process.stdin.on('end', () => {
  const lines = input.trim().split('\n')
  let curLine = 0
  const [n, q] = parseIntArray(lines[curLine++])
  const v = [...new Array(n + 1)].map((_, idx) => idx)
  const acc = [0]
  v.slice(1).forEach((x) => acc.push(acc[acc.length - 1] + x))

  const suffixIdx = Math.max(1, n - 15)

  for (let i = 0; i < q; i++) {
    const [op, l, r] = parseIntArray(lines[curLine++])
    if (op === 1) {
      console.log(acc[r] - acc[l - 1])
    } else {
      const newSuffix = findNextPermutation(v.slice(suffixIdx), l)
      for (let j = suffixIdx; j <= n; j++) {
        v[j] = newSuffix[j - suffixIdx]
        acc[j] = acc[j - 1] + v[j]
      }
    }
  }
})

const factorial = [1]
for (let i = 1; i < 20; i++) {
  factorial.push(i * factorial[i - 1])
}

const findNextPermutation = (arr, k) => {
  const permIdx = getPermutationIdx(arr)
  return genPermutation([...arr].sort((a, b) => a - b), permIdx + k)
}

const getPermutationIdx = (arr) => {
  let permIdx = 0
  arr.forEach((x, idx) => {
    const count = arr.slice(idx + 1).reduce((a, b) => a + (b < x ? 1 : 0), 0)
    permIdx += count * factorial[arr.length - idx - 1]
  })
  return permIdx
}

const genPermutation = (arr, k) => {
  const rem = [...arr]
  const perm = []
  for (let i = 0; i < arr.length; i++) {
    const q = Math.floor(k / factorial[arr.length - i - 1])
    k -= q * factorial[arr.length - i - 1]
    perm.push(...rem.splice(q, 1))
  }
  return perm
}

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

let input = ''

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

process.stdin.on('end', () => {
  const lines = input.trim().split('\n')
  let curLine = 0
  const [n, q] = parseIntArray(lines[curLine++])
  const v = [...new Array(n + 1)].map((_, idx) => idx)
  const acc = [0]
  v.slice(1).forEach((x) => acc.push(acc[acc.length - 1] + x))

  const suffixIdx = Math.max(1, n - 15)

  for (let i = 0; i < q; i++) {
    const [op, l, r] = parseIntArray(lines[curLine++])
    if (op === 1) {
      console.log(acc[r] - acc[l - 1])
    } else {
      const newSuffix = findNextPermutation(v.slice(suffixIdx), l)
      for (let j = suffixIdx; j < n; j++) {
        v[j] = newSuffix[j - suffixIdx]
        acc[j] = acc[j - 1] + v[j]
      }
    }
  }
})

const factorial = [1]
for (let i = 1; i < 20; i++) {
  factorial.push(i * factorial[i - 1])
}

const findNextPermutation = (arr, k) => {
  const permIdx = getPermutationIdx(arr)
  return genPermutation([...arr].sort((a, b) => a - b), permIdx + k)
}

const getPermutationIdx = (arr) => {
  let permIdx = 0
  arr.forEach((x, idx) => {
    const count = arr.slice(idx + 1).reduce((a, b) => a + (b < x ? 1 : 0), 0)
    permIdx += count * factorial[arr.length - idx - 1]
  })
  return permIdx
}

const genPermutation = (arr, k) => {
  const rem = [...arr]
  const perm = []
  for (let i = 0; i < arr.length; i++) {
    const q = Math.floor(k / factorial[arr.length - i - 1])
    k -= q * factorial[arr.length - i - 1]
    perm.push(...rem.splice(q, 1))
  }
  return perm
}

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


The integers shop sells $$$n$$$ segments. The $$$i$$$-th of them contains all integers from $$$l_i$$$ to $$$r_i$$$ and costs $$$c_i$$$ coins.Tomorrow Vasya will go to this shop and will buy some segments there. He will get all integers that appear in at least one of bought segments. The total cost of the purchase is the sum of costs of all segments in it.After shopping, Vasya will get some more integers as a gift. He will get integer $$$x$$$ as a gift if and only if all of the following conditions are satisfied:   Vasya hasn't bought $$$x$$$.  Vasya has bought integer $$$l$$$ that is less than $$$x$$$.  Vasya has bought integer $$$r$$$ that is greater than $$$x$$$. Vasya can get integer $$$x$$$ as a gift only once so he won't have the same integers after receiving a gift.For example, if Vasya buys segment $$$[2, 4]$$$ for $$$20$$$ coins and segment $$$[7, 8]$$$ for $$$22$$$ coins, he spends $$$42$$$ coins and receives integers $$$2, 3, 4, 7, 8$$$ from these segments. He also gets integers $$$5$$$ and $$$6$$$ as a gift.Due to the technical issues only the first $$$s$$$ segments (that is, segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_s, r_s]$$$) will be available tomorrow in the shop.Vasya wants to get (to buy or to get as a gift) as many integers as possible. If he can do this in differents ways, he selects the cheapest of them.For each $$$s$$$ from $$$1$$$ to $$$n$$$, find how many coins will Vasya spend if only the first $$$s$$$ segments will be available.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of segments in the shop. Each of next $$$n$$$ lines contains three integers $$$l_i$$$, $$$r_i$$$, $$$c_i$$$ ($$$1 \leq l_i \leq r_i \leq 10^9, 1 \leq c_i \leq 10^9$$$) — the ends of the $$$i$$$-th segments and its cost. It is guaranteed that the total sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case output $$$n$$$ integers: the $$$s$$$-th ($$$1 \leq s \leq n$$$) of them should be the number of coins Vasia will spend in the shop if only the first $$$s$$$ segments will be available.

NoteIn the first test case if $$$s = 1$$$ then Vasya can buy only the segment $$$[2, 4]$$$ for $$$20$$$ coins and get $$$3$$$ integers.The way to get $$$7$$$ integers for $$$42$$$ coins in case $$$s = 2$$$ is described in the statement.In the second test case note, that there can be the same segments in the shop.

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

const INF = 1e9 + 1e9 + 100;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		let la = INF, ra = -INF, lrc = INF;
		let lb = INF, rb = -INF, lc = INF, rc = INF;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l <= la && r >= ra) {
				if (l < la || r > ra) {
					la = l;
					ra = r;
					lrc = c;
				} else {
					lrc = Math.min(lrc, c);
				}
			}

			if (l <= lb) {
				if (l < lb) {
					lb = l;
					lc = c;
				} else {
					lc = Math.min(lc, c);
				}
			}

			if (r >= rb) {
				if (r > rb) {
					rb = r;
					rc = c;
				} else {
					rc = Math.min(rc, c);
				}
			}

			console.log(Math.min(lc + rc, la == lb && ra == rb ? lrc : INF));
		}
	}
}

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

const INF = 1e18;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		let la = INF, ra = -INF, lrc = INF;
		let lb = INF, rb = -INF, lc = INF, rc = INF;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l <= la && r >= ra) {
				if (l < la || r > ra) {
					la = l;
					ra = r;
					lrc = c;
				} else {
					lrc = Math.min(lrc, c);
				}
			}

			if (l <= lb) {
				if (l < lb) {
					lb = l;
					lc = c;
				} else {
					lc = Math.min(lc, c);
				}
			}

			if (r >= rb) {
				if (r > rb) {
					rb = r;
					rc = c;
				} else {
					rc = Math.min(rc, c);
				}
			}

			console.log(Math.min(lc + rc, la == lb && ra == rb ? lrc : INF));
		}
	}
}

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

const INF = 1e18;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		let la = INF, ra = -INF, lrc = INF;
		let l = INF, r = -INF, lc = INF, rc = INF;
		for (let i = 0; i < n; i++) {
			const [li, ri, ci] = rna();

			if (li <= la && ri >= ra) {
				if (li < la || ri > ra) {
					la = li;
					ra = ri;
					lrc = ci;
				} else {
					lrc = Math.min(lrc, ci);
				}
			}

			if (li == l) {
				lc = Math.min(lc, ci);
			} else if (li < l) {
				l = li;
				lc = ci;
			}

			if (ri == r) {
				rc = Math.min(rc, ci);
			} else if (ri > r) {
				r = ri;
				rc = ci;
			}
			//console.log({la, ra, l, r, lrc, lc, rc})

			console.log(Math.min(lc + rc, la == l && ra == r ? lrc : INF));
		}
	}
}

'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] = ra();
  LT({n});
  let A = [];
  let cost = 0;
  let ans = [];
  let minLPrice = -1;
  let minL = -1;
  let minRPrice = -1;
  let maxR = -1;
  let fullPrice = -1;
  for (let i=0; i<n; i++){
    let [l, r, c] = ra();
    if (minL==-1 || l<minL || l==minL && c<minLPrice){
      if (l!=minL)
        fullPrice = -1;
      minL = l;
      minLPrice = c;
    }
    if (maxR==-1 || r>maxR || r==maxR && c<minRPrice){
      if (r!=maxR)
        fullPrice = -1;
      maxR = r;
      minRPrice = c;
    }
    if (l==minL && r==maxR){
      fullPrice = fullPrice==-1 ? c : Math.min(fullPrice, c);
    }
    if (fullPrice!=-1 && fullPrice<minLPrice+minRPrice)
      ans.push(fullPrice);
    else
      ans.push(minLPrice+minRPrice);
    //A.push({l, r, c});
  }
  return ans.join('\n')
};

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

function _main() {
  _inputLines = _inputData
    .trim()
    .split("\n")
    .map((string) => {
      return string.trim();
    });

  let t = inputReader.readNumber();

  function solve() {
    let n = inputReader.readNumber();
    let minL = Infinity,
      maxR = -Infinity,
      costL = Infinity,
      costR = Infinity,
      ans = Infinity;
    while (n--) {
      let [l, r, c] = inputReader.readNumberArray();
      if (l < minL) {
        minL = l;
        costL = c;
        ans = Infinity;
      }
      if (r > maxR) {
        maxR = r;
        costR = c;
        ans = Infinity;
      }
      if (l == minL && r == maxR) ans = Math.min(c, ans);
      if (l == minL && costL > c) costL = c;
      if (r == maxR && costR > c) costR = c;
      console.log(Math.min(ans, costL + costR));
    }
  }

  while (t--) {
    solve();
  }
}

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

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

const getLine = (function () {
    const getLineGen = (async function* () {
        for await (const line of rl) {
            yield line;
        }
    })();
    return async () => {
        let next;
        do {
            next = (await getLineGen.next());
        } while (!next.done && next.value === '');
        return next.value;
    };
})();

const readInt = async function(){
    return parseInt(await getLine());
}

const readIntArray = async function() {
    return (await getLine()).split(' ').map(num => parseInt(num));
}

let solve = async () => {
    const nsc = await readInt();
    for(let sc = 0; sc < nsc; sc++) {
        const n = await readInt();
        let [l,r,c] = await readIntArray();
        let lleft, lright, cl, rleft, rright, cr;
        let onel, oner, onec;
        onel = lleft = rleft = l;
        oner = lright = rright = r;
        onec = cl = cr = c;
        console.log(c);
        for(let i = 1; i < n; i++) {
           [l,r,c] = await readIntArray();
           if (l < lleft || (lleft === l && c < cl)) {
               lleft = l;
               lright = r;
               cl = c;
           }

            if (r > rright || (r === rright && c < cr)) {
                rleft = l;
                rright = r;
                cr = c;
            }

            if (l === lleft && r === rright) {
                if (l < onel || r > oner || (l === onel && r===oner && c < onec)) {
                    onel = l;
                    oner = r;
                    onec = c;
                }
            }

            if (lleft === onel && rright === oner && cr + cl > onec) {
                console.log(onec);
            } else {
                console.log(cr + cl);
            }
        }
    }
}

solve();

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

function solve(n, arr) {
    let min = Infinity
    let mincost
    let max = -Infinity
    let maxcost
    const map = {}
    return arr.map(([l, r, c], i) => {
        if (l < min) {
            min = l
            mincost = i
        } else if (l === min && c < arr[mincost][2]) {
            mincost = i
        }
        if (r > max) {
            max = r
            maxcost = i
        } else if (r === max && c < arr[maxcost][2]) {
            maxcost = i
        }
        //
        let k = key(l, r)
        map[k] = (k in map) ? Math.min(map[k], c) : c
        //
        let prev
        if (mincost === maxcost) {
            prev = arr[mincost][2]
        } else {
            prev = arr[mincost][2] + arr[maxcost][2]
        }
        //
        k = key(min, max)
        if (k in map) {
            return Math.min(map[k], prev)
        } else {
            return prev
        }
    }).join('\n')
}
function key(...args) {
    return args.join(',')
}

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

const INF = 1e9 + 100;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		let la = INF, ra = -INF, lrc = INF;
		let lb = INF, rb = -INF, lc = INF, rc = INF;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l <= la && r >= ra) {
				if (l < la || r > ra) {
					la = l;
					ra = r;
					lrc = c;
				} else {
					lrc = Math.min(lrc, c);
				}
			}

			if (l <= lb) {
				if (l < lb) {
					lb = l;
					lc = c;
				} else {
					lc = Math.min(lc, c);
				}
			}

			if (r >= rb) {
				if (r > rb) {
					rb = r;
					rc = c;
				} else {
					rc = Math.min(rc, c);
				}
			}

			console.log(Math.min(lc + rc, la == lb && ra == rb ? lrc : INF));
		}
	}
}

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

const INF = 1e18;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		let la = INF, ra = -INF, lrc = INF;
		let lb = INF, rb = -INF, lc = INF, rc = INF;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l <= la && r >= ra) {
				if (l < la || r > ra) {
					la = l;
					ra = r;
					lrc = c;
				} else {
					lrc = Math.min(lrc, c);
				}
			}

			if (l <= lb) {
				if (l < lb) {
					lb = l;
					lc = c;
				} else {
					lc = Math.min(lc, c);
				}
			}

			if (r >= r) {
				if (r > rb) {
					rb = r;
					rc = c;
				} else {
					rc = Math.min(rc, c);
				}
			}

			console.log(Math.min(lc + rc, la == lb && ra == rb ? lrc : INF));
		}
	}
}

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

const INF = 1e9;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		let la = INF, ra = -INF, lrc = INF;
		let l = INF, r = -INF, lc = INF, rc = INF;
		for (let i = 0; i < n; i++) {
			const [li, ri, ci] = rna();

			if (li <= la && ri >= ra) {
				if (li < la || ri > ra) {
					la = li;
					ra = ri;
					lrc = ci;
				} else {
					lrc = Math.min(lrc, ci);
				}
			}

			if (li == l) {
				lc = Math.min(lc, ci);
			} else if (li < l) {
				l = li;
				lc = ci;
			}

			if (ri == r) {
				rc = Math.min(rc, ci);
			} else if (ri > r) {
				r = ri;
				rc = ci;
			}
			//console.log({la, ra, l, r, lrc, lc, rc})

			console.log(Math.min(lc + rc, la == l && ra == r ? lrc : INF));
		}
	}
}

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

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

const INF = 1e18;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		const ans = [];
		let mn = INF, mnc, mx = 0, mxc;
		let oneseg, onel, oner, onec;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l < mn || l == mn && c < mnc) {
				mn = l;
				mnc = c;
			}

			if (r > mx || r == mx && c < mxc) {
				mx = r;
				mxc = c;
			}

			oneseg = onel == mn && oner == mx;

			if (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mnc + mxc)) {
				oneseg = true;
				onel = l;
				oner = r;
				onec = c;
			}

			console.log(oneseg ? onec : mnc + mxc);
		}
	}
}

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

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

const INF = 1e18;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		const ans = [];
		let mn = INF, mnc, mx = 0, mxc;
		let oneseg, onel, oner, onec;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l < mn || l == mn && c < mnc) {
				mn = l;
				mnc = c;
			}

			if (r > mx || r == mx && c < mxc) {
				mx = r;
				mxc = c;
			}

			if (onel > mn || oner < mx)
				oneseg = false;

			if (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mxc+mnc)) {
				oneseg = true;
				onel = l;
				oner = r;
				onec = c;
			}

			console.log(oneseg ? onec : mnc + mxc);
		}
	}
}

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

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

const INF = 1e18;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		const ans = [];
		let mn = INF, mnc, mx = 0, mxc;
		let oneseg, onel, oner, onec;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l < mn || l == mn && c < mnc) {
				mn = l;
				mnc = c;
			}

			if (r > mx || r == mx && c < mxc) {
				mx = r;
				mxc = c;
			}

			if (oner != mx || onel != mn)
				oneseg = false;

			if (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mxc+mnc)) {
				oneseg = true;
				onel = l;
				oner = r;
				onec = c;
			}

			console.log(oneseg ? onec : mnc + mxc);
		}
	}
}

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

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

const INF = 2e9+10;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		const ans = [];
		let mn = INF, mnc, mx = 0, mxc;
		let oneseg, onel, oner, onec;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l < mn || l == mn && c < mnc) {
				mn = l;
				mnc = c;
			}

			if (r > mx || r == mx && c < mxc) {
				mx = r;
				mxc = c;
			}

			if (oner != mx || onel != mn)
				oneseg = false;

			if (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mxc+mnc)) {
				oneseg = true;
				onel = l;
				oner = r;
				onec = c;
			}

			console.log(oneseg ? onec : mnc + mxc);
		}
	}
}

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

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

const INF = 1e9;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		const ans = [];
		let mn = INF, mnc, mx = 0, mxc;
		let oneseg, onel, oner, onec;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l < mn || l == mn && c < mnc) {
				mn = l;
				mnc = c;
			}

			if (r > mx || r == mx && c < mxc) {
				mx = r;
				mxc = c;
			}

			if (oner != mx || onel != mn)
				oneseg = false;

			if (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mxc+mnc)) {
				oneseg = true;
				onel = l;
				oner = r;
				onec = c;
			}

			console.log(oneseg ? onec : mnc + mxc);
		}
	}
}

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

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

const INF = 1e9;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		const ans = [];
		let mn = INF, mnc, mx = 0, mxc;
		let oneseg, onel, oner, onec;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l < mn || l == mn && c < mnc) {
				mn = l;
				mnc = c;
			}

			if (r > mx || r == mx && c < mxc) {
				mx = r;
				mxc = c;
			}

			if (l == mn && r == mx && c < Math.min(oneseg ? onec : INF, mxc+mnc)) {
				oneseg = true;
				onel = l;
				oner = r;
				onec = c;
			}

			if (oner != mx || onel != mn)
				oneseg = false;

			console.log(oneseg ? onec : mnc + mxc);
		}
	}
}

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

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

const INF = 1e9;

function main () {
	let T = rn();
	while (T--) {
		const n = rn();

		const ans = [];
		let mn = INF, mnc, mx = 0, mxc;
		let oneseg, onel, oner, onec;
		for (let i = 0; i < n; i++) {
			const [l, r, c] = rna();
			if (l < mn || l == mn && c < mnc) {
				mn = l;
				mnc = c;
			}

			if (r > mx || r == mx && c < mxc) {
				mx = r;
				mxc = c;
			}

			if (l == mn && r == mx && c < mxc+mnc) {
				oneseg = true;
				onel = l;
				oner = r;
				onec = c;
			}

			if (oner != mx || onel != mn)
				oneseg = false;

			console.log(oneseg ? onec : mnc + mxc);
		}
	}
}


Ashish has two strings $$$a$$$ and $$$b$$$, each of length $$$n$$$, and an integer $$$k$$$. The strings only contain lowercase English letters.He wants to convert string $$$a$$$ into string $$$b$$$ by performing some (possibly zero) operations on $$$a$$$.In one move, he can either   choose an index $$$i$$$ ($$$1 \leq i\leq n-1$$$) and swap $$$a_i$$$ and $$$a_{i+1}$$$, or  choose an index $$$i$$$ ($$$1 \leq i \leq n-k+1$$$) and if $$$a_i, a_{i+1}, \ldots, a_{i+k-1}$$$ are all equal to some character $$$c$$$ ($$$c \neq$$$ 'z'), replace each one with the next character $$$(c+1)$$$, that is, 'a' is replaced by 'b', 'b' is replaced by 'c' and so on. Note that he can perform any number of operations, and the operations can only be performed on string $$$a$$$. Help Ashish determine if it is possible to convert string $$$a$$$ into $$$b$$$ after performing some (possibly zero) operations on it.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$) — the number of test cases. The description of each test case is as follows. The first line of each test case contains two integers $$$n$$$ ($$$2 \leq n \leq 10^6$$$) and $$$k$$$ ($$$1 \leq k \leq n$$$). The second line of each test case contains the string $$$a$$$ of length $$$n$$$ consisting of lowercase English letters. The third line of each test case contains the string $$$b$$$ of length $$$n$$$ consisting of lowercase English letters. It is guaranteed that the sum of values $$$n$$$ among all test cases does not exceed $$$10^6$$$.

For each test case, print "Yes" if Ashish can convert $$$a$$$ into $$$b$$$ after some moves, else print "No". You may print the letters of the answer in any case (upper or lower).

4
3 3
abc
bcd
4 2
abba
azza
2 1
zz
aa
6 2
aaabba
ddddcc

NoteIn the first test case it can be shown that it is impossible to convert $$$a$$$ into $$$b$$$.In the second test case,"abba" $$$\xrightarrow{\text{inc}}$$$ "acca" $$$\xrightarrow{\text{inc}}$$$ $$$\ldots$$$ $$$\xrightarrow{\text{inc}}$$$ "azza".Here "swap" denotes an operation of the first type, and "inc" denotes an operation of the second type.In the fourth test case,"aaabba" $$$\xrightarrow{\text{swap}}$$$ "aaabab" $$$\xrightarrow{\text{swap}}$$$ "aaaabb" $$$\xrightarrow{\text{inc}}$$$ $$$\ldots$$$ $$$\xrightarrow{\text{inc}}$$$ "ddaabb" $$$\xrightarrow{\text{inc}}$$$ $$$\ldots$$$ $$$\xrightarrow{\text{inc}}$$$ "ddddbb" $$$\xrightarrow{\text{inc}}$$$ $$$\ldots$$$ $$$\xrightarrow{\text{inc}}$$$ "ddddcc".

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, k] = readLine().split(" ").map(Number);
    const s1 = readLine();
    const s2 = readLine();
    let flag = true;
    const [a1, a2] = [Array(26).fill(0), Array(26).fill(0)];
    for (let i = 0; i < len; i++) {
      const char1 = s1[i].charCodeAt(0) - 97;
      a1[char1]++;
    }
    for (let i = 0; i < len; i++) {
      const char2 = s2[i].charCodeAt(0) - 97;
      a2[char2]++;
    }

    for (let i = 0; i < 26; i++) {
      if (a1[i] < a2[i]) {
        console.log(`NO`);
        flag = false;
        break;
      }
      const extra = a1[i] - a2[i];
      if (extra % k !== 0) {
        console.log(`NO`);
        flag = false;
        break;
      } else {
        a1[i + 1] += extra;
      }
    }
    flag && console.log(`YES`);
  }
}


A binary string is a string where each character is either 0 or 1. Two binary strings $$$a$$$ and $$$b$$$ of equal length are similar, if they have the same character in some position (there exists an integer $$$i$$$ such that $$$a_i = b_i$$$). For example:  10010 and 01111 are similar (they have the same character in position $$$4$$$);  10010 and 11111 are similar;  111 and 111 are similar;  0110 and 1001 are not similar. You are given an integer $$$n$$$ and a binary string $$$s$$$ consisting of $$$2n-1$$$ characters. Let's denote $$$s[l..r]$$$ as the contiguous substring of $$$s$$$ starting with $$$l$$$-th character and ending with $$$r$$$-th character (in other words, $$$s[l..r] = s_l s_{l + 1} s_{l + 2} \dots s_r$$$).You have to construct a binary string $$$w$$$ of length $$$n$$$ which is similar to all of the following strings: $$$s[1..n]$$$, $$$s[2..n+1]$$$, $$$s[3..n+2]$$$, ..., $$$s[n..2n-1]$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$). The second line of each test case contains the binary string $$$s$$$ of length $$$2n - 1$$$. Each character $$$s_i$$$ is either 0 or 1.

For each test case, print the corresponding binary string $$$w$$$ of length $$$n$$$. If there are multiple such strings — print any of them. It can be shown that at least one string $$$w$$$ meeting the constraints always exists.

NoteThe explanation of the sample case (equal characters in equal positions are bold):The first test case:   $$$\mathbf{1}$$$ is similar to $$$s[1..1] = \mathbf{1}$$$. The second test case:   $$$\mathbf{000}$$$ is similar to $$$s[1..3] = \mathbf{000}$$$;  $$$\mathbf{000}$$$ is similar to $$$s[2..4] = \mathbf{000}$$$;  $$$\mathbf{000}$$$ is similar to $$$s[3..5] = \mathbf{000}$$$. The third test case:   $$$\mathbf{1}0\mathbf{10}$$$ is similar to $$$s[1..4] = \mathbf{1}1\mathbf{10}$$$;  $$$\mathbf{1}01\mathbf{0}$$$ is similar to $$$s[2..5] = \mathbf{1}10\mathbf{0}$$$;  $$$\mathbf{10}1\mathbf{0}$$$ is similar to $$$s[3..6] = \mathbf{10}0\mathbf{0}$$$;  $$$1\mathbf{0}1\mathbf{0}$$$ is similar to $$$s[4..7] = 0\mathbf{0}0\mathbf{0}$$$. The fourth test case:   $$$0\mathbf{0}$$$ is similar to $$$s[1..2] = 1\mathbf{0}$$$;  $$$\mathbf{0}0$$$ is similar to $$$s[2..3] = \mathbf{0}1$$$.

var numCases = parseInt(readline());
for (var i = 0; i < numCases; i ++) {
    var n = parseInt(readline());
    var str = readline();
    var output = '';
    for (var j = 0; j < n; j ++) {
        output += str[j * 2];
    }
    print(output);
}

var t = parseInt(readline());

while(t--){
  var n = parseInt(readline());
  var s = readline();

  var sym = s[n - 1];
  var res = "";
  for(var i = 0; i < n; i++){
    res += sym;
  }
  print(res);
}

'use strict'

const readLine = require('readline')

const readLineInterface = readLine.createInterface({
    input: process.stdin,
})

const rows = []
let numberOfRows = 0

readLineInterface.on('line', (row) => {
    if (!numberOfRows) {
        numberOfRows = Number(row)
    } else {
        rows.push(row)
    }

    if (rows.length === numberOfRows * 2) {
        readLineInterface.close()
    }
})
readLineInterface.on('close', main)

function main() {
    for (let i = 0; i < numberOfRows * 2; i += 2) {
        const n = Number(rows[i])
        const fullS = rows[i + 1]
        const s = []
        const startPosition = n - 1
        for (let j = startPosition; j < fullS.length; j++) {
            s.push(fullS.slice(j - startPosition, j + 1))
        }
        let resultS = ''
        for (let i = 0; i < n; i++) {
            let additionValue = 0
            for (let j of s) {
                additionValue += Number(j[i])
            }
            if (additionValue === n) {
                resultS += '1'
            } else {
                resultS += '0'
            }
        }
        console.log(resultS)
    }
}

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++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const str = readLine();
    let [count0, count1] = [0, 0];

    for (let i = 0; i < str.length; i++) {
      if (str[i] === "0") count0++;
      else count1++;
    }

    if (count0 > count1) console.log("0".repeat(len));
    else console.log("1".repeat(len));
  }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
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';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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 output = new Array(t);
  for(var i = 0; i < t; i++){
    var N = nextInt();
    var s = next();
    var str = [];
    var count = new Array(N);
    for(var j = 0; j < N; j++){
      count[j] = new Set();
    }
    for(var j = 0; j < s.length; j++){
      str.push(s[j]);
      if(j >= N){
        str.shift();
      }
      if(j >= N - 1){
        for(var k = 0; k < N; k++){
          count[k].add(str[k]);
        }
      }
    }
    str = "";
    myerr(count);
    for(var j = 0; j < N; j++){
      var tmp = Array.from(count[j]).sort();
      str += tmp[0];
    }
    output[i] = str;
  }
  myout(myconv(output, 9));
}

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', async _ => {
    inputString = inputString.split(/\n/);
    try {
      await main();
    } catch (e) {
      console.log(e)
    }
});

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

async function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
    const n = Number(readLine())
    const s = readLine().trim()
    console.log(Array.from(s).filter((_, i) => i % 2 === 0).join(''))
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const t = parseInt(readline());
  for (let i=0; i<t; i++) {
    const n = parseInt(readline());
    const s = readline();
    let w = "";
    for (let i=0; i<n; i++) {
      w += s[i*2];
    }
    console.log(w);
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1])) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, 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);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[998244353 % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
  let t = $()
  while (t--) {
    let n = +$(), s = $()
    out.push(s[n-1].repeat(n))
  }
  log(out.join('\n'))
}

const readline = require('readline');
const fs = require('fs');

const rl = readline.createInterface({
  input: process.env.TEST ? fs.createReadStream('input.txt') : process.stdin,
  output: process.stdout,
});
/** @type {Array<String>} */
const lines = [];

rl.on('line', (line) => lines.push(line));

rl.on('close', task);

function nextNumber() {
  return Number(lines.shift());
}
function nextString() {
  return lines.shift();
}

function task() {
  let t = nextNumber();
  while (t--) {
    let n = nextNumber();
    let s = nextString();
    let ret = '';
    for (let i = 0; i < n; i++) {
      ret += s[i * 2];
    }
    console.log(ret);
  }
}

const processData = (lines) => {
    let acc = 0
    const n = +lines[acc++]
    for (let i=0; i<n; i++) {
        const t = +lines[acc++]
        const s = lines[acc++].split('')
        let offset = 0
        let cur = s[0]
        const res = (new Array(t)).fill(0)
        res[0] = cur
        for (let i=1; i<t; i++) {
            if (cur !== s[i + offset]) {
                offset++

                cur = s[i + offset]
                res[offset] = cur
            }
        }

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

}

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

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

    probA();
});

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

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;

        let n = parseInt(readline());
        let s = readline().split('');
        let c = s[n-1];
        let res = '';
        for(let i = 0;  i< n; i++){
            res += c;
        }

        console.log(res);
    }
}

var numCases = parseInt(readline());
for (var i = 0; i < numCases; i ++) {
    var n = parseInt(readline());
    var str = readline();
    var output;
    for (var j = 0; j < n; j ++) {
        output += str[j * 2];
    }
    print(output);
}

'use strict'

const readLine = require('readline')

const readLineInterface = readLine.createInterface({
    input: process.stdin,
})

const rows = []
let numberOfRows = 0

readLineInterface.on('line', (row) => {
    if (!numberOfRows) {
        numberOfRows = Number(row)
    } else {
        rows.push(row)
    }

    if (rows.length === numberOfRows * 2) {
        readLineInterface.close()
    }
})
readLineInterface.on('close', main)

function main() {
    for (let i = 0; i < numberOfRows * 2; i += 2) {
        const n = Number(rows[i])
        const fullS = rows[i + 1]
        const s = []
        const startPosition = n - 1
        for (let j = startPosition; j < fullS.length; j++) {
            s.push(fullS.slice(j - startPosition, j + 1))
        }
        let resultS = ''
        for (let i = 0; i < n; i++) {
            let additionValue = 0
            for (let j of s) {
                additionValue += Number(j[i])
            }
            if (additionValue > Math.floor(n / 2)) {
                resultS += '1'
            } else {
                resultS += '0'
            }
        }
        console.log(resultS)
    }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n↑入力 ↓出力');
  Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
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';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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 output = new Array(t);
  for(var i = 0; i < t; i++){
    var N = nextInt();
    var s = next();
    var str = [];
    var count = new Array(N);
    for(var j = 0; j < N; j++){
      count[j] = new Set();
    }
    for(var j = 0; j < s.length; j++){
      str.push(s[j]);
      if(j >= N){
        str.shift();
      }
      if(j >= N - 1){
        for(var k = 0; k < N; k++){
          count[k].add(str[k]);
        }
      }
    }
    str = "";
    for(var j = 0; j < N; j++){
      var tmp = Array.from(count[j]);
      str += tmp[0];
    }
    output[i] = str;
  }
  myout(myconv(output, 9));
}

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

    probA();
});

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

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;

        let n = parseInt(readline());
        let s = readline();
        console.log(s.substring(0,n));
    }
}


One day, you are accepted as being Dr. Chanek's assistant. The first task given by Dr. Chanek to you is to take care and store his magical stones.Dr. Chanek has $$$N$$$ magical stones with $$$N$$$ being an even number. Those magical stones are numbered from $$$1$$$ to $$$N$$$. Magical stone $$$i$$$ has a strength of $$$A_i$$$. A magical stone can be painted with two colours, namely the colour black or the colour white. You are tasked to paint the magical stones with the colour black or white and store the magical stones into a magic box with a magic coefficient $$$Z$$$ ($$$0 \leq Z \leq 2$$$). The painting of the magical stones must be done in a way such that there are $$$\frac{N}{2}$$$ black magical stones and $$$\frac{N}{2}$$$ white magical stones.Define $$$\text{concat}(x, y)$$$ for two integers $$$x$$$ and $$$y$$$ as the result of concatenating the digits of $$$x$$$ to the left of $$$y$$$ in their decimal representation without changing the order. As an example, $$$\text{concat}(10, 24)$$$ will result in $$$1024$$$.For a magic box with a magic coefficient $$$Z$$$, magical stone $$$i$$$ will react with magical stone $$$j$$$ if the colours of both stones are different and $$$\text{concat}(A_i, A_j) \times \text{concat}(A_j, A_i) + A_i \times A_j \equiv Z \mod 3$$$. A magical stone that is reacting will be very hot and dangerous. Because of that, you must colour the magical stones and determine the magic coefficient $$$Z$$$ of the magic box in a way such that there is no magical stone that reacts, or report if it is impossible.

The first line contains a single even integer $$$N$$$ ($$$2 \le N \le 10^5$$$) — the number of magical stones Dr. Chanek has. The second line contains $$$N$$$ integer $$$A_1, A_2, \ldots, A_N$$$ ($$$1 \leq A_i \leq 10^9$$$) — the strengths of all magical stones.

If it is not possible to satisfy the condition of the problem, output $$$-1$$$. Otherwise, output two lines. The first line contains an integer $$$Z$$$ denoting the magic coefficient of the magic box. The second line contains a string $$$S$$$ of length $$$N$$$. $$$S_i$$$ is $$$0$$$ if magical stone $$$i$$$ is coloured black or $$$1$$$ if magical stone $$$i$$$ is coloured white. If there are more than one possibilities of colouring and choosing the magic coefficient $$$Z$$$, output any of them.

NoteBy giving the above colouring, it can be seen that:   $$$i=1, j=2 \longrightarrow \text{concat}(4, 10) \times \text{concat}(10, 4) + 10 \times 4 = 410 \times 104 + 40 = 42680 \equiv 2 \mod 3$$$  $$$i=1, j=3 \longrightarrow \text{concat}(4, 9) \times \text{concat}(9, 4) + 4 \times 9 = 49 \times 94 + 36 = 4642 \equiv 1 \mod 3$$$  $$$i=4, j=2 \longrightarrow \text{concat}(14, 10) \times \text{concat}(10, 14) + 10 \times 14 = 1410 \times 1014 + 140 = 1429880 \equiv 2 \mod 3$$$  $$$i=4, j=3 \longrightarrow \text{concat}(14, 9) \times \text{concat}(9, 14) + 14 \times 9 = 149 \times 914 + 126 = 136312 \equiv 1 \mod 3$$$ Because of that, by choosing $$$Z = 0$$$, it can be guaranteed that there is no magical stone that reacts.

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        a = new Array(n);
  let cnt = [0, 0, 0];
  for (let i = 0; i < n; i++) {
    a[i] = rn() % 3;
    cnt[a[i]]++;
  }
  let res = new Array(n).fill(1);
  const check0 = () => {
    if (cnt[0] === 0) {
      for (let i = 0; i < n / 2; i++) res[i] = 0;
      return true;
    }
    if (cnt[0] <= n / 2) {
      let t = n / 2 - cnt[0];
      for (let i = 0; i < n; i++) {
        if (!a[i]) res[i] = 0;else if (t) {
          res[i] = 0;
          t--;
        }
      }
      return true;
    }
    return false;
  };
  const check1 = () => {
    if (cnt[0] === 0 || cnt[0] === n) {
      for (let i = 0; i < n / 2; i++) res[i] = 0;
      return true;
    }
    return false;
  };
  const check2 = () => {
    if (cnt[1] + cnt[2] <= n / 2) {
      let t = n / 2 - (cnt[1] + cnt[2]);
      for (let i = 0; i < n; i++) {
        if (a[i]) res[i] = 0;else if (t) {
          res[i] = 0;
          t--;
        }
      }
      return true;
    }
    return false;
  };
  if (check0()) return `0\n${res.join('')}`;else if (check1()) return `1\n${res.join('')}`;else if (check2()) return `2\n${res.join('')}`;
  return -1;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        a = new Array(n);
  let cnt = [0, 0, 0];
  for (let i = 0; i < n; i++) {
    a[i] = rn() % 3;
    cnt[a[i]]++;
  }
  let res = new Array(n).fill(1);
  const check0 = () => {
    if (cnt[0] === 0) {
      for (let i = 0; i < n / 2; i++) res[i] = 0;
      return true;
    }
    if (cnt[0] <= n / 2) {
      let t = n / 2 - cnt[0];
      for (let i = 0; i < n; i++) {
        if (!a[i]) res[i] = 0;else if (t) {
          res[i] = 0;
          t--;
        }
      }
      return true;
    }
    return false;
  };
  const check1 = () => {
    if (cnt[0] === 0 || cnt[0] === n) {
      for (let i = 0; i < n / 2; i++) res[i] = 0;
      return true;
    }
    return false;
  };
  const check2 = () => {
    if (cnt[1] === 0 || cnt[2] === 0) {
      for (let i = 0; i < n / 2; i++) res[i] = 0;
      return true;
    }
    if (cnt[1] + cnt[2] <= n / 2) {
      let t = n / 2 - (cnt[1] + cnt[2]);
      for (let i = 0; i < n; i++) {
        if (a[i]) res[i] = 0;else if (t) {
          res[i] = 0;
          t--;
        }
      }
      return true;
    }
    return false;
  };
  if (check0()) return `0\n${res.join('')}`;else if (check1()) return `1\n${res.join('')}`;else if (check2()) return `2\n${res.join('')}`;
  return -1;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        a = new Array(n);
  let cnt = [0, 0, 0];
  for (let i = 0; i < n; i++) {
    a[i] = rn() % 3;
    cnt[a[i]]++;
  }
  let res = new Array(n).fill(1);
  const check0 = () => {
    if (cnt[0] === n || cnt[1] === n || cnt[2] === n || cnt[2] === 0) {
      for (let i = 0; i < n / 2; i++) res[i] = 0;
      return true;
    }
    return false;
  };
  const check1 = () => {
    if (cnt[0] === n || cnt[2] === n || cnt[0] === 0 || cnt[1] === 0) {
      for (let i = 0; i < n / 2; i++) res[i] = 0;
      return true;
    }
    if (cnt[0] + cnt[1] <= n / 2) {
      let t = n / 2 - (cnt[0] + cnt[1]);
      for (let i = 0; i < n; i++) {
        if (a[i] < 2) res[i] = 0;else if (t) {
          res[i] = 0;
          t--;
        }
      }
      return true;
    }
    return false;
  };
  const check2 = () => {
    if (cnt[1] === n || cnt[2] === 0 || cnt[0] === 0) {
      for (let i = 0; i < n / 2; i++) res[i] = 0;
      return true;
    }
    if (cnt[0] <= n / 2 && cnt[1] <= n / 2) {
      let t = n / 2 - cnt[0];
      for (let i = 0; i < n; i++) {
        if (!a[i]) res[i] = 0;else if (a[i] === 1 && t) {
          res[i] = 0;
          t--;
        }
      }
      return true;
    }
    return false;
  };
  if (check0()) return `0\n${res.join('')}`;else if (check1()) return `1\n${res.join('')}`;else if (check2()) return `2\n${res.join('')}`;
  return -1;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const rn = () => Number(read());
  const n = rn(),
        a = new Array(n);
  let cnt = [0, 0, 0];
  for (let i = 0; i < n; i++) {
    a[i] = rn() % 3;
    cnt[a[i]]++;
  }
  let res = new Array(n).fill(1);
  const check0 = () => {
    if (cnt[0] <= n / 2) {
      let t = n / 2 - cnt[0];
      for (let i = 0; i < n; i++) {
        if (!a[i]) res[i] = 0;else if (t) {
          res[i] = 0;
          t--;
        }
      }
      return true;
    }
    return false;
  };
  const check1 = () => {
    if (cnt[0] === n || cnt[1] === n || cnt[2] === n || cnt[0] === 0) {
      for (let i = 0; i < n / 2; i++) res[i] = 0;
      return true;
    }
    return false;
  };
  const check2 = () => {
    if (cnt[1] === 0 || cnt[2] === 0) {
      for (let i = 0; i < n / 2; i++) res[i] = 0;
      return true;
    }
    if (cnt[1] + cnt[2] <= n / 2) {
      let t = n / 2 - (cnt[1] + cnt[2]);
      for (let i = 0; i < n; i++) {
        if (a[i]) res[i] = 0;else if (t) {
          res[i] = 0;
          t--;
        }
      }
      return true;
    }
    return false;
  };
  if (check0()) return `0\n${res.join('')}`;else if (check1()) return `1\n${res.join('')}`;else if (check2()) return `2\n${res.join('')}`;
  return -1;
}

function main(r) {
  try {
    let t = 1;
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      }
    }
    if (t >= 100) ; else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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


While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly $$$H$$$ centimeters above the water surface. Inessa grabbed the flower and sailed the distance of $$$L$$$ centimeters. Exactly at this point the flower touched the water surface.  Suppose that the lily grows at some point $$$A$$$ on the lake bottom, and its stem is always a straight segment with one endpoint at point $$$A$$$. Also suppose that initially the flower was exactly above the point $$$A$$$, i.e. its stem was vertical. Can you determine the depth of the lake at point $$$A$$$?

The only line contains two integers $$$H$$$ and $$$L$$$ ($$$1 \le H < L \le 10^{6}$$$).

Print a single number — the depth of the lake at point $$$A$$$. The absolute or relative error should not exceed $$$10^{-6}$$$. Formally, let your answer be $$$A$$$, and the jury's answer be $$$B$$$. Your answer is accepted if and only if $$$\frac{|A - B|}{\max{(1, |B|)}} \le 10^{-6}$$$.

const readline = require('readline');

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

rl.on('line', (data) => {
    var arr = data.split(' ')
    var H = parseInt(arr[0])
    var L = parseInt(arr[1])

    var res = (L*L) - (H*H)
    res = res/(2*H)

    console.log(res.toFixed(13))
});

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let l, h, result;
rl.on('line', input => {
    [h, l] = input.split(' ').map(x => +x);
    result = (l*l - h*h) / h
    console.log(result / 2)
    rl.close()
})

// Codeforces 1199/B

const readline = require('readline');

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

rl.question('', (input) => {
  const [h, l] = input.split(' ');
  console.log(((l*l) - (h*h)) / (2 * h));
  rl.close();
});

const processData = (lines) => {
  const [conditions] = lines
  const [h, l] = conditions.split(' ').map(x => +x)
  const hyp = Math.sqrt(h*h + l*l)
  const atan = Math.atan(l/h)
  const A = hyp / Math.sin(Math.PI - 2 * atan) * Math.sin(atan)
  console.log(A - h)
}

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

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*/
    for (const line of lines) {
        const [H, L] = line.split(' ')
        if (H && L) {
            const A = (L ** 2) / (2 * H) - H / 2
            console.log(A)
        }
    }
})

let lines = ''

process.stdin.resume()
process.stdin.setEncoding('utf-8')
process.stdin.on('data', input => lines += input)
process.stdin.on('end', () => {
  const { EOL } = require('os')
  lines = lines.split(EOL)

  main()
})

function main() {
  const [ h, l ] = lines[0].split(/\s/).map(Number)
  const a = (Math.pow(l, 2) - Math.pow(h, 2)) / (2 * h)

  console.log(a.toFixed(13))
}

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

rl.on('line', (line) => {
  var num = line.split(" ").map(x => parseInt(x));
  var h, l;
  h = num[0];
  l = num[1];

  var result = (l*l-h*h)/(2*h);
  console.log(result);
});

var num = readline().split(" ").map(x => parseInt(x));
var h,l;
h=num[0],l=num[1];

var r= (l*l-h*h)/(2*h);
print(r);

var num = readline().split(" ").map(x => parseInt(x));
var h,l;
h=num[0],l=num[1];

print((l*l-h*h)/(2*h));

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

var h=num[0];
var l=num[1];

var r= (l*l-h*h)/(2*h);

print(r);

function padStart(str, count, symbol) {
  for(var i = str.length; i < count; i++) {
    str = '0' + str;
  }

  return str;
}

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

print((arr[1] * arr[1] - arr[0] * arr[0]) / (2 * arr[0]));

var input = readline()
  .split(" ")
  .map(function(x) {
    return parseInt(x);
  });
var result =
  (Math.pow(input[0], 2) + Math.pow(input[1], 2)) / (2 * input[0]) - input[0];
print(result);

// '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() {
//     let line;
//     while(line = readline()) {
//         let [h, l] = line.split(' ').map(num => parseInt(num));
//         findHeight(h, l)
//     }
// }

// function findHeight(h, l) {
//     let output = (l*l - h*h)/(2*h);
//     print(output)
// }
var line = readline().split(' ').map(num => parseInt(num));
var h = line[0];
var l = line[1];
var output = (l*l - h*h)/(2*h);
print(output)

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

var h,l;
h = num[0], l= num[1];

var r = (l*l-h*h)/(2*h);

print(r);

var inp = readline().split(' ');
var h = parseInt(inp[0], 10), l = parseInt(inp[1], 10);

var a = (Math.pow(l,2) - Math.pow(h,2)) / (2*h);

print(a);

(function() {
var INPUT = ``;
var OUTPUT = ``;

var main = function() {"use strict";
    // TODO
    var input = rdArN();
    var H = input[0];
    var L = input[1];

    var fullHyp = Math.sqrt(L*L + H*H);
    var halfHyp = fullHyp/2;
    var cosA = H/fullHyp;

    var stem = halfHyp/cosA;
    var x = stem - H;
    wr(x.toFixed(20))
};

if(INPUT){INPUT=INPUT.split('\n').reverse();
readline=()=>INPUT.pop();
write=(...s)=>{OUTPUT+=[...s].join(' ')};
print=(...s)=>{write(...s);OUTPUT+='\n'};}
const
rdS=readline,
rdN=()=>+rdS(),
rdArS=()=>rdS().split(' '),
rdArN=()=>rdArS().map(v=>+v),
wr=write,
pr=print,
prAr=(a)=>pr(...a),
prOb=(o)=>pr(JSON.stringify(o,null,4)),
crAr=function(length,...fillArgs){return new Array(length).fill(...fillArgs);},
getPrimes=function(n){var sieve=crAr(n+1,true);for(var i=2,j=4;j<sieve.length;j=Math.pow(++i,2)){if(sieve[j]){for(;j<sieve.length;j+=i){sieve[j]=false;}}}var primes=[];for(i=2;i<sieve.length;++i){if(sieve[i]){primes.push(i);}}return primes;},
defineProperty=(o,pN,v)=>Object.defineProperty(o,pN,{configurable:true,enumerable:false,value:v});
defineProperty(Array.prototype,'sortLt',function(){return this.sort((a,b)=>a-b);});
defineProperty(Array.prototype,'sortGt',function(){return this.sort((a,b)=>b-a);});
defineProperty(Set.prototype,'union',function(s){return new Set([...this,...s]);});
defineProperty(Set.prototype,'intersection',function(s){return new Set([...this].filter((v)=>s.has(v)));});
defineProperty(Set.prototype,'difference',function(s){return new Set([...this].filter((v)=>!s.has(v)));});

main();
return OUTPUT;
})();

var r,h,l,num=readline().split(" ").map(x => parseInt(x)),h=num[0],l=num[1],r= (l*l-h*h)/(2*h);print(r);

var input = readline()
  .split(" ")
  .map(function(x) {
    return parseInt(x);
  });
var result = (Math.pow(input[0], 2) + Math.pow(input[1], 2)) / 2 - input[0];
print(result);

var input = readline()
  .split(" ")
  .map(function(x) {
    return parseInt(x);
  });
var result = (input[0] + input[1]) / 2 - input[0];
print(result);


Little Petya very much likes arrays consisting of n integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose exactly one element from the array and replace it with another integer that also lies in the range from 1 to 109, inclusive. It is not allowed to replace a number with itself or to change no number at all. After the replacement Petya sorted the array by the numbers' non-decreasing. Now he wants to know for each position: what minimum number could occupy it after the replacement and the sorting.

The first line contains a single integer n (1 ≤ n ≤ 105), which represents how many numbers the array has. The next line contains n space-separated integers — the array's description. All elements of the array lie in the range from 1 to 109, inclusive.

Print n space-separated integers — the minimum possible values of each array element after one replacement and the sorting are performed.

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    let [_, ...arr] = i.split`\n`;
    arr = arr[0].split` `.map(Number);
    arr.sort((a, b) => a - b);
    arr.pop() === 1 ? arr.push(2) : arr.unshift(1);
    console.log(arr.join` `);
});

//Input
// var firstLine = "5" ; var secondLine = "1 2 3 4 5"      //R: 1 1 2 3 4
// var firstLine = "5" ; var secondLine = "2 3 4 5 6 "      //R: 1 2 3 4 5
// var firstLine = "3" ; var secondLine = "2 2 2"      //R: 1 2 2
// var firstLine = "4" ; var secondLine = "1 1 2 3"      //R: 1 1 1 2

// var firstLine = "3" ; var secondLine = "1 1 1"      //R: 1 1 2

// var firstLine = "10" ; var secondLine = "5 6 1 2 3 1 3 45 7 1000000000"      //R: 1 1 1 2 3 3 5 6 7 45
// var firstLine = "1" ; var secondLine = "1 "      //R: 1

var firstLine = readline(); var secondLine = readline();

retorno = eval(firstLine, secondLine);

//Solution
function eval(firstLine, secondLine){
    var n = parseInt(firstLine);
    var arr = secondLine.split(" ").map(function (x){ return parseInt(x)});

    write(replace(arr));
    // console.log(replace(arr));
    return "Hola";
};

function replace(arr){
    var len = arr.length;
    var newArr = ""; new Array(len+1).join("0").split("").map(parseInt); if(len > 1){newArr[1] = 0};

    arr.sort(function (a, b){return a-b});
    if(arr[len-1] != 1){
        arr[len-1] = 1;
    } else{
        arr[len-1] = 2
    };
    arr.sort(function(a, b){ return a-b});

    for(var i = 0 ; i < len ; i++){
        newArr += "" + arr[i];
        if(i < len -1){
            newArr += " ";
        };
    };

    return newArr;
};

;(function () {

	print(function (n) {

		var a = readline().split(' '),
			isEqual = true,
			max = 0, j = 0;

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

			if (isEqual && a[i] !== a[0]) isEqual = false;

			if (max < a[i]) {
				j = i;
				max = a[i];
			}
		}

		if (isEqual) {

			if (a[0] !== 1) a[0] = 1;
			else a[a.length - 1] = 2;

		} else a[j] = 1;

		return a.sort(function (a, b) { return a - b; }).join(' ');

	}(+readline()));

}.call(this));

var getNums = function () {
    return readline().split(' ').map(function (a) { return parseInt(a) });
};

//135A, 2 attempts
var n = readline();
var arr = getNums();
var max = {val: 1, pos: -1};
for (var i = 0; i < n; i++) {
    if (arr[i] > max.val) {
        max = {val: arr[i], pos: i};
    }
}
if (max.pos === -1) {
    arr[0] = 2;
} else {
    arr[max.pos] = 1;
}
print(arr.sort(function(a, b){return a - b}).join(' '));

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    let [_, ...arr] = i.split`\n`;
    arr = arr[0].split` `.map(Number);
    arr.sort((a, b) => a - b);
    arr.pop() === 1 ? arr.push(2) : arr.unshift(1);
    console.log(arr);
});

//Input
// var firstLine = "5" ; var secondLine = "1 2 3 4 5"      //R: 1 1 2 3 4
// var firstLine = "5" ; var secondLine = "2 3 4 5 6 "      //R: 1 2 3 4 5
// var firstLine = "3" ; var secondLine = "2 2 2"      //R: 1 2 2
// var firstLine = "4" ; var secondLine = "1 1 2 3"      //R: 1 1 1 2

// var firstLine = "3" ; var secondLine = "1 1 1"      //R: 1 1 2

// var firstLine = "10" ; var secondLine = "5 6 1 2 3 1 3 45 7 1000000000"      //R: 1 1 1 2 3 3 5 6 7 45
// var firstLine = "1" ; var secondLine = "1 "      //R: 1

var firstLine = readline(); var secondLine = readline();

retorno = eval(firstLine, secondLine);

//Solution
function eval(firstLine, secondLine){
    var n = parseInt(firstLine);
    var arr = secondLine.split(" ").map(function (x){ return parseInt(x)});

    // console.log(replace(arr));
    write(replace(arr));
    return "Hola";
};

function replace(arr){
    var len = arr.length;
    var newArr = new Array(len+1).join("0").split("").map(parseInt); if(len > 1){newArr[1] = 0};

    //console.log("arr: " + arr);
    arr.sort(function (a, b){return a-b});
    //console.log("arr: " + arr);
    if(arr[len-1] != 1){
        arr[len-1] = 1;
    } else{
        arr[len-1] = 2
    };
    arr.sort(function(a, b){ return a-b});

    return arr;
};

var getNums = function () {
    return readline().split(' ').map(function (a) { return parseInt(a) });
};

//134B
var n = readline();
var arr = getNums();
var max = {val: arr[0], pos: 0};
for (var i = 1; i > n; i++) {
    if (arr[i] > max.val) {
        max = {val: arr[i], pos: i};
    }
}
arr[max.pos] = 1;
print(arr.sort(function(a, b){return a - b}).join(' '));

var getNums = function () {
    return readline().split(' ').map(function (a) { return parseInt(a) });
};

//134B
var n = readline();
var arr = getNums();
var max = {val: arr[0], pos: 0};
for (var i = 1; i < n; i++) {
    if (arr[i] > max.val) {
        max = {val: arr[i], pos: i};
    }
}
arr[max.pos] = 1;
print(arr.sort(function(a, b){return a - b}).join(' '));


You are given an equation:  Ax2 + Bx + C = 0. Your task is to find the number of distinct roots of the equation and print all of them in ascending order.

The first line contains three integer numbers A, B and C ( - 105 ≤ A, B, C ≤ 105). Any coefficient may be equal to 0.

In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))

const A = lll[0]
const B = lll[1]
const C = lll[2]

;(function () {
  if (A == 0) {
    if (B == 0) {
      if (C == 0) return print(-1)
      return print(0)
    }
    print(1)
    return print(-C / B)
  } else {
    const D = B * B - 4 * A * C
    if (D < 0) return print(0)
    if (D == 0) {
      print(1)
      return print(-B / (2 * A))
    }
    print(2)
    if (A > 0) {
      print((-B - Math.sqrt(D)) / (2 * A))
      print((-B + Math.sqrt(D)) / (2 * A))
    } else {
      print((-B + Math.sqrt(D)) / (2 * A))
      print((-B - Math.sqrt(D)) / (2 * A))
    }
  }
})()

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))

const A = lll[0]
const B = lll[1]
const C = lll[2]

;(function () {
  if (A == 0) {
    if (B == 0) {
      if (C == 0) return print(-1)
      return print(0)
    }
    print(1)
    return print(-C / B)
  } else {
    const D = B * B - 4 * A * C
    if (D < 0) return print(0)
    if (D == 0) {
      print(1)
      return print(-B / (2 * A))
    }
    print(2)
    print((-B - Math.sqrt(D)) / (2 * A))
    print((-B + Math.sqrt(D)) / (2 * A))
  }
})()

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))

const A = lll[0]
const B = lll[1]
const C = lll[2]

;(function () {
  if (A == 0) {
    if (B == 0) {
      if (C == 0) return print(0)
      return print(-1)
    }
    print(1)
    return print(-C / B)
  } else {
    const D = B * B - 4 * A * C
    if (D < 0) return print(0)
    if (D == 0) {
      print(1)
      return print(-B / (2 * A))
    }
    print(2)
    print((-B - Math.sqrt(D)) / (2 * A))
    print((-B + Math.sqrt(D)) / (2 * A))
  }
})()


There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your friend for these k games. Your friend did not tell exact number of wins of each team, instead he thought that absolute difference between number of wins of first and second team will be d1 and that of between second and third team will be d2.You don't want any of team win the tournament, that is each team should have the same number of wins after n games. That's why you want to know: does there exist a valid tournament satisfying the friend's guess such that no team will win this tournament?Note that outcome of a match can not be a draw, it has to be either win or loss.

The first line of the input contains a single integer corresponding to number of test cases t (1 ≤ t ≤ 105). Each of the next t lines will contain four space-separated integers n, k, d1, d2 (1 ≤ n ≤ 1012; 0 ≤ k ≤ n; 0 ≤ d1, d2 ≤ k) — data for the current test case.

For each test case, output a single line containing either "yes" if it is possible to have no winner of tournament, or "no" otherwise (without quotes).

NoteSample 1. There has not been any match up to now (k = 0, d1 = 0, d2 = 0). If there will be three matches (1-2, 2-3, 3-1) and each team wins once, then at the end each team will have 1 win.Sample 2. You missed all the games (k = 3). As d1 = 0 and d2 = 0, and there is a way to play three games with no winner of tournament (described in the previous sample), the answer is "yes".Sample 3. You missed 4 matches, and d1 = 1, d2 = 0. These four matches can be: 1-2 (win 2), 1-3 (win 3), 1-2 (win 1), 1-3 (win 1). Currently the first team has 2 wins, the second team has 1 win, the third team has 1 win. Two remaining matches can be: 1-2 (win 2), 1-3 (win 3). In the end all the teams have equal number of wins (2 wins).

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function feasible(n, k, d1, d2) {
	if (n%3 != 0) {
		return false;
	}
	var x = k - d1 - 2*d2;
	if (x < 0 || x%3 != 0) {
		return false;
	}
	var c0 = x/3, b0 = c0 + d2, a0 = b0 + d1,
		y =  n/3;
	if (a0 > y || b0 > y || c0 > y ||
		a0 < 0 || b0 < 0 || c0 < 0) {
		return false;
	}
	return true;
}

function main() {
	var numCases = parseInt(readline());
	for (var caseIndex = 0; caseIndex < numCases; ++caseIndex) {
		var data = tokenizeIntegers(readline()),
			n = data[0], k = data[1], d1 = data[2], d2 = data[3];
		if (feasible(n, k, d1, d2) || feasible(n, k, -d1, d2) ||
				feasible(n, k, d1, -d2) || feasible(n, k, -d1, -d2)) {
			print('yes');
		} else {
			print('no');
		}
	}
}

main();

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function solve(n, k, d1, d2) {
	if (n%3 != 0) {
		return 'no';
	}
	var x = k - d1 - 2*d2;
	if (x < 0 || x%3 != 0) {
		return 'no';
	}
	var c0 = x/3, b0 = c0 + d2, a0 = b0 + d1,
		y =  n/3;
	if (a0 > y || b0 > y || c0 > y) {
		return 'no';
	}
	return 'yes';
}

function main() {
	var numCases = parseInt(readline());
	for (var caseIndex = 0; caseIndex < numCases; ++caseIndex) {
		var data = tokenizeIntegers(readline()),
			n = data[0], k = data[1], d1 = data[2], d2 = data[3];
		print(solve(n, k, d1, d2));
	}
}

main();