Ashishgup and FastestFinger play a game. They start with a number $$$n$$$ and play in turns. In each turn, a player can make any one of the following moves:  Divide $$$n$$$ by any of its odd divisors greater than $$$1$$$.  Subtract $$$1$$$ from $$$n$$$ if $$$n$$$ is greater than $$$1$$$. Divisors of a number include the number itself.The player who is unable to make a move loses the game.Ashishgup moves first. Determine the winner of the game if both of them play optimally.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. The description of the test cases follows. The only line of each test case contains a single integer  — $$$n$$$ ($$$1 \leq n \leq 10^9$$$).

For each test case, print "Ashishgup" if he wins, and "FastestFinger" otherwise (without quotes).

FastestFinger
Ashishgup
Ashishgup
FastestFinger
Ashishgup
FastestFinger
Ashishgup

NoteIn the first test case, $$$n = 1$$$, Ashishgup cannot make a move. He loses.In the second test case, $$$n = 2$$$, Ashishgup subtracts $$$1$$$ on the first move. Now $$$n = 1$$$, FastestFinger cannot make a move, so he loses.In the third test case, $$$n = 3$$$, Ashishgup divides by $$$3$$$ on the first move. Now $$$n = 1$$$, FastestFinger cannot make a move, so he loses.In the last test case, $$$n = 12$$$, Ashishgup divides it by $$$3$$$. Now $$$n = 4$$$, FastestFinger is forced to subtract $$$1$$$, and Ashishgup gets $$$3$$$, so he wins by dividing it by $$$3$$$.

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var n = +readline();
    if (n === 1) {
      print("FastestFinger");
      continue;
    }
    if (n % 2 || n === 2) {
      print("Ashishgup");
      continue;
    }
    check(n);
  }
}

function check(n) {
  var m = n;
  while (m > 1 && m % 2 === 0) {
    m = m / 2;
  }
  if (m === 1 || (n / m === 2 && isSimple(m))) {
    print("FastestFinger");
    return;
  }
  print("Ashishgup");
}

function isSimple(n) {
  var sq = Math.floor(Math.sqrt(n)) + 1;
  for (var k = 3; k < sq; k += 2) {
    if (n % k === 0) {
      return false;
    }
  }
  return true;
}
main();

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var input = '';
process.stdin.on('data', function (line) {
    input += line;
});
process.stdin.on('end', function () {
    var lines = input.split('\n');
    var tests = parseInt(lines.shift(), 10);
    while (tests--) {
        var n = parseInt(lines.shift(), 10);
        var ans = (function (n) {
            if (n == 1) {
                return 1;
            }
            if (n === 2) {
                return 0;
            }
            if (n % 2 === 1) {
                return 0;
            }
            if ((n & (n - 1)) === 0) {
                return 1;
            }
            var twoCount = 0;
            while (n % 2 === 0) {
                n /= 2;
                twoCount++;
            }
            if (twoCount > 1) {
                return 0;
            }
            return isPrime(n) ? 1 : 0;
        })(n);
        console.log(['Ashishgup', 'FastestFinger'][ans]);
    }
});
function isPrime(n) {
    for (var i = 3; i * i <= n; i += 2) {
        if (n % i === 0) {
            return false;
        }
    }
    return true;
}
// input helper
function lineToNumArray(line) {
    return line.split(' ').map(function (element) { return parseInt(element, 10); });
}

function findPrimeFactors (num) {

  var primeFactors = [];
  while (num % 2 === 0) {
    primeFactors.push(2);
    num = num / 2;
  }

  var sqrtNum = Math.sqrt(num);
  for (var i = 3; i <= sqrtNum; i++) {
    while (num % i === 0) {
      primeFactors.push(i);
      num = num / i;
    }
  }

  if (num > 2) {
    primeFactors.push(num);
  }
  return primeFactors;
}

const processData = (lines) => {
  let acc = 0
  const n = +lines[acc]
  acc++
  for (let i=0; i<n; i++) {
    const a = +lines[acc]
    acc++
    if (a === 1) {
      console.log('FastestFinger')
    } else {
      if (a % 2 === 1) {
        console.log('Ashishgup')
      } else {
        if (a === 2) {
          console.log('Ashishgup')
        } else {
          var facts = findPrimeFactors(a)
          let twos = 0
          let nonTwos = 0
          for (const t of facts) {
            if (t === 2) {
              twos++
            } else {
              nonTwos++
            }
          }
          if (nonTwos === 0) {
            console.log('FastestFinger')
          } else {
            if (twos > 1) {
              console.log('Ashishgup')
            } else {
              if (nonTwos > 1) {
                console.log('Ashishgup')
              } else {
                console.log('FastestFinger')
              }
            }
          }
        }
      }
    }
  }
}

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

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

let checkOddFactor = (n) => {
    let i = 2;
    let oddNum = 1;
    while(i*i <= n){
        if(n%i === 0){
            if(i%2 !== 0){
                oddNum *= i;
            }else if((n/i)%2 !== 0){
                oddNum *= (n/i);
            }
        }
        i++;
    }
    return oddNum;
}

let checkPrime = (n) => {
    let i = 2;
    while(i*i <= n){
        if(n%i === 0)
            return false;
        i++;
    }

    return true;
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let winner = '';

        if(n === 1){
            winner = 1;
        }else if(n === 2){
            winner = 0;
        }
        else if(n%2 !== 0){
            winner = 0;
        }else{
            let x = (n & (n-1));
            if(n % 4 === 0 && x !== 0){
                winner = 0;
            }else if(x === 0){
                winner = 1;
            }else{
                if(checkPrime(n/2)){
                    winner = 1;
                }else{
                    winner = 0;
                }
            }
        }

        console.log(winner === 0 ? 'Ashishgup' : 'FastestFinger');
    }
}

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var n = +readline();
    if (n === 1) {
      print("FastestFinger");
      continue;
    }
    if (n % 2 || n === 2) {
      print("Ashishgup");
      continue;
    }
    check(n);
  }
}

function check(n) {
  var m = n;
  while (m > 1 && m % 2 === 0) {
    m = m / 2;
  }
  if (m === 1 || n / m === 2) {
    print("FastestFinger");
    return;
  }
  print("Ashishgup");
}
main();

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

let checkOddFactor = (n) => {
    let i = 2;
    while(i*i <= n){
        if(n%i === 0 && (i%2 !== 0 || (n/i)%2 !== 0)){
            return i%2 !== 0 ? i : n/(n/i);
        }
        i++;
    }
    return n;
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let turn = 0;
        let winner = '';
        while(n > 1){
            if(n%2 !== 0){
                winner = turn === 0 ? 'Ashishgup' : 'FastestFinger';
                break;
            }else{
                let x = checkOddFactor(n);
                if(x === n){
                    if(n === 2){
                        winner = turn === 0 ? 'Ashishgup' : 'FastestFinger';
                    }else{
                        winner = turn === 0 ? 'FastestFinger' : 'Ashishgup';
                    }
                    break;
                }
                n = x;
            }
            turn = turn === 0 ? 1 : 0;
        }

        if(winner === ''){
            console.log(turn === 0 ? 'FastestFinger' : 'Ashishgup');
        }else{
            console.log(winner);
        }
    }
}

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

let checkOddFactor = (n) => {
    let i = 2;
    while(i*i <= n){
        if(n%i === 0 && i%2 !== 0)
            return n/i;
        i++;
    }
    return n;
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let turn = 0;
        let winner = '';
        while(n > 1){
            if(n%2 !== 0){
                winner = turn === 0 ? 'Ashishgup' : 'FastestFinger';
                break;
            }else{
                let x = checkOddFactor(n);
                if(x === n){
                    if(n === 2){
                        winner = turn === 0 ? 'Ashishgup' : 'FastestFinger';
                    }else{
                        winner = turn === 0 ? 'FastestFinger' : 'Ashishgup';
                    }
                    break;
                }
                n = x;
            }
            turn = turn === 0 ? 1 : 0;
        }

        if(winner === ''){
            console.log(turn === 0 ? 'FastestFinger' : 'Ashishgup');
        }else{
            console.log(winner);
        }
    }
}

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

let checkOddFactor = (n) => {
    let i = 2;
    while(i*i <= n){
        if(n%i === 0 && (i%2 !== 0 || (n/i)%2 !== 0)){
            return i%2 !== 0 ? n/i : n/(n/i);
        }
        i++;
    }
    return n;
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let turn = 0;
        let winner = '';
        while(n > 1){
            if(n%2 !== 0){
                winner = turn === 0 ? 'Ashishgup' : 'FastestFinger';
                break;
            }else{
                let x = checkOddFactor(n);
                if(x === n){
                    if(n === 2){
                        winner = turn === 0 ? 'Ashishgup' : 'FastestFinger';
                    }else{
                        winner = turn === 0 ? 'FastestFinger' : 'Ashishgup';
                    }
                    break;
                }
                n = x;
            }
            turn = turn === 0 ? 1 : 0;
        }

        if(winner === ''){
            console.log(turn === 0 ? 'FastestFinger' : 'Ashishgup');
        }else{
            console.log(winner);
        }
    }
}


We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.

The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.

Print the minimum number of steps modulo 109 + 7.

NoteThe first example: "ab"  →  "bba".The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".

var line = readline();
var total = 0;
var increment = 0;
var n = 1000000007;
for (var i = 0; i < line.length; i++){
    if (line[i] == "a")
        increment = (2 * increment + 1) % n;
    else
        total =  (total + increment) % n;
}

/*
var newStr = ['b','b','a'];
var str = [];
for (var i = 0; i < line.length; i++)
    str[i] = line[i];

if (str.length > 1){
    for (var i = 1; i < str.length; i++){
        if (str[i] == 'b' && str[i - 1] == 'a'){
            //str = str.slice(0, i - 1).concat(newStr).concat(str.slice(i + 1));
            str = str.
            total++;
            i-=2;
        }
    }
}
*/
print(total);

var s = readline();
var count = 0;
var countb = 0;
for (var i=s.length-1; i>=0; i--){
	if (s[i] == 'b') countb++;
	else {
		count += countb;
		countb *= 2;
		count %= 1000000007;
		countb %= 1000000007;
	}
}
print (count);

var line = readline();
var total = 0;
var increment = 0;
for (var i = 0; i < line.length; i++){
    if (line[i] == "a")
        increment = 2 * increment + 1;
    else
        total += increment;
}

/*
var newStr = ['b','b','a'];
var str = [];
for (var i = 0; i < line.length; i++)
    str[i] = line[i];

if (str.length > 1){
    for (var i = 1; i < str.length; i++){
        if (str[i] == 'b' && str[i - 1] == 'a'){
            //str = str.slice(0, i - 1).concat(newStr).concat(str.slice(i + 1));
            str = str.
            total++;
            i-=2;
        }
    }
}
*/
print(total);

var s = readline();
var count = 0;
var countb = 0;
var counta = 0;
for (var i=s.length-1; i>=1; i--){
	if (s[i] == 'b' && s[i-1] == 'b') countb++;
	if (s[i] == 'b' && s[i-1] == 'a') {
		countb++;
		count += countb;
	}
	if (s[i] == 'a' && s[i-1] == 'a') {
		countb *= 2;
		count += countb;
	}
}
print (count%(1000000000 + 7));


Mocha is a young girl from high school. She has learned so much interesting knowledge from her teachers, especially her math teacher. Recently, Mocha is learning about binary system and very interested in bitwise operation.This day, Mocha got a sequence $$$a$$$ of length $$$n$$$. In each operation, she can select an arbitrary interval $$$[l, r]$$$ and for all values $$$i$$$ ($$$0\leq i \leq r-l$$$), replace $$$a_{l+i}$$$ with $$$a_{l+i} \,\&\, a_{r-i}$$$ at the same time, where $$$\&$$$ denotes the bitwise AND operation. This operation can be performed any number of times.For example, if $$$n=5$$$, the array is $$$[a_1,a_2,a_3,a_4,a_5]$$$, and Mocha selects the interval $$$[2,5]$$$, then the new array is $$$[a_1,a_2\,\&\, a_5, a_3\,\&\, a_4, a_4\,\&\, a_3, a_5\,\&\, a_2]$$$.Now Mocha wants to minimize the maximum value in the sequence. As her best friend, can you help her to get the answer?

Each test contains multiple test cases.  The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the sequence. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$).

For each test case, print one integer — the minimal value of the maximum value in the sequence.

NoteIn the first test case, Mocha can choose the interval $$$[1,2]$$$, then the sequence becomes $$$[ 0, 0]$$$, where the first element is $$$1\,\&\,2$$$, and the second element is $$$2\,\&\,1$$$.In the second test case, Mocha can choose the interval $$$[1,3]$$$, then the sequence becomes $$$[ 1,1,1]$$$, where the first element is $$$1\,\&\,3$$$, the second element is $$$1\,\&\,1$$$, and the third element is $$$3\,\&\,1$$$.

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

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

		let ans = a[0];
		for (const elm of a) ans &= elm;

		console.log(ans);
	}
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		for(var i = 0; i < N - 1; i++){
			for(var j = i + 1; j < N; j++){
				var L = i;
				var R = j;
				for(var k = L; k <= R; k++){
					var tmp = list[k] & list[R - k];
					list[k] = tmp;
					list[R - k] = tmp;
				}
			}
		}
		for(var i = 0; i < N - 1; i++){
			for(var j = i + 1; j < N; j++){
				var L = i;
				var R = j;
				for(var k = L; k <= R; k++){
					var tmp = list[k] & list[R - k];
					list[k] = tmp;
					list[R - k] = tmp;
				}
			}
		}
		var max = 0;
		for(var i = 0; i < N; i++){
			max = Math.max(max, list[i]);
		}
		myout(max);
	}
}

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e, n) {
  let t = n[0]
  for (let s = 1; s < e; ++s) t &= n[s]
  return t
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve(Number(e.readLine()), e.readIntegersOfLine())
    e.print(n + '\n')
  }
})

let inputBuffer = ''
process.stdin.on('data', data => {
	inputBuffer += data
})
process.stdin.on('end', _ => {
	inputBuffer = inputBuffer.trim().split('\n')

	main()
})

let currentLine = 0
function readline() {
	return inputBuffer[currentLine++]
}
function readint() {
	return parseInt(readline(), 10)
}
function readints() {
	return readline().split(' ').map(s => parseInt(s, 10))
}
function print(s) {
	process.stdout.write(s + '\n')
}
function write(s) {
	process.stdout.write(s)
}

function range(lowerBound, upperBound = undefined, step = 1) {
	if (upperBound === undefined) {
		upperBound = lowerBound
		lowerBound = 0
	}
	let ret = []
	for (let i = lowerBound; i < upperBound; i += step) ret.push(i)
	return ret
}
function loop(lowerBound, upperBound = undefined, step = 1) {
	return (func) => {
		range(lowerBound, upperBound, step).forEach(i => func(i))
	}
}

function main() {
	let t = readint()
	loop(t)(_ => {
		readint()
		print(readints().reduce((prev, x) => prev & x))
	})
}

var t = parseInt(readline())
while(t--){
    var n=parseInt(readline())
    var v=readline().split(' ')
    var res=v[0]
    while(--n)
        res &= v[n]
    print(res)
}

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 readLine = () => dataitr.next().value.trim();
function rl () {
	let ans = readLine().split(' ');
	if (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));
	return ans.length == 1 ? ans[0] : ans;
}

function main () {
	let t = rl();
	while(t--){
		let n = rl();
		let a = rl();

		let ans = a[0];
		for (let i = 1 ; i < n; i++)
			ans &= a[i];

		console.log(ans);
	}

}

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 readLine = () => dataitr.next().value.trim();
function rl () {
	let ans = readLine().split(' ');
	if (!isNaN(Number(ans[0]))) ans = ans.map(x => Number(x));
	return ans.length == 1 ? ans[0] : ans;
}

function main () {
	let t = rl();
	while(t--) {
		let n = rl();
		let a = rl();
		console.log(a[n - 1]);
	}

}

//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] = BigInt(next());
		}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 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 getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		for(var i = 0; i < N - 1; i++){
			for(var j = i + 1; j < N; j++){
				var L = i;
				var R = j;
				for(var k = L; k <= R; k++){
					var tmp = list[k] & list[R - k];
					list[k] = tmp;
					list[R - k] = tmp;
				}
			}
		}
		var max = 0;
		for(var i = 0; i < N; i++){
			max = Math.max(max, list[i]);
		}
		myout(max);
	}
}

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve() {
  return -1
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve()
    e.print(n + '\n')
  }
})


You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. Polycarp wants to remove exactly $$$k$$$ characters ($$$k \le n$$$) from the string $$$s$$$. Polycarp uses the following algorithm $$$k$$$ times:  if there is at least one letter 'a', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;  if there is at least one letter 'b', remove the leftmost occurrence and stop the algorithm, otherwise go to next item;  ...  remove the leftmost occurrence of the letter 'z' and stop the algorithm. This algorithm removes a single letter from the string. Polycarp performs this algorithm exactly $$$k$$$ times, thus removing exactly $$$k$$$ characters.Help Polycarp find the resulting string.

The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 4 \cdot 10^5$$$) — the length of the string and the number of letters Polycarp will remove. The second line contains the string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.

Print the string that will be obtained from $$$s$$$ after Polycarp removes exactly $$$k$$$ letters using the above algorithm $$$k$$$ times. If the resulting string is empty, print nothing. It is allowed to print nothing or an empty line (line break).

var nk = readline().split(' ').map(Number);
var n = nk[0];
var k = nk[1];
var s = readline().split('');
var count = 0;
for (var i=97; i<=122; i++){
	if (count == k) break;
	for (var j=0; j<s.length; j++){
		if (s[j].charCodeAt(0) == i){
			s[j] = '0';
			count++;
		}
		if (count == k) break;
	}
}
s = s.filter( a => a != '0').join('');
print(s);


Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it?The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper.There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not.

The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font:

Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes).

(function main() {
    var line = readline();

    var sym = "AHIMOTUVWXY";

    for (var i = 0; i < line.length; i++){

        if (sym.indexOf(line[i]) == -1){
            print("NO");
            return 0;
        }

        if (line[i] !== line[line.length - i - 1]){
            print("NO");
            return 0;
        }
    }

    print("YES");

    return 0;
})();


The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.If there is no police officer free (isn't busy with crime) during the occurrence of a crime, it will go untreated.Given the chronological order of crime occurrences and recruit hirings, find the number of crimes which will go untreated.

The first line of input will contain an integer n (1 ≤ n ≤ 105), the number of events. The next line will contain n space-separated integers. If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than 10 officers will be recruited at a time.

Print a single integer, the number of crimes which will go untreated.

NoteLets consider the second example:  Firstly one person is hired.  Then crime appears, the last hired person will investigate this crime.  One more person is hired.  One more crime appears, the last hired person will investigate this crime.  Crime appears. There is no free policeman at the time, so this crime will go untreated.  One more person is hired.  One more person is hired.  One more person is hired. The answer is one, as one crime (on step 5) will go untreated.

'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 events =   parseInt(readline());
    const values = readline().split(' ').map(x => parseInt(x));
    let availableOfficer = 0 ;
    let crimes = 0 ;
    for (let i = 0 ; i < events ; i++){
        if (values[i] > 0){
            availableOfficer += values[i];
        }else {
            let crime = Math.abs(values[i]);
           let isCrime = availableOfficer - crime
            availableOfficer = (isCrime < 0 ) ? 0 : isCrime
            if (isCrime < 0) crimes += crime;
        }
    }
    console.log(crimes);
}

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let numOfEvents;
let events;
let crimeCounter = 0;
let recruitersCounter = 0;
rl.on("line", (input) => {
    if (!numOfEvents) {
        numOfEvents = parseInt(input.split(" "))
    } else {
        events = input.split(" ").map(Number)
        events.forEach(element => {
            if (element === -1) {
                if (recruitersCounter > 0) {
                    recruitersCounter = recruitersCounter - 1
                }
                else{
                    crimeCounter++
                }
            } else {
                recruitersCounter += element
            }

        });
        console.log(crimeCounter)
        rl.close()
    }
})

"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 x = readline();
  const x2 = readline()
    .split(" ")
    .map((x) => +x);

  policeRecruits(x2);
}

function policeRecruits(array) {
  let crimeCount = 0;
  let availableCops = 0;

  for (let i = 0; i < array.length; i++) {
    const element = array[i];
    if (element < 0) {
      if (availableCops > 0) {
        availableCops--;
        crimeCount = Math.max(crimeCount, crimeCount - 1);
      } else {
        crimeCount++;
      }
    } else {
      availableCops += element;
    }
  }
  console.log(crimeCount);
}

(function() {
    var n = parseInt(readline());
    var hired = 0, untreated = 0;
    readline().split(' ').forEach(function (v){
        if ( v[0] !== "-" ){
            hired += parseInt(v);
        }else{
            if ( hired > 0 ){
                --hired;
            }else{
                ++untreated;
            }
        }
    });
    print(untreated);
})();

var events = parseInt(readline());

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

var buffer = 0;
var crimes = 0;

for (var i = 0; i < events; i++ ) {
    if (order[i] === -1) {
        if (!buffer) {
            crimes++;
        } else {
            buffer--;
        }
    } else {
        buffer += order[i];
    }
}

print(crimes);

if (!this.readline) print = console.log, readline = require('./readline');

function readNums() {
	return readline().split(' ').map(Number);
}
print(function(n) {
	var a = readNums();
	var ans = 0;
	var p = 0;
	for (var i = 0; i < n; i++) {
		if (a[i] === -1) {
			if (p > 0) {
				p--;
			} else {
				ans++;
			}
		} else {
			p += a[i];
		}
	}
	return ans;
}(+readline()));

var n = +readline(), events = readline().split(" "), sum = 0, police = 0;

events.forEach(function(a){
	if(a == "-1" && police == 0){
		sum++;
	}
	else if(a == "-1" && police > 0){
		police--;
	}
	else{
		police += +a;
	}
});

write(sum);

var n = parseInt(readline());
var input = readline().split(' ').map(x=>parseInt(x));

var crime=0;
var officer=0;
var temp;
for(var i=0 ; i<n ;i++){
    if(input[i]>0){
        officer+=input[i];
    }
    else{
       temp = input[i]+ officer;
       if(temp>0){
           officer=temp;
       }
       else{
           crime += temp;
           officer=0;
       }
    }
}

print(Math.abs(crime));

var n = parseInt(readline());
var input = readline().split(' ').map(x=>parseInt(x));

var crime=0;
var officer=0;

for(var i=0 ; i<n ;i++){
    if(input[i]>0){
        officer+=input[i];
    }
    else{
       officer--;
       if(officer<0){
           officer=0;
           crime++;

       }
    }
}

print(crime);

  var numberOfEvents = readline()
  var events = readline().split(' ').map(Number)

  var policeAvailable = 0
  var untreatedEvents = 0

  for (var i = 0; i < numberOfEvents; i++) {
    if (events[i] > 0) {
      policeAvailable += events[i]
    } else if (events[i] < 0 && policeAvailable === 0) {
      untreatedEvents += 1
    } else {
      policeAvailable -= 1
    }
  }

  print(untreatedEvents)

;(function () {

	var n = +readline();
	var s = readline().split(' ').map(Number);
	var x = 0;
	var y = 0;

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

		if (s[i] == -1) {
			if (!x) y++;
			else x--;
		} else x += s[i];

	}

	print(y);

}).call(this);

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 main() {
	var n = parseInt(readline());
	var data = tokenizeIntegers(readline());
	var police = 0, crimes = 0;
	for (var i = 0; i < n; ++i) {
		if (data[i] == -1) {
			if (police == 0) {
				++crimes;
			}
			else {
				--police;
			}
		}
		else {
			police += data[i];
		}
	}
	print(crimes);
}

main();

var line = readline();
var n = line.split(' ')[0];
line = readline();
var array=line.split(' ');
var sum =0;
var temp;
var solution = 0;

for(var i = 0 ;  i < array.length;i++){
    temp = parseInt(array[i]);
    if(temp < 0){
        if(sum === 0){
            solution++
        }
        else{
            sum--;
        }
    }
    else{
        sum += temp;
    }
}

print(solution);

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
}

readline();
let events = readline().getNumArray(),
    crimeCounter = 0,
    availablePolice = 0;

events.map((event) => {
  if (event === -1) {
    if (availablePolice === 0) {
      crimeCounter++;
    } else {
       availablePolice--;
    }
  } else {
     availablePolice += event;
  }
});

write(crimeCounter);

var totalEvents=readline();
var events = readline().split(' ').map(Number);
var availablePolice=0;
var crimes = 0;

for(var i=0;i<totalEvents;i++){
    if(events[i]>0){
        availablePolice += events[i];
    }else if (events[i]<0 && availablePolice ===0){
        crimes +=1;
    }else{
        availablePolice -=1;
    }
}
print(crimes);

var n = readline(),
	num = readline().split(" ").map(function(x) {
        return parseInt(x)
    }),
	p = 0, c = 0;
for (var i = 0; i < n; i++) {
	if (num[i] >= 0) {
		p += num[i];
    } else {
		(p > 0) ? p-- : c++;
    }
}
print(c);

var n =  readline();
var str = readline().split(" ");
var temp = 0;
var res = 0
	for (var i=0; i<+n; i++){
		temp+= Number(str[i]);
		if (temp<0){
			res++;
			temp=0;
			}
	}
print(res);

var n = readline();
var c = readline().split(' ').map(Number);
var person = 0;
var crimes = 0;

for(var i = 0; i < n; i++){
    if(c[i] > 0){
        person += c[i];
    }
    else if(person !== 0){
        person += c[i];
    }
    else {
        crimes ++;
    }
}

print(crimes);

var n = parseInt(readline());
var answ = 0;
var items = readline().split(' ');
var police = 0;
for( var i = 0; i < items.length; ++i) {
  if (items[i] == '-1' && police == 0) {
    answ++;
  } else {
    police += parseInt(items[i]);
  }
}

print(answ);

var hired = 0, arr, events, numOfCrims = 0;

events = readline('Enter Num of Events');
arr = readline().split(' ').map(Number);

for (var i = 0; i < arr.length; i++) {
    if (arr[i] < 0) {
        if (hired === 0)
            numOfCrims++;
        else
            hired--;
    }
    else
        hired = hired +arr[i];

}

print(numOfCrims);

readline();
var a = readline().split(" ").map(function(x) { return parseInt(x); });
var n = 0, police = 0;
for (var i = 0; i < a.length; i++) {
  if (a[i] >= 0) {
    police+= a[i];
  } else {
    if (police > 0) {
      police--;
    } else {
      n++;
    }
  }
}
print(n);

var n=parseInt(readline());
var array=readline().split(' ').map(Number);

un=0
per=0;

for(var i=0;i<array.length;i++){
  if(array[i]==-1){
    if(per>0){
      per=per+array[i]
    }else{
      un=un+1;
    }
  }else{
    per=per+array[i]
  }
}
print(un);

readline();
var recruits = readline().split(' ').map(Number);
var sum=0;
var index=0
for (i = recruits.length-1; i>=0; i--) {
  if (recruits[i]<0)
      sum+=recruits[i];
  else{
    sum=recruits[i]+sum;
    if(sum>=1)
    sum=0;

  }

}
print(Math.abs(sum))

var n = readline();
var p = readline().split(" ");
var stack = [];
var u = 0;
var min = 0;
var push = function(n,stack){
	if(stack.length != 0)
		n+=stack.pop();
	stack.push(n);
	min = (n < min) ? n : min;
}

for (var i = 0; i < p.length; i++)
	push(parseInt(p[i]),stack);
print(min*-1);

n=+readline()
x=0
print(readline().split(' ').map(Number).reduce((s,a)=>s+((x=a>0?Math.max(a,x+a):x-1)<0?1:0),0))

var n = readline();

var line = readline().split(' ');

var police = 0;
var crimes = 0;
var unsolved = 0;

for(i=0;i<n;i++){
    if(parseInt(line[i])>0){
	police+=parseInt(line[i]);
    } else{
	crimes+=1;
	if(crimes>police){
	    unsolved+=1;
	    crimes=0;
	    continue;
	}else{
	    police-=1;
	    crimes-=1;
	}
    }
}

print(unsolved);

"use strict";

var main = function() {
    var n = +rd();
    var A = rdAr();

    wr(A.reduce((a, v) => [Math.max(0, a[0] + v), a[1] + (v === -1 && a[0] <= 0)], [0, 0])[1]);
};

var rd = readline;
var wr = write;
var pr = print;
var rdAr = () => rd().split(' ').map(v => +v);
var cmpLt = (a, b) => a - b;
var cmpGt = (a, b) => b - a;

main();

readline()
T=readline().split(' ').map(Number)
print(T.reduce((a,c) => {
    if (c > 0) {
        a.p += c;
    } else {
        if (a.p) {
            a.p--;
        } else {
            a.a++;
        }
    }
    return a;
}, { a: 0, p: 0 }).a)

// 'use strict';

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

// let inputString = '';
// let currentLine = 0;

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

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

//   main();
// });

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

function main() {
  const events_count = parseInt(readline(), 10);
  const events = readline().trim().split(' ').map(string => parseInt(string, 10));
  var crimes_untreated = 0;
  var free_police_forces = 0;

  events.forEach(event => {
    if (event === -1) {
      if (free_police_forces > 0) {
        free_police_forces--;
      } else {
        crimes_untreated++;
      }
    } else {
      free_police_forces += event;
    }
  });

  print(crimes_untreated);
}

main();

(function (){
    var Ret = 0;
    var K = 0;
    var C = readline();
    var Arr = readline().split(" ");
    for (var i in Arr) {
        var N = parseInt(Arr[i]);
        //console.log(i,N);
        if (N > 0) {
            K += N;
        } else {
            if (K > 0) {
                K--;
            } else {
                Ret++;
            }
        }
    }
    print(Ret);
})();

//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");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return 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 N = nextInt();
  var list = nextIntArray();
  var ok = 0;
  var ng = 0;
  for(var i = 0; i < N; i++){
    if(list[i] > 0){
      ok += list[i];
    }else{
      if(ok > 0){
        ok--;
      }else{
        ng++;
      }
    }
  }
  myout(ng);
}

const readline = require('readline');

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

let counter = 0;

rl.on('line', (input) => {
    if (counter++ === 0) return;
    let line = input.split(' ');
    let inputs = [];
    line.forEach(element => {
        inputs.push(parseInt(element));
    });
    rl.close();
    console.log(solve(inputs));
});

const solve = (inputs) => {
    let currentHired = 0,
        unsolved = 0;
    inputs.forEach(element => {
        if (element === -1 && currentHired === 0) unsolved++;
        else if (element === -1 && currentHired !== 0) currentHired--;
        else currentHired += element;
    });
    return unsolved;
}

'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 print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const n = readline();
  let l = readline().split(' ').map(x => parseInt(x));
  let result = 0;
  let sum = 0;
  for (let i = 0; i < n; i++) {
    sum += l[i];
    if (sum < 0) {
      result++;
      sum = 0;
    }
  }
  // output
  print(result);
}

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 arr = d.split(' ').map(Number);
  let ans = 0;
  let cops = 0;

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] > 0) {
      cops += arr[i];
    }
    else {
      if (cops === 0) {
        ans++;
      }
      else {
        cops = Math.max(0, --cops);
      }
    }
  }

  console.log(ans);

  c++;
});

const input = [];

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

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

RL.on('close', () => {
  const nums = input[1].split(' ').map(x => parseInt(x));
  let answ = 0; let cops = 0;

  nums.forEach(x => {
    if (x >= 0) cops += x;
    else {
      if (cops + x < 0) answ += 1;
      else cops += x;
    }
  });

  console.log(answ);
});

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

const readLine=()=> inputString[currentLine++];
/* ================================================
           Main Solution Starts Here
===================================================*/

const main=()=>{
	let hired=0
	let untreated=0
	let x=+readLine()
	let order=readLine().split(" ").map(n=>+n)/* +ve int*/
	for(let i=0;i<order.length;i++){
		if(order[i]===-1){
			if(hired){
				hired--
			}else untreated++
		}else hired+=order[i]
	}

	console.log(untreated)
}

// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.trim().split('\n');
    let test = +inputs[0];
    let positive = 0;
    let untreatedCrime = 0;
    let cases = inputs[1].split(' ').map(num => Number(num));

    for (i = 0; i < test; i++) {

        if (cases[i] > 0) {
            positive += cases[i];
        }
        else if (positive > 0) {
            positive--;
        }
        else {
            untreatedCrime++;
        }

    }
    return untreatedCrime.toString();

}

'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    let arr = readLine().split(' ').map(v => parseInt(v));
    let current = 0;
    let ans = 0;
    for (var i = 0; i < n; i++) {
        current += arr[i];
        if (current < 0) {
            ans++;
            current = 0;
        }
    }
    console.log(ans);
}

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let numOfEvents;
let events;
let crimeCounter = 0;
let recruitersCounter = 0;
rl.on("line", (input) => {
    if (!numOfEvents) {
        numOfEvents = parseInt(input.split(" "))
    } else {
        events = input.split(" ").map(Number)
        events.forEach(element => {
            if (element === -1) {
                crimeCounter++
            } else {
                recruitersCounter += element
            }
            if (crimeCounter <= recruitersCounter) {
                recruitersCounter = recruitersCounter - crimeCounter
                crimeCounter = 0
            }
        });
        console.log(crimeCounter)
        rl.close()
    }
})

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let numOfEvents;
let events;
let crimeCounter = 0;
let recruitersCounter = 0;
rl.on("line", (input) => {
    if (!numOfEvents) {
        numOfEvents = parseInt(input.split(" "))
    } else {
        events = input.split(" ").map(Number)
        events.forEach(element => {
            if (crimeCounter <= recruitersCounter) {
                recruitersCounter = recruitersCounter - crimeCounter
                crimeCounter = 0
            }
            if (element === -1) {
                crimeCounter++
            } else {
                recruitersCounter += element
            }

        });
        console.log(crimeCounter)
        rl.close()
    }
})

(function() {
    var n = parseInt(readline());
    var hired = 0, untreated = 0;
    readline().split(' ').forEach(function (v){
        if ( v[0] === "1" ){
            ++hired;
        }else{
            if ( hired > 0 ){
                --hired;
            }else{
                ++untreated;
            }
        }
    });
    print(untreated);
})();

var hired = 0, arr, events, numOfCrims = 0;

events = readline('Enter Num of Events');
arr = readline().split(' ').map(Number);

for (var i = 0; i < arr.length; i++) {
    if (arr[i] < 0) {
        if (hired === 0)
            numOfCrims++;
        else
            hired--;
    }
    else
        hired = arr[i];

}

print(numOfCrims);

readline();
var recruits = readline().split(' ').map(Number);
var sum=0;
var index=0
for (i = recruits.length-1; i>=0; i--) {
  if (recruits[i]<0)
      sum+=recruits[i];
  else{
    sum=recruits[i]+sum;
    if(sum>=1)
    sum=0;

  }
  print(Math.abs(sum))

}
print(Math.abs(sum))

n=+readline()
x=0
print(readline().split(' ').map(Number).reduce((s,a)=>s+((x=a>0?a:x-1)<0?1:0),0))

var n = readline();

var line = readline().split(' ');

var police = 0;
var crimes = 0;
var unsolved = 0;

for(i=0;i<n;i++){
    if(parseInt(line[i])>0){
	police+=1;
    } else{
	crimes+=1;
	if(crimes>police){
	    unsolved+=1;
	    crimes=0;
	    continue;
	}else{
	    police-=1;
	    crimes-=1;
	}
    }
}

print(unsolved);

// '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 events_count = parseInt(readline(), 10);
  const events = readline().trim().split(' ').map(string => {
    return parseInt(string, 10);
  });
  var crimes_untreated = 0;
  var free_police_forces = 0;

  events.forEach(event => {
    if (event === -1) {
      if (free_police_forces > 0) {
        free_police_forces--;
      } else {
        crimes_untreated++;
      }
    } else {
      free_police_forces += event;
    }
  });

  print(crimes_untreated);
}

(function() {
    var n = parseInt(readline());
    var hired = 0, untreated = 0;
    readline().split(' ').forEach(function (v){
        if ( v[0] == '1' ){
            ++hired;
        }else{
            if ( hired > 0 ){
                --hired;
            }else{
                ++untreated;
            }
        }
    });
    print(untreated);
})();

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 arr = d.split(' ').map(Number);
  let ans = 0;
  let cops = 0;

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === 1) {
      cops++;
    }
    else {
      if (cops === 0) {
        ans++;
      }
      else {
        cops = Math.max(0, --cops);
      }
    }
  }

  console.log(ans);

  c++;
});

// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.trim().split('\n');
    let untreatedCrime = 0;
    let cases = inputs[1].split(' ');
    for (let index = 0; index < cases.length - 1; index++) {
        const element = cases[index];
        if (cases[index] < 0) {
            untreatedCrime++;
            if ((index - 1) >= 0 && cases[index - 1] > 0) {
                untreatedCrime -= 1;
            }

        }

    }
    return untreatedCrime.toString();

}

// Sample code to perform I/O:

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;                               // Reading input from STDIN
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {

    let inputs = str.trim().split('\n');
    let positive = 0;
    let untreatedCrime = 0;
    let cases = inputs[1].split(' ');
    for (let index = 0; index < cases.length; index++) {
        const element = cases[index];
        if (cases[index] < 0) {
            untreatedCrime++;
            if (positive > 0) {
                untreatedCrime -= positive;
                positive = 0;
            }
        }
        else {
            positive += +cases[index];
        }

    }
    return untreatedCrime.toString();

}


There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbour of itself.Vasya has an account in each bank. Its balance may be negative, meaning Vasya owes some money to this bank.There is only one type of operations available: transfer some amount of money from any bank to account in any neighbouring bank. There are no restrictions on the size of the sum being transferred or balance requirements to perform this operation.Vasya doesn't like to deal with large numbers, so he asks you to determine the minimum number of operations required to change the balance of each bank account to zero. It's guaranteed, that this is possible to achieve, that is, the total balance of Vasya in all banks is equal to zero.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of banks. The second line contains n integers ai ( - 109 ≤ ai ≤ 109), the i-th of them is equal to the initial balance of the account in the i-th bank. It's guaranteed that the sum of all ai is equal to 0.

Print the minimum number of operations required to change balance in each bank to zero.

NoteIn the first sample, Vasya may transfer 5 from the first bank to the third.In the second sample, Vasya may first transfer 1 from the third bank to the second, and then 1 from the second to the first.In the third sample, the following sequence provides the optimal answer:   transfer 1 from the first bank to the second bank;  transfer 3 from the second bank to the third;  transfer 6 from the third bank to the fourth.

(function () {
	var n = parseInt(readline());
	var line = readline().split(' ');
	var m = {};
	var prefix = 0;
	var ans = n - 1;
	//print(n);
	for(var idx in line){
		prefix += parseInt(line[idx]);
		//print(prefix);
		if(!m[''+prefix]) {
			m[''+prefix] = 1;
		} else {
			++m[''+prefix];
		}
		ans = n - m[''+prefix] > ans? ans: n - m[''+prefix];
	}
	print(ans);
})();

(function () {
	var n = parseInt(readline());
	var line = readline().split(' ');
	var m = {};
	var prefix = 0;
	var ans = n - 1;
	//print(n);
	for(var idx in line){
		prefix += parseInt(line[idx]);
		//print(prefix);
		if(!m[prefix]) {
			m[prefix] = 1;
		} else {
			++m[prefix];
		}
		ans = n - m[prefix] > ans? ans: n - m[prefix];
	}
	print(ans);
})();


Gianni, SWERC's chief judge, received a huge amount of high quality problems from the judges and now he has to choose a problem set for SWERC.He received $$$n$$$ problems and he assigned a beauty score and a difficulty to each of them. The $$$i$$$-th problem has beauty score equal to $$$b_i$$$ and difficulty equal to $$$d_i$$$. The beauty and the difficulty are integers between $$$1$$$ and $$$10$$$. If there are no problems with a certain difficulty (the possible difficulties are $$$1,2,\dots,10$$$) then Gianni will ask for more problems to the judges.Otherwise, for each difficulty between $$$1$$$ and $$$10$$$, he will put in the problem set one of the most beautiful problems with such difficulty (so the problem set will contain exactly $$$10$$$ problems with distinct difficulties). You shall compute the total beauty of the problem set, that is the sum of the beauty scores of the problems chosen by Gianni.

Each test contains multiple test cases. The first line contains an integer $$$t$$$ ($$$1\le t\le 100$$$) — the number of test cases. The descriptions of the $$$t$$$ test cases follow. The first line of each test case contains the integer $$$n$$$ ($$$1\le n\le 100$$$) — how many problems Gianni received from the judges. The next $$$n$$$ lines contain two integers each. The $$$i$$$-th of such lines contains $$$b_i$$$ and $$$d_i$$$ ($$$1\le b_i, d_i\le 10$$$) — the beauty score and the difficulty of the $$$i$$$-th problem.

For each test case, print the total beauty of the problem set chosen by Gianni. If Gianni cannot create a problem set (because there are no problems with a certain difficulty) print the string MOREPROBLEMS (all letters are uppercase, there are no spaces).

NoteIn the first test case, Gianni has received only $$$3$$$ problems, with difficulties $$$3, 4, 7$$$ which are not sufficient to create a problem set (for example because there is not a problem with difficulty $$$1$$$).In the second test case, Gianni will create a problem set by taking the problems $$$2$$$, $$$3$$$, $$$4$$$, $$$5$$$, $$$7$$$, $$$8$$$, $$$9$$$, $$$10$$$, $$$11$$$ (which have beauty equal to $$$10$$$ and all difficulties from $$$1$$$ to $$$9$$$) and one of the problems $$$1$$$ and $$$6$$$ (which have both beauty $$$3$$$ and difficulty $$$10$$$). The total beauty of the resulting problem set is $$$10\cdot 9 + 3 = 93$$$.

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    let cnt=0;
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[++cnt]);
        let a=new Array(11);
        for(let i=0;i<=10;i++) a[i]=0;
        for(let i=1;i<=n;i++)
        {
            let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
            a[y]=Math.max(a[y],x);
        }
        let ans=0;
        flag=false;
        for(let i=1;i<=10;i++)
        {
            if(!a[i]) flag=true;
            ans+=a[i];
        }
        if(flag) console.log('MOREPROBLEMS');
        else console.log(ans);
    }
})

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    let cnt=0;
    for(let _=1;_<=t;_++)
    {
        let n=parseInt(line[++cnt]);
        let a=new Array(11);
        for(let i=0;i<=10;i++) a[i]=0;
        for(let i=1;i<=n;i++)
        {
            let [x,y]=line[++cnt].split(' ').map(x=>{return parseInt(x)});
            // console.log('z->',x,y);
            a[y]=Math.max(a[y],x);
        }
        // for(let i=1;i<=n;i++) console.log(a[i]);
        let ans=0;
        flag=false;
        for(let i=1;i<=10;i++)
        {
            if(!a[i]) flag=true;
            ans+=a[i];
        }
        if(flag) console.log('MOREPROBLEMS');
        else console.log(ans);
    }
})

'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, a) {
  const res = new Array(11).fill(-1);
  for (let [b, d] of a) {
    res[d] = Math.max(res[d], b);
  }
  let sum = 0;
  for (let i = 1; i < 11; i++) {
    if (res[i] === -1) {
      console.log('MOREPROBLEMS');
      return;
    }
    sum += res[i];
  }
  console.log(sum);
}

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

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


$$$n$$$ people gathered to hold a jury meeting of the upcoming competition, the $$$i$$$-th member of the jury came up with $$$a_i$$$ tasks, which they want to share with each other.First, the jury decides on the order which they will follow while describing the tasks. Let that be a permutation $$$p$$$ of numbers from $$$1$$$ to $$$n$$$ (an array of size $$$n$$$ where each integer from $$$1$$$ to $$$n$$$ occurs exactly once).Then the discussion goes as follows:  If a jury member $$$p_1$$$ has some tasks left to tell, then they tell one task to others. Otherwise, they are skipped.  If a jury member $$$p_2$$$ has some tasks left to tell, then they tell one task to others. Otherwise, they are skipped.  ...  If a jury member $$$p_n$$$ has some tasks left to tell, then they tell one task to others. Otherwise, they are skipped.  If there are still members with tasks left, then the process repeats from the start. Otherwise, the discussion ends. A permutation $$$p$$$ is nice if none of the jury members tell two or more of their own tasks in a row. Count the number of nice permutations. The answer may be really large, so print it modulo $$$998\,244\,353$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of the test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — number of jury members. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the number of problems that the $$$i$$$-th member of the jury came up with. The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer — the number of nice permutations, taken modulo $$$998\,244\,353$$$.

NoteExplanation of the first test case from the example:There are two possible permutations, $$$p = [1, 2]$$$ and $$$p = [2, 1]$$$. For $$$p = [1, 2]$$$, the process is the following:  the first jury member tells a task;  the second jury member tells a task;  the first jury member doesn't have any tasks left to tell, so they are skipped;  the second jury member tells a task. So, the second jury member has told two tasks in a row (in succession), so the permutation is not nice.For $$$p = [2, 1]$$$, the process is the following:  the second jury member tells a task;  the first jury member tells a task;  the second jury member tells a task. So, this permutation is nice.

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 MOD = 998244353;

const B = n => BigInt(n);
const N = n => Number(n);

function fact (n) {
	let res = 1;
	for (let i = 1; i <= n; i++) res = res * i % MOD;
	return res;
}

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

		a.sort((x, y) => x - y);

		let ans = 0;
		if (a[n-1] - a[n-2] == 0) {
			ans = fact(n);
		}
		if (a[n-1] - a[n-2] == 1) {
			let cnt = 0;
			for (let i = 0; i < n; i++) cnt += a[i] == a[n-2];
			let ways = 1;
			let juries = n - (cnt + 1);
			let spots = 1 + (cnt + 1);
			while (juries--) {
				ways = ways * spots % MOD, spots++;
			}
			ans = fact(n) - N(B(fact(cnt)) * B(ways) % B(MOD));
			ans = (MOD + ans) % MOD;
		}

		console.log(ans);
	}
}

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++]
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        console.log(solve(n, arr))
    }
// })()
})

function solve(n, arr) {
    const gs = arr.reduce((o, x) => {
        o[x] = (o[x] || 0) + 1
        return o
    }, {})
    const sorted = Object.keys(gs).map(Number)
        .sort((a, b) => b - a)
// console.log(gs, sorted)
    const all = fac(n)
    if (sorted.length < 2) return all

    const a = sorted[0]
    const b = sorted[1]
    if (gs[a] > 1) return all
    if (a > b + 1) return 0

    let ca = gs[a]
    let cb = gs[b]
    let cc = n - ca - cb

    let invalid = mul(fac(ca), fac(cb))
    for (let i = 1; i <= cc; i++) {
        invalid = mul(invalid, ca + cb + i)
    }
    let ans = add(all, -invalid)
    return add(ans, 998244353)
}

function add(a, b) {
    return (a + b) % 998244353
}
function mul(a, b) {
    const str = b.toString(2)
    let r = 0
    let base = a
    for (let i = str.length - 1; i >= 0; i--) {
        if (str[i] === '1') {
            r = add(r, base)
        }
        base = add(base, base)
    }
    return r
}
function fac(n) {
    let ans = 1
    for (let i = 2; i <= n; i++) {
        ans = mul(ans, i)
    }
    return ans
}

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 MOD = 998244353;

const B = n => BigInt(n);
const N = n => Number(n);

function fact (n) {
	let res = 1;
	for (let i = 1; i <= n; i++) res = res * i % MOD;
	return res;
}

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

		a.sort((x, y) => x - y);

		let ans = 0;
		if (a[n-1] - a[n-2] == 0) {
			ans = fact(n);
		}
		if (a[n-1] - a[n-2] == 1) {
			let cnt = 0;
			for (let i = 0; i < n; i++) cnt += a[i] == a[n-2];
			let ways = 1;
			let juries = n - (cnt + 1);
			let spots = 1 + (cnt + 1);
			while (juries--) {
				ways = ways * spots % MOD, spots++;
			}
			ans = fact(n) - N(B(fact(cnt)) * B(ways) % B(MOD));
		}

		console.log(ans);
	}
}

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 MOD = 998244353;

function fact (n) {
	let ans = 1;
	for (let i = 1; i <= n; i++)
		ans = ans * i % MOD;
	return ans;
}

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

		a.sort((x, y) => y - x);

		let ans = 2;
		if (a[0] - a[1] == 0) ans = fact(n);
		if (a[0] - a[1] == 1) {

			let k = 0;
			for (const vl of a) {
				k += vl == a[1];
			}

			for (let x = n - 1; x >= k; x--) {
				let prd = 1;
				for (let i = 0; i < k; i++) {
					prd = prd * (x - i) % MOD;
				}
				ans += prd * fact(n-k-1);
				ans %= MOD;
			}
			ans = (fact(n) - ans + MOD) % MOD;
		}

		console.log(ans);
	}
}

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 MOD = 998244353;

function fact (n) {
	let ans = 1;
	while (n) ans = (ans * n--) % MOD;
	return ans;
}

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

		a.sort((x, y) => x - y);

		let k = 0;
		for (const x of a) k += x == a[n-2];

		let ans = 0;
		if (a[n-1] == a[n-2]) ans = fact(n);
		if (a[n-1] == a[n-2] + 1) {
			let x = n - 1;
			while (x >= k) {
				let prd = 1;
				for (let j = 0; j < k; j++) {
					prd = prd * (x - j) % MOD;
				}

				ans = (ans + prd * fact(n-k-1)) % MOD;
				x--;
			}
			ans = (fact(n) - ans) % MOD;
		}

		console.log(ans);
	}
}

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 MOD = 998244353;

function fact (n) {
	let ans = 1;
	while (n) ans = (ans * n--) % MOD;
	return ans;
}

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

		a.sort((x, y) => x - y);

		let k = 0;
		for (const x of a) k += x == a[n-2];

		let ans = 0;
		if (a[n-1] == a[n-2]) ans = fact(n);
		if (a[n-1] == a[n-2] + 1) {
			let x = n - 1;
			while (x >= k) {
				ans = (ans + fact(x)/fact(x-k) * fact(n-k-1)) % MOD;
				x--;
			}
			ans = (fact(n) - ans) % MOD;
		}

		console.log(ans);
	}
}

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 MOD = 998244353;

function fact (n) {
	let ans = 1;
	while (n) ans = (ans * n--) % MOD;
	return ans;
}

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

		a.sort((x, y) => x - y);

		let cnt = 0;
		for (const x of a) cnt += x == a[n-2];

		let ans = 0;
		if (a[n-1] == a[n-2]) ans = fact(n);
		if (a[n-1] == a[n-2] + 1) ans = fact(n) * cnt / (cnt + 1) % MOD;

		console.log(ans);
	}
}

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++]
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        console.log(solve(n, arr))
    }
// })()
})

function solve(n, arr) {
    const gs = arr.reduce((o, x) => {
        o[x] = (o[x] || 0) + 1
        return o
    }, {})
    const sorted = Object.keys(gs).map(Number)
        .sort((a, b) => b - a)

    const all = fac(n)
    if (sorted.length < 2) return all

    const a = sorted[0]
    const b = sorted[1]
    if (a > b + 1) return 0

    let ca = gs[a]
    let cb = gs[b]
    let cc = n - ca - cb

    let invalid = mul(fac(ca), fac(cb))
    for (let i = 1; i <= cc; i++) {
        invalid = mul(invalid, ca + cb + i)
    }
    let ans = add(all, -invalid)
    return add(ans, 998244353)
}

function add(a, b) {
    return (a + b) % 998244353
}
function mul(a, b) {
    const str = b.toString(2)
    let r = 0
    let base = a
    for (let i = str.length - 1; i >= 0; i--) {
        if (str[i] === '1') {
            r = add(r, base)
        }
        base = add(base, base)
    }
    return r
}
function fac(n) {
    let ans = 1
    for (let i = 2; i <= n; i++) {
        ans = mul(ans, i)
    }
    return ans
}


Leo has developed a new programming language C+=. In C+=, integer variables can only be changed with a "+=" operation that adds the right-hand side value to the left-hand side variable. For example, performing "a += b" when a = $$$2$$$, b = $$$3$$$ changes the value of a to $$$5$$$ (the value of b does not change).In a prototype program Leo has two integer variables a and b, initialized with some positive values. He can perform any number of operations "a += b" or "b += a". Leo wants to test handling large integers, so he wants to make the value of either a or b strictly greater than a given value $$$n$$$. What is the smallest number of operations he has to perform?

The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 100$$$) — the number of test cases. Each of the following $$$T$$$ lines describes a single test case, and contains three integers $$$a, b, n$$$ ($$$1 \leq a, b \leq n \leq 10^9$$$) — initial values of a and b, and the value one of the variables has to exceed, respectively.

For each test case print a single integer — the smallest number of operations needed. Separate answers with line breaks.

NoteIn the first case we cannot make a variable exceed $$$3$$$ in one operation. One way of achieving this in two operations is to perform "b += a" twice.

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
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--) {
    let [a, b, target] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    let count = 0;
    let i = 0;
    while (a <= target || b <= target) {
      if (a > b) {
        b += a;
      } else {
        a += b;
      }
      count++;
      i++;
    }
    console.log(count - 1);
  }
}

//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');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
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 input = nextIntArray();
  	var N = input[2];
  	var min = Math.min(input[0], input[1]);
  	var max = Math.max(input[0], input[1]);
  	var count = 0;
  	while(N >= max){
  		min += max;
  		var tmp = max;
  		max = min;
  		min = tmp;
  		count++;
  	}
  	output[i] = count;
  }
  myout(myconv(output, 9));
}

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

let stdinInput = '';

process.stdin.on('data', input => {
  stdinInput += input;
})

process.stdin.on('end', () => {
  main(stdinInput);
})

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 1;
    let i = 1;
    while (i <= testCases) {
        const int = data[i].split(' ');
        let a = int[0] * 1;
        let b = int[1] * 1;
        const n = int[2] * 1;
        let count = 0;
        while (true) {
            if (a > n || b > n) {
                console.log(count);
                break;
            }
            a > b ? b += a : a += b;
            count += 1;
        }
        i += 1;
    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var input = '';
process.stdin.on('data', function (line) {
    input += line;
});
process.stdin.on('end', function () {
    var _a, _b;
    var lines = input.split('\n');
    var tests = parseInt(lines.shift(), 10);
    while (tests--) {
        var a = void 0, b = void 0, n = void 0;
        _a = lineToNumArray(lines.shift()), a = _a[0], b = _a[1], n = _a[2];
        var steps = 0;
        while (Math.max(a, b) <= n) {
            _b = [a + b, Math.max(a, b)], a = _b[0], b = _b[1];
            steps++;
        }
        console.log(steps);
    }
});
// input helper
function lineToNumArray(line) {
    return line.split(' ').map(function (element) { return parseInt(element, 10); });
}

const process = require('process')
let input = ''
process.stdin.on('data', data => input += data)
process.stdin.on('end', () => main(input))

function main(input) {
    let lines = input.trim().split('\n')
    let n = +lines[0]
    for(let i = 0; i < n; i++) {
        let [a, b, n] = lines[1 + i].split(' ')
        console.log(solution(+a, +b, +n))
    }
}

function solution(a, b, n) {
    if (a < b) return solution(b, a, n)
    // a >= b
    let i = 0
    for (; a <= n; i++) {
        let c = a + b
        b = a
        a = c
    }
    return i
}

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 => string.trim());

    main();
});

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

const s2i = s => parseInt(s, 10);

function main() {
  const T = s2i(readLine());
  for(let i = 0; i < T; i++) {
    let [a, b, n] = readLine().split(' ').map(s2i);

    if (a > b) [a, b] = [b, a];

    let ops = 0;

    while (b <= n) {
      [a, b] = [b, a + b];
      ops++;
    }

    console.log(ops);
  }
}

'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++];
}
/**
3 4
##..
##..
...#

**/

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

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

function main() {
    // let n = Number(readline());

    // let string = 'codeforces';

    // let s = 's'.repeat(BigInt.asIntN(n-1));

    // console.log(string + s);

    let n = parseInt(readline());

    for(let i=0;i<n;i++) {
        solve();
    }

}

function solve() {
    let [a, b, n] = readline().split(" ").map(Number);

    let x = Math.min(a, b);
    let y = Math.max(a, b);

    let count = 0;
    let sum = 0;

    while( sum <= n) {
        sum = x + y;

        if(count % 2 === 0) {
            x = sum;
        } else {
            y = sum;
        }

        count++;
    }

    console.log(count);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var inp = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var a = inp[0],
    b = inp[1],
    n = inp[2];
  var count = 0;
  while (Math.max(a, b) <= n) {
    if (a < b) {
      var temp = a;
      a = b;
      b = temp;
    }
    b += a;
    count++;
  }
  print(count);
}

"use strict";

//readline().split(' ').map(Number);

function sec(){
    var arr = readline().split(' ').map(Number);
    var a = Math.min(arr[0],arr[1]);
    var b = Math.max(arr[0],arr[1]);
    var aa = 1, bb = 1;
    var c = 1;
    while(aa * a + bb * b <= arr[2]){
        c++;
        bb = aa+bb;
        aa = bb-aa;
    }
    print(c);
}

function main(){
    var t = readline();
    while(t--){
        sec();
    }
}

main();

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; ++t) {
      var abn = read().split(' ').map(Number);
      var a = abn[0], b = abn[1], n = abn[2];
      var count = 0;
      while (a <= n && b <= n) {
         if (a < b) {
            a += b;
         } else {
            b += a;
         }
         count++;
      }
      write(count);
   }
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

      RL.on('line', (line) => {
         MEMORY.push(line);
      });

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

var count = +readline();

for(var index = 0; index < count; ++index) {
    var content = readline()
    var content = content.split(' ');
    var a = +content[0];
    var b = +content[1];
    var n = +content[2];

    var rounds = 0;

    if(a > n || b > n) {
        print("0");
    } else {
        while(a <= n && b <= n) {
            ++rounds;

            if(a + b > n) {
                a += b;
            } else {
                if(a < b) {
                    a += b;
                } else {
                    b += a;
                }
            }
        }
    }

    print('' + rounds + '\n');
}

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

const s2i = s => parseInt(s, 10);

function main() {
  const T = s2i(readLine());
  for(let i = 0; i < T; i++) {
    let [a, b, n] = readLine().split(' ').map(s2i);

    if (a < b) {
      const temp = a;
      a = b;
      b = temp;
    }

    let ops = 0;

    while (b <= n) {
      ops++;
      const sum = a + b;
      a = b;
      b = sum;
    }

    console.log(ops);
  }
}

'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++];
}
/**
3 4
##..
##..
...#

**/

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

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

function main() {
    // let n = Number(readline());

    // let string = 'codeforces';

    // let s = 's'.repeat(BigInt.asIntN(n-1));

    // console.log(string + s);

    let n = parseInt(readline());

    for(let i=0;i<n;i++) {
        solve();
    }

}

function solve() {
    let [a, b, n] = readline().split(" ").map(Number);

    a = Math.min(a, b);
    b = Math.max(a, b);

    let count = 0;
    let sum = 0;

    while( sum <= n) {
        sum = a + b;

        if(count % 2 === 0) {
            a = sum;
        } else {
            b = sum;
        }

        count++;
    }

    console.log(count);
}

'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 gcd(a, b) {
    if (!b) {
        return a;
    }

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

function main() {
    // let n = Number(readline());

    // let string = 'codeforces';

    // let s = 's'.repeat(BigInt.asIntN(n-1));

    // console.log(string + s);

    let n = parseInt(readline());

    for(let i=0;i<n;i++) {
        solve();
    }

}

function solve() {
    let [a, b, n] = readline().split(" ").map(Number);

    a = Math.min(a, b);
    b = Math.max(a, b);

    let count = 0;
    let sum = 0;

    while( b <= n || a <= n) {
        sum = a + b;

        if(a > b) {
            b = sum;
        } else {
            a = sum;
        }

        count++;
    }

    console.log(count - 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++];
}

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

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

function main() {
    // let n = Number(readline());

    // let string = 'codeforces';

    // let s = 's'.repeat(BigInt.asIntN(n-1));

    // console.log(string + s);

    let n = parseInt(readline());

    for(let i=0;i<n;i++) {
        solve();
    }

}

function solve() {
    let [a, b, n] = readline().split(" ").map(Number);

    a = Math.min(a, b);
    b = Math.max(a, b);

    let count = 0;
    let sum = 0;

    while( sum <= n) {
        sum = a + b;

        if(a > b) {
            b = sum;
        } else {
            a = sum;
        }

        count++;
    }

    console.log(count);
}

var count = +readline();

for(var index = 0; index < count; ++index) {
var content = readline()
var content = content.split(' ');
var a = +content[0];
var b = +content[1];
var n = +content[2];

var rounds = 0;

if(a > n || b > n) {
    print("0");
} else {
    while(a < n && b < n) {
        ++rounds;

        if(a + b > n) {
            a += b;
        } else {
            if(a < b) {
                a += b;
            } else {
                b += a;
            }
        }
    }
}

print('' + rounds + '\n');
}

var content = readline()
var content = content.split(' ');
var a = +content[0];
var b = +content[1];
var n = +content[2];

var rounds = 0;

if(a > n || b > n) {
    print("0");
} else {
    while(a < n && b < n) {
        ++round;

        if(a + b > n) {
            a += b;
        } else {
            if(a < b) {
                a += b;
            } else {
                b += a;
            }
        }
    }
}

print('' + rounds);