Let's call a positive integer $$$n$$$ ordinary if in the decimal notation all its digits are the same. For example, $$$1$$$, $$$2$$$ and $$$99$$$ are ordinary numbers, but $$$719$$$ and $$$2021$$$ are not ordinary numbers.For a given number $$$n$$$, find the number of ordinary numbers among the numbers from $$$1$$$ to $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case is characterized by one integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

For each test case output the number of ordinary numbers among numbers from $$$1$$$ to $$$n$$$.

var hotel = readline();

while(hotel--){
    var n = parseInt(readline());
    var cnt = 0;
    var noOfDigits = n.toString().length;
    for(var i=1; i<=noOfDigits; i++){
       var val = parseInt('1'.repeat(i));
       for(var j=1; j<=9; j++){
           var res = val*j;
           if(res >= 1 && res <= n) {
               cnt++;
           }
       }
    }
    print(cnt);
}

        var limit = parseInt(readline());
        for (var i = 0; i < limit; i++)
        {
         var value = parseInt(readline());
         var count = 0;
         for (var j = 1; j < 10; j++)
         {
          var current = j;
          while (current <= value)
          {
           count++;
           current = (current * 10) + j;
          }
         }
         print(count);
        }

var testcases = readline();
var count;

for(var k = 0 ; k < testcases ; k++) {
    var number = readline();
    count = 0;
    for (var i = 1; i <= number; i = i * 10 + 1) {
        for (var j = 1; j <= 9; j++) {
            if(i * j <= number) count++;
        }
    }
    print(count);
}

var T = parseInt(readline());
var values = [];
for(var i = 1; i <= 9; i++) {
    var ans = 0;
    while(ans < 1000000000) {
        ans = (ans * 10) + i;
        values.push(ans);
    }
}
while(T--) {
    var N = parseInt(readline());
    var ans = 0;
    for(var value of values) {
        if(value <= N) {
            ans++;
        }
    }
    print(ans);
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var s = readline();
  var len = s.length;
  var n = parseInt(s);

  var p = 0;
  var count = 0;
  for (var i = 0; i < len; i++) {
    p = p * 10 + 1;
    for (var j = 1; j <= 9; j++)
      if (p * j >= 1 && p * j <= n)
        count++;
  }
  print(count);
}

// 1520 B - Ordinary Numbers

// number of test case
var numTests = parseInt( readline() );

for (var numTest = 0; numTest < numTests; numTest++) {

    // input data
    var num = parseInt( readline() );

    // calculate number
    var n1 = 9 * ( num.toString().length -  1 );
    var n2 = num;
    var n3 = '1'.repeat( num.toString().length );

    var output = n1 + ( parseInt ( n2 / n3 ) );
    print( output );

}

t = parseInt(readline()) ;
while (t--) {
	n= readline();
	ans =  9 * ((n.length - 1 )) ;
	x  = parseInt(n);
	ds = "1" ;
	for (i = 1 ; i < n.length ; i ++ ) {
	    ds +='1' ;
	}
	new_x = parseInt(ds) ;
	for (i = 1 ; i <= 9 ; i++ ) {
	    if ((new_x * i )> x) break ;
	    ans ++ ;
	}
	print (ans);

}

var arr = [];
var tc = readline();
var sz;
function func(k, t) {
	var str = "";
	while (t--) str += k;
	return Number(str);
}
for (var i = 1; i <= 9; i++) {
	for (var j = 1; j <= 10; j++) {
		var str = func(i, j);
		arr.push(str);
	}
}
arr.sort(function (u, v) {
	return u - v;
});
sz=arr.length;
while (tc--) {
	var n = readline();
	var ans = 0;
	for (var i = 0; i < sz; i++) {
		if (arr[i] <= n) ans++;
		else break;
	}
	print(ans);
}

var t = +readline();

while (t--) {
  var n = +readline();
  var d = Math.floor(Math.log10(n)) + 1;
  var o = (d - 1) * 9; // ordinary numbers with less number of digits than n
  var firstOrdinary = (Math.pow(10, d) - 1) / 9;

  for(var i = 1; i < 10; i++) {
      if(n < firstOrdinary * i) {
          break;
      }
      o++;
  }
  print(o);
}

var numberOfCases = Number(readline());
for (var i = 0; i < numberOfCases; ++i) {
    processCase();
}

function processCase() {
    var limit = Number(readline());
    var limitStr = limit.toString();
    if (limit < 10) {
        return print(limit);
    }

    var numberOfFullDigits = limitStr.length - 1;

    var firstDigit = Number(limitStr[0]);
    var maxLesserBoringNumber = 0;
    for (var i = 0; i < limitStr.length; ++i) {
        maxLesserBoringNumber += firstDigit * Math.pow(10, i);
    }

    print(numberOfFullDigits * 9 + firstDigit - (limit >= maxLesserBoringNumber ? 0 : 1));
}

const t=parseInt(readline());

for(var j=0;j<t;j++)
{
    var n=parseInt(readline());
    var s=n.toString();
    var l=s.length;

    var ans=0;
    ans+=(l-1)*9;

    var fn=parseInt(s[0]);
    ans+=(fn-1);

    var ns='';

    for(var i=0;i<l;i++)
    {
        ns+=s[0];
    }

    var nn=parseInt(ns);
    //print(ns);

    if(nn<=n)
    {
        ans++;
    }

    print(ans);

}

var T = parseInt(readline());
while (T--) {
    var c = 0;
    var n = parseInt(readline());
	for (var x = 1; x <= n; x *= 10, ++x)
    	for (var y = x, z = 0; y <= n && z < 9; y += x, ++z)
    			++c;
    print(c); }

const readline = require('readline');

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

let input = [];

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

    if (input.length === +input[0] + 1) {
        rl.close();
        input.shift();
        main();
    }
});

function main() {
    input.forEach(item => ordinaryNumbers(item));
}

function ordinaryNumbers(item) {
    if (item.length === 1) {
        console.log(item);

    } else {
        let digits = item.length,
            ordinaryNumbers = 9 * (digits - 1),
            firstChar = item.charAt(0),
            ordinaryNumberWithFirstChar = firstChar.repeat(digits);

        ordinaryNumbers += Math.floor(+item / Math.pow(10, digits - 1)) - 1;

        if (item >= ordinaryNumberWithFirstChar) {
            console.log(++ordinaryNumbers);
        } else {
            console.log(ordinaryNumbers);
        }
    }
}

const readline = require('readline');

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

let input = [];

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

    if (input.length === +input[0] + 1) {
        rl.close();
        input.shift();
        main();
    }
});

function main() {
    input.forEach(item => ordinaryNumbers(item));
}

function ordinaryNumbers(item) {
    if (item.length === 1) {
        console.log(item);

    } else {
        let digits = item.length,
            ordinaryNumbers = 9 * (digits - 1),
            firstChar = item.charAt(0);

        ordinaryNumbers += Math.floor(+item / Math.pow(10, digits - 1));

        ordinaryNumberWithFirstChar = firstChar.repeat(digits);

        if (item >= ordinaryNumberWithFirstChar) {
            console.log(ordinaryNumbers);
        } else {
            console.log(--ordinaryNumbers);
        }
    }
}

const _mergeArrays = (a, b) => {
    const c = []

    while (a.length && b.length) {
      c.push(a[0] > b[0] ? b.shift() : a.shift())
    }

    //if we still have values, let's add them at the end of `c`
    while (a.length) {
      c.push(a.shift())
    }
    while (b.length) {
      c.push(b.shift())
    }

    return c
  }

  const mergeSort = (a) => {
    if (a.length < 2) return a
    const middle = Math.floor(a.length / 2)
    const a_l = a.slice(0, middle)
    const a_r = a.slice(middle, a.length)
    const sorted_l = mergeSort(a_l)
    const sorted_r = mergeSort(a_r)
    return _mergeArrays(sorted_l, sorted_r)
  }

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL); /*your input text, split by lines*/
    for(j =1 ; j<= lines[0]; j++){
        var a = lines[j]
        var b = 1
        var c = 0
        var d = 0
        for(l = 10; l <= a; l*=10){
            d = l - 1
            c += d /b
            b = b * 10 + 1
        }
        c += a/b
        console.log(Math.floor(c))
    }

});

//2 - 2 % 0 + 1
//2 - 2 % 0 - (0 - 1)

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    for(j = 1; j <= lines[0]; j++){
        var a = lines[j]
        var b = 1
        var c = 0
        var d = 0
        for(l = 10; l <= a; l*=10){
            d = l - 1
            c += d /b
            b = b * 10 + 1
        }
        c += a/ b
        console.log(Math.floor(c))
    }

});

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

let c = 0;
const answers = [];

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

  const n = Number(d);
  const len = d.length;
  let ans = Math.max(0, (len - 1) * 9);
  let inc = Number(String(1).repeat(len));

  for (let i = inc; i <= n; i += inc) {
    ans++;
  }

  answers.push(ans);

  // let answers = [];
  // let ans = 0;

  // for (let i = 1; i <= Number(d); i++) {
  //   if (new Set(String(i)).size === 1) {
  //     answers.push(i);
  //     ans++;
  //   }
  // }

  // console.log({ answers });
  // console.log({ ans });
  c++;
});

rl.on("close", () => {
  console.log(answers.join("\n"));
});

'use-strict'

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

        let testCases = parseInt(readLine());
        while(testCases--)
        {
            const n = parseInt(readLine());
            //const s = readLine();
            b(n);
        }

});

function print(c){
    return console.log(c);
}

function get_ints() {
    return readLine().split(' ').map(Number)
}

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

function a(n,s)
{
    let last = '';
        let solved = '';
        for(let i = 0 ; i < n; i++)
        {
            if(s[i] !== last && solved.includes(s[i]))
            {
                return console.log('NO');
            }
            solved += s[i];
            last = s[i];
        }
        return print('YES');
}

function b(n)
{
    // usiming every decimal add 9
    let d = n.toString()[0];
    let k = n.toString().length;
    let max = 0;
    for(let pw = 1; pw <= n; pw = pw * 10 + 1)
    {
        for(let d = 1; d <= 9; d++)
        {
            if(pw * d <= n)
            {
                max++
            }
        }
    }

    return print(max)

}

module.exports = b;

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let input = '';
process.stdin.on('data', inputStdin => {
    input += inputStdin;
});
process.stdin.on('end', _ => {
    main(input);
});

function main(input) {
    const args = input.split('\n');
    var v = [];
    var n = 1;
    for (var j = 1; j <= 9; j++) {
        for (var i = 1; i <= 9; i++) {
            v.push(i * n);
        }
        n *= 10;
        n += 1;
    }
    v.push(10 ** 9 + 1);
    const t = parseInt(args[0], 10);
    for (var i = 1; i <= t; i++) {
        const c = parseInt(args[i], 10);
        var j = 0;
        while (v[j] <= c) {
            j++;
        }
        console.log(j);
    }
}

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

function amountOfSameNums(inp){
  if(inp < 10) return inp

  let digits = String(inp).length,
      counter = (digits-1) * 9,
      divisor = '1'.repeat(digits);

  return counter + Math.floor(inp / divisor)

  //+ (Number( String(inp)[digits-1] ) || '');

  // for(var i=1, counter=0; i<=inp; i++){

  //   // count amount of digits 10-100  11 22 33 44 55 66 77 88 99
  //   100-1000 (3-4 symbols difference) 4-5 difference same 9 numbers to check
  //   11 22 33 44 55 66 77 88 99
  //   111 222 333 444 555 666 777 888 999
  //   if([...String(i)]
  //     ++counter
  //   }
}

rl.on('line', (input) => {
  if(initialized){ console.log( amountOfSameNums(input) ) }
  else initialized = true
});

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 = rl();

		const D = n.length;

		let flg = 0;
		for (const d of n) {
			if (d == n[0]) {
				continue;
			}
			if (d > n[0]) {
				break;
			}
			if (d < n[0]) {
				flg = 1;
				break;
			}
		}

		const ans = 9 * (D - 1) + Number(n[0]) - flg;

		console.log(ans)
	}
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var a = lines[j];
        var b = 1;
        var r = 0;
        var t = 0;
        for(l = 10; l <= Number(a); l*=10){
            t = l-1;
            r += t/b;
            b = b*10+1;
        }
        r += Number(a)/b;
        console.log(Math.floor(r));
    }

});

const readline = require('readline');

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

function amountOfSameNums(inp) {
    if (inp < 10) return inp;

    const digits = String(inp).length;
    const counter = (digits - 1) * 9;
    const divisor = '1'.repeat(digits);

    return counter + Math.floor(inp / divisor);
}

rl.on('line', (input) => {
    if (initialized) { console.log(amountOfSameNums(input)); } else initialized = true;
});

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        main()
        process.exit(0)
    }
})

function solve(n) {
    let r = n.toString().length
    let copy = n
    let temp = 0
    for (let i = 0; i < r - 1; i++) copy = Math.floor(copy / 10)
    if (n > 9) {
        for (let i = 0; i < r; i++) {
            temp += copy * (10 ** i)
        }
        if (n < temp) --copy
    }
    console.log((r - 1) * 9 + copy)

}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve(Number(inputArr[i]))
}

const isNum = (num) => {
	if (num < 10)
		return true;

	const str = `${num}`.split('');

	const set = new Set();
	for (let i=0; i<str.length; i++) {
		set.add(str[i]);
	}

	return set.size === 1;
}

const solve = (line) => {
	const n = +line;

	let counter = 0;
	for (let i=1; i<10; i++) {
		let num = `${i}`;
		while (+num <= n) {
			counter++;
			num += `${i}`;
		}
	}

	return counter;
}

let input = '';
process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	const [n, ...lines] = input.trim().split('\n')
		.map(l => l.trim());

	for (let i=0; i<n; i++) {
		console.log(solve(lines[i]))
	}
})

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

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

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

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

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

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

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

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

// ********** actual Code Starts from here **********
function buildNumber(n,digit){
    if(n==1){
        return parseInt(digit);
    }
    let ans = 0;
    while(n--){
        ans = ans*10+ digit;
    }

    return ans;
}

function solve() {

    let t = readSingleInt();
    let firstDigit ,ans ,targetNumber ,inputNumber,included;
    while(t--)
    {
        ans = 0;
        included = -1;
        let n =readLine();
        firstDigit = parseInt(n[0]);
        targetNumber = buildNumber(n.length,firstDigit);
        inputNumber = parseInt(n);
        if(inputNumber>=targetNumber){
            included = 0;
        }
        ans = (n.length-1) * 9 + (firstDigit) + included;
        console.log(ans);

    }

}

/**
 * Bismillahir Rahmanir Rahim
 * This code has been taken from: https://codeforces.com/blog/entry/69610
 */
 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++];
 }

 /****** BELOW HERE START WRITING YOUR CODE IN main() FUNCTION   ***************************************/
 /**
  * Use "readLine()" function for input, which will return a string consisting the entire line, so accordingly split the string
  * when required.
  *
  * I am using console.log() to output
  */
//  function main() {
//      let t = readLine();
//      t = parseInt(t);
//      console.log("mai yahan aaya")
//      while(t--) {
//          let line = readLine();
//          line = line.split(" ");
//          let n = parseInt(line[0]);
//          let m = parseInt(line[1]);
//          if(n === 1) {
//              console.log("0");
//          } else if (n === 2) {
//              console.log(m);
//          } else {
//              console.log(2*m);
//          }
//      }
//  }

function main() {

	let t = parseInt(readLine());
	// t = parseInt(t);
	while(t--) {
		let n = readLine();
		n = parseInt(n);
		//let s = readLine().split(" ").map(item=>parseInt(item));
		solve(n);

	}
    // console.log(t);
}

function solve(n) {
	let sol = 0 ;
	for (let i = 1; i <= 9; i++) {
		let j = i;
		while (j <= n) {
			sol++;
			j = j*10 + i;
		}
	}
	console.log(sol);
}

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	let t = nl.num();
    let ans = [];
    for(let i = 0; i < t; i++){
        ans.push(nl.num());
    }
    let numz = (n) => {
        let t = n;
        let cnt = 0;
        while(t >= 10){
            t /= 10;
            cnt++;
        }

        t = Math.trunc(t);
        let c = t;
        for(let i = 0; i < cnt; i++)  {
            c *= 10;
            c += t;
        }
        return cnt * 9  + ((c > n)?t - 1:t);
    }

	console.log(ans.map(numz).join("\n"));

};

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

const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
let input = [];
rl.on('line', line => {
    input.push(line);
})
rl.on('close', line => {
    var t = Number(input[0]);
    for (var a = 1; a < input.length; a++) {
        var n = Number(input[a]);
        var sum = 0;
        var count = 0;
        for (var i = 0; i <= 8; i++) {
            sum += 10 ** i;
            for (var j = 1; j <= 9; j++) {
                if (j * sum <= n) {
                    count++;
                }
            }
        }
        console.log(count);
    }
})

//////////////////////  Nodejs  Problem Solving /////////////////
/////////////////////* @author  Nawab Khairuzzaman Mohammad Kibria *////////

process.stdin.resume();
process.stdin.setEncoding("utf-8");
let currentLine = 0;
let inputString = "";
process.stdin.on("data", (raw_data) => {
  inputString += raw_data;
});

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

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

///////////////////////// END BASIC IO STREAM TEMPLATE //////////////////////

function main() {
  let t = readLine(Number);
  while (t--) {
    let n = readLine(Number);

    if (n < 10) {
      console.log(n);
    } else {
      let y;
      let x = n.toString().split("").map(Number);
      y = x[0];

      for (let i = 1; i < x.length; i++) {
        if (x[0] > x[i]) {
          y -= 1;
          break;
        }

        if (x[0] < x[i]) {
          break;
        }
      }

      console.log(x.length * 9 - (9 - y));
    }
  }
}

function findNumberOfDigts(N) {
    let count = 0;
    while (N) {
        count += 1;
        N = Math.floor(N / 10);
    }
    return count;
}

function solve(N) {
    const digits = findNumberOfDigts(N);
    let ans = (digits - 1) * 9;
    let b = 0;
    for (let i = 0; i < digits; i++) {
        b += Math.pow(10, i);
    }
    ans += Math.floor(N / b);
    return ans;
}

function processData(input) {
    //Enter your code here
    input = input.split('\n');
    const T = Number(input[0].trim());
    let i = 1;
    for (let t = 0; t < T; t++) {
        const N = Number(input[i++].trim());
        const ans = solve(N);
        console.log(ans);
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
    processData(_input);
});

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

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

function main() {
	let t = +readLine();
	while (t--) {
		const n = readLine();
		if (+n <= 9) console.log(n);
		else {
			let count = 9;
			const firstChar = n[0];
			const len = n.length;
			if (+n >= +firstChar.repeat(len)) count++;
			count += +firstChar - 1;
			count += (len - 2) * 9;
			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++];
}
/**
6
1
2
3
4
5
100

**/

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

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

function lcm(a, b) {
    return (a / gcd(a, b) * b);
}

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

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

}

function solve() {
    let n = Number(readline());

    let d = Math.log(n) + 1;
    let temp = 0;

    let ans = 0;

    for(let i=0;i<d;i++) {
        temp = temp * 10 + 1;
            for(let j=1;j<=9;j++) {
                if((temp * j) <= n) {
                    ans++;
                } else {
                    console.log(ans);
                    return;
                }
            }
    }

    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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var output = 0;
		var V = 1;
		var keta = 1;
		while(V <= N){
			output++;
			if(V % 10 != 9){
				V += (Math.pow(10, keta) - 1) / 9;
			}else{
				V = (Math.pow(10, keta + 1) - 1) / 9;
				keta++;
			}
		}
		myout(output);
	}
}

var hotel = readline();

while(hotel--){
    var n = parseInt(readline());
    var cnt = 0;
    if(n < 10) {
        print(n)
    }
    else {
        for(var i=10; i <= n; i++){
            var noOfDigits = i.toString().length;
            var divisor = '1'.repeat(noOfDigits);
            if(i%parseInt(divisor)===0){
                cnt++;
            }
        }
        print(cnt);
    }
}

var testcases = readline();
var count;

for(var i = 0 ; i < testcases ; i++) {
    var number = readline();
    if(number < 10){
        count = number;
    }
    if(number > 10){
        count = 9;
        for (var j = 10; j <= number; j++) {
            var flag = true;
            j = j.toString();
            for (var i = 1; i < j.length; i++) {
                if(j[i - 1] !== j[i]){
                    flag = false;
                    break;
                }
            }
            if(flag) count++;
        }
    }
    print(i);
}

var testcases = readline();
var count;

for(var i = 0 ; i < testcases ; i++) {
    var number = readline();
    if(number < 10){
        count = number;
    }
    if(number > 10){
        count = 9;
        for (var j = 10; j <= number; j++) {
            var flag = true;
            j = j.toString();
            for (var i = 1; i < j.length; i++) {
                if(j[i - 1] !== j[i]){
                    flag = false;
                    break;
                }
            }
            if(flag) count++;
        }
    }
    print(count);
}

var T = parseInt(readline());
var values = [];
for(var i = 1; i <= 9; i++) {
    var ans = 0;
    while(ans < 1000000) {
        ans = (ans * 10) + i;
        values.push(ans);
    }
}
while(T--) {
    var N = parseInt(readline());
    var ans = 0;
    for(var value of values) {
        if(value <= N) {
            ans++;
        }
    }
    print(ans);
}

const t = parseInt(readline());

for (var _ = 0; _ < t; _++) {
  var s = readline();
  var n = parseInt(s);
  var len = s.length - 1;
  var p = Math.pow(10, len);
  print(n % (p === 1? 10: p) + 9 * len);
}

const readline = require('readline');

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

let input = [];

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

    if (input.length === +input[0] + 1) {
        rl.close();
        input.shift();
        main();
    }
});

function main() {
    input.forEach(item => ordinaryNumbers(item));
}

function ordinaryNumbers(item) {
    let ordinaryNumbers = 1;
    let firstChar = item.charAt(0);

    for (let i = 1; i < item.length; ++i) {
        if (firstChar === item.charAt(i)) {
            ordinaryNumbers++;
        }
    }

    console.log(ordinaryNumbers);
}

const readline = require('readline');

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

let input = [];

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

    if (input.length === +input[0] + 1) {
        rl.close();
        input.shift();
        main();
    }
});

function main() {
    input.forEach(item => console.log(item));
}

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*/
    var s = 1
    var answer = 0
    for(j = 1; j <= lines[0]; j ++){
        var a = lines[j]
        for(k = 1; k < a; k++){
            var b = a.split('').sort(function(a, b){return a - b});
           for(c = 0 ; c < b.length; c++){
               if(b[c] == b[c - 1]){
                   answer++
               }else if(b[c + 1] === '') {
                   answer++
               }
           }
           s++
        }
        console.log(answer)
    }
});

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 [firstNumber, ...rest] = d;
  let ans = (d.length - 1) * 9;

  if (ans === 0) {
    console.log(d);
  } else {
    ans += Number(firstNumber) - 1;
    console.log(ans);
  }

  // let answers = [];
  // let ans = 0;

  // for (let i = 1; i <= Number(d); i++) {
  //   if (new Set(String(i)).size === 1) {
  //     answers.push(i);
  //     ans++;
  //   }
  // }

  // console.log({ answers });
  // console.log(ans);
  c++;
});

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

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 [firstNumber, ...rest] = d;
  let ans = (d.length - 1) * 9;

  if (ans === 0) {
    console.log(d);
  } else {
    ans += Number(firstNumber) - 1;
  }

  console.log(ans);

  // let answers = [];
  // let ans = 0;

  // for (let i = 1; i <= Number(d); i++) {
  //   if (new Set(String(i)).size === 1) {
  //     answers.push(i);
  //     ans++;
  //   }
  // }

  // console.log({ answers });
  // console.log(ans);
  c++;
});

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

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

  let ans = (d.length - 1) * 9;

  if (ans === 0) {
    console.log(d);
  } else {
    console.log(ans);
  }

  c++;
});

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

'use-strict'

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

let data = '';
let currentLine = 0;

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

process.stdin.on('end', () =>{
    data = data.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));

        let testCases = parseInt(readLine());
        while(testCases--)
        {
            const n = parseInt(readLine());
            //const s = readLine();
            b(n);
        }

});

function print(c){
    return console.log(c);
}

function get_ints() {
    return readLine().split(' ').map(Number)
}

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

function a(n,s)
{
    let last = '';
        let solved = '';
        for(let i = 0 ; i < n; i++)
        {
            if(s[i] !== last && solved.includes(s[i]))
            {
                return console.log('NO');
            }
            solved += s[i];
            last = s[i];
        }
        return print('YES');
}

function b(n)
{
    // usiming every decimal add 9
    let s = n.toString();
    let max = s.length * 9 - (9 - parseInt(s[0]));
    if(s[1] < s[0]) max--;
    return print(max)
}

module.exports = b;

'use strict';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
let input = '';
process.stdin.on('data', inputStdin => {
    input += inputStdin;
});
process.stdin.on('end', _ => {
    main(input);
});

function main(input) {
    const args = input.split('\n');
    var v = [];
    var n = 1;
    for (var j = 1; j <= 9; j++) {
        for (var i = 1; i <= 9; i++) {
            v.push(i * n);
        }
        n *= 10;
        n += 1;
    }
    v.push(10 ** 9);
    const t = parseInt(args[0], 10);
    for (var i = 1; i <= t; i++) {
        const c = parseInt(args[i], 10);
        var j = 0;
        while (v[j] <= c) {
            j++;
        }
        console.log(j);
    }
}

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

function amountOfSameNums(inp){
  if(inp < 10) return inp

  let digits = String(inp).length,
      counter = (digits-1) * 9 + (Number( String(inp)[digits-1] ) || '');
  // for(var i=1, counter=0; i<=inp; i++){

  //   // count amount of digits 10-100  11 22 33 44 55 66 77 88 99
  //   100-1000 (3-4 symbols difference) 4-5 difference same 9 numbers to check
  //   11 22 33 44 55 66 77 88 99
  //   111 222 333 444 555 666 777 888 999
  //   if([...String(i)]
  //     ++counter
  //   }

  return counter
}

rl.on('line', (input) => {
  if(initialized){ console.log( amountOfSameNums(input) ) }
  else initialized = true
});

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 = rl();

		const D = n.length;

		const dmin = Math.min(...n.split(''));

		const ans = 9 * (D - 1) + Number(n[0]) - (dmin == n[0] ? 0 : 1);

		console.log(ans)
	}
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    for(var j = 1; j <= n; j++){
        var a = lines[j];
        var b = 1;
        var r = 0;
        var t = 0;
        for(l = 10; l <= a; l*=10){
            t = l-1;
            r += t/b;
            b *= 10+1;
        }
        r += a/b;
        console.log(Math.floor(r));
    }

});

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        main()
        process.exit(0)
    }
})

function solve(n) {
    let count = 9
    if (n < 10) console.log(n)
    else console.log(9 + Math.floor(n / 11))

}

function main() {
    for (let i = 0; i < inputArr.length; i++) solve(Number(inputArr[i]))
}

const isNum = (num) => {
	if (num < 10)
		return true;

	const str = `${num}`.split('');

	const set = new Set();
	for (let i=0; i<str.length; i++) {
		set.add(str[i]);
	}

	return set.size === 1;
}

const solve = (line) => {
	const n = +line;

	let counter = 0;
	for (let i=1; i<10; i++) {
		let num = `${i}`;
		while (+num <= n) {
			counter++;
			num += `${i}`;
		}
	}

	return counter;
}

let input = '';
process.stdin.on('data', str => input += str)
process.stdin.on('end', () => {
	const lines = input.trim().split('\n').slice(1)
		.map(l => l.trim());

	console.time('time')
	for (let i=0; i<lines.length; i++) {
		console.log(solve(lines[i]))
	}
	console.timeEnd('time');
})


You are given two arrays $$$a$$$ and $$$b$$$ of $$$n$$$ positive integers each. You can apply the following operation to them any number of times:  Select an index $$$i$$$ ($$$1\leq i\leq n$$$) and swap $$$a_i$$$ with $$$b_i$$$ (i. e. $$$a_i$$$ becomes $$$b_i$$$ and vice versa). Find the minimum possible value of $$$\max(a_1, a_2, \ldots, a_n) \cdot \max(b_1, b_2, \ldots, b_n)$$$ you can get after applying such operation any number of times (possibly zero).

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1\le n\le 100$$$) — the length of the arrays. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$) where $$$a_i$$$ is the $$$i$$$-th element of the array $$$a$$$. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 10\,000$$$) where $$$b_i$$$ is the $$$i$$$-th element of the array $$$b$$$.

For each test case, print a single integer, the minimum possible value of $$$\max(a_1, a_2, \ldots, a_n) \cdot \max(b_1, b_2, \ldots, b_n)$$$ you can get after applying such operation any number of times.

NoteIn the first test, you can apply the operations at indices $$$2$$$ and $$$6$$$, then $$$a = [1, 4, 6, 5, 1, 5]$$$ and $$$b = [3, 2, 3, 2, 2, 2]$$$, $$$\max(1, 4, 6, 5, 1, 5) \cdot \max(3, 2, 3, 2, 2, 2) = 6 \cdot 3 = 18$$$.In the second test, no matter how you apply the operations, $$$a = [3, 3, 3]$$$ and $$$b = [3, 3, 3]$$$ will always hold, so the answer is $$$\max(3, 3, 3) \cdot \max(3, 3, 3) = 3 \cdot 3 = 9$$$.In the third test, you can apply the operation at index $$$1$$$, then $$$a = [2, 2]$$$, $$$b = [1, 1]$$$, so the answer is $$$\max(2, 2) \cdot \max(1, 1) = 2 \cdot 1 = 2$$$.

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

var T = readline();
for(var q=1;q<=T;q++) {
            var g = readline();
            var a = readline().split(" ").map(w => parseInt(w))
            var b = readline().split(" ").map(w => parseInt(w))
            var max = []
            var min = []
            for(var i=0;i<a.length;i++) {
                max[i]=Math.max(a[i],b[i])
                min[i]=Math.min(a[i],b[i])
            }
            var mx = max[0]
            var mn = min[0]
            for(var i=0;i<a.length;i++) {
                mx=Math.max(mx,max[i])
                mn=Math.max(mn,min[i])
            }
            console.log(mx*mn)
}

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});
process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0]);
  let i = 1;
  while (t--) {
    let n = parseInt(lines[i++]);
    let a = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    let b = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    let index = a.indexOf(Math.max(...a));
    while (a[index] > b[index]) {
      let temp = a[index];
      a[index] = b[index];
      b[index] = temp;
      index = a.indexOf(Math.max(...a));
    }
    index = b.indexOf(Math.max(...b));
    while (b[index] > a[index]) {
      let temp = a[index];
      a[index] = b[index];
      b[index] = temp;
      index = b.indexOf(Math.max(...b));
    }
    console.log(Math.max(...a) * Math.max(...b));
  }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    var a = 0;
    for(i = 1; i <= t * 3; i++){
        if(i % 3 == 1){
            n = lines[i];
        }else if(i % 3 == 2){
            a = lines[i].split(' ').map(Number);
        }else{
            var b = lines[i].split(' ').map(Number);
            var ans = 0;
            for(j = 0; j < n; j++){
                if(b[j] > a[j]){
                    var temp = b[j];
                    b[j] = a[j];
                    a[j] = temp;
                }
            }
            a.sort(function(a, b){return b - a});
            b.sort(function(a, b){return b - a});
            console.log(a[0] * b[0]);
        }
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

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

        for (let i = 0; i < n; i++) {
            if (arr[i] > brr[i]) {
                [arr[i], brr[i]] = [brr[i], arr[i]];
            }
        }

        let f = Math.max(...arr);
        let s = Math.max(...brr);

        output(f * s);
    }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var alist = nextIntArray(N);
		var blist = nextIntArray(N);
		for(var i = 0; i < N; i++){
			if(alist[i] < blist[i]){
				var tmp = alist[i];
				alist[i] = blist[i];
				blist[i] = tmp;
			}
		}
		alist.sort(function(a,b){
			return b - a;
		});
		blist.sort(function(a,b){
			return b - a;
		});
		myout(alist[0] * blist[0]);
	}
}

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let j = 0 ; j < t; j++) {
		let n = nl.num();
		let a = nl.nums();
		let b = nl.nums();
		for(let i = 0; i < n; i++){
			if (a[i] > b[i]) {
				[a[i], b[i]] = [b[i], a[i]];
			}
		}
		ans.push(Math.max(...a) * Math.max(...b));
	}
	console.log(ans.join('\n'));
};

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

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

let inputString = '';

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

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

    main(inputString);
});

function log(message){
    if(process.env.NODE_ENV === "debug"){
        console.log(message);
    }
}

// function main(fileContents) {//input lines as an array
//     // console.log(fileContents);
//     fileContents.splice(0,1);
//     for(let i = 0; i < fileContents.length; i+=3){
//         const line1 = fileContents[i+1].split(" ")
//         const line2 = fileContents[i+2].split(" ")
//         // console.log("line1: ",line1,"line2: ",line2)
//         let max = line1[0]*line2[0];
//
//         for(let x = 0; x < line1.length; x++){
//             max= Math.max(max,line1[x]*line2[x])
//         }
//
//         console.log(max)
//     }
// }

function main(fileContents) {//input lines as an array
    // console.log(fileContents);
    fileContents.splice(0,1);
    for(let i = 0; i < fileContents.length; i+=3){
        const small = fileContents[i+1].split(" ")
        const big = fileContents[i+2].split(" ")

        for(let x = 0; x < small.length; x++){
            const smallBuff = Math.min(small[x],big[x]);
            const bigBuff = Math.max(small[x],big[x]);

            small[x] = smallBuff;
            big[x] = bigBuff;
        }

        // console.log("small",small,"big",big)
        console.log(Math.max(...small)*Math.max(...big))
    }
}

// your code goes here
var total = parseInt(readline());

for(var i = 0; i < total; i++) {
	var count = parseInt(readline());
	var a = readline().split(" ").map(x => parseInt(x));
	var b = readline().split(" ").map(x => parseInt(x));

	var maxa = 1;
	var maxb = 1;
	for(var j = 0; j < count; j++) {
		if(a[j] < b[j]) {
			var temp = a[j];
			a[j] = b[j];
			b[j] = temp;
		}

		maxa = Math.max(maxa, a[j]);
		maxb = Math.max(maxb, b[j]);
	}

	print(maxa*maxb);
}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var g = readline();
            var a = readline().split(" ").map(w => parseInt(w))
            var b = readline().split(" ").map(w => parseInt(w))
            a.sort(function(ar,br) { return ar-br })
            b.sort(function(ar,br) { return ar-br })
            var g = 'b';
            var ans = a[a.length-1]*b[b.length-1]
            for(var i=0;i<a.length;i++) {
            	if(a[i]>b[i]) {
            		g='a';
            		break;
            	}
            	else if(b[i]>a[i]) {
            		g='b';
            		break;
            	}
            }
            if(g == 'b') {
            	var maxb = b[0]
            	for(var i=0;i<a.length;i++) {
            		if(a[i] > b[0]) {
            			break;
            		} else {
            			maxb = Math.max(b[i], maxb);
            		}
            	}
                ans = Math.min(ans, a[a.length-1]*maxb)
            }
            else if(g =='a') {
            	var maxa = a[0]
            	for(var i=0;i<b.length;i++) {
            		if(b[i] <= a[0]) {
            			maxa = Math.max(maxa, a[i])
            		} else {
            		    break;
            		}
            	}
            	ans = Math.min(ans, b[b.length-1]*maxa)
            }
            console.log(ans)
}

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});
process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0]);
  let i = 1;
  while (t--) {
    let n = parseInt(lines[i++]);
    let a = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    let b = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    if (Math.max(...a) > Math.max(...b)) {
      let index = b.indexOf(Math.max(...b));
      while (a[index] < b[index]) {
        let temp = a[index];
        a[index] = b[index];
        b[index] = temp;
        index = b.indexOf(Math.max(...b));
      }
    } else {
      let index = a.indexOf(Math.max(...a));
      while (a[index] > b[index]) {
        let temp = a[index];
        a[index] = b[index];
        b[index] = temp;
        index = b.indexOf(Math.max(...b));
      }
    }
    console.log(Math.max(...a) * Math.max(...b));
  }
});


Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.

The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).

Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them.

NoteIn the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.

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

rl.on('line', (d) => {
  const [n, k] = d.split(' ').map(Number);
  const matrix = new Array(n).fill(0).map(x => new Array(n).fill(0));
  let idx = 0;
  for (let i = 0; i < matrix.length; i++) {
    matrix[i][idx] = k;
    idx++;
  }

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

  c++;
});

print(function(n, k) {

	var ans = [];
	for (var i = 0; i < n; i++) {
		ans[i] = [];
		for (var j = 0; j < n; j++)
			ans[i][j] = i === j ? k : 0;
	}

	return ans.map(function(v) {
		return v.join(' ');
	}).join('\n');

} .apply(0, readline().split(' ').map(Number)));

;(function () {

	print((function (n, k) {
		var ret = [], t = [];
		for (var i = 0; i < n; i++) t.push(0);
		t[0] = k; ret.push(t.join(' '));
		for (var i = 1; i < n; i++) {
			t[i - 1] = 0; t[i] = k;
			ret.push(t.join(' '));
		}
		return ret.join('\n');
	}).apply(this, readline().split(' ').map(Number)));

}).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]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var n = integers[0], sum = integers[1];

	for (var r = 0; r < n; ++r) {
		var row = [];
		for (var c = 0; c < n; ++c) {
			row.push(c == r ? sum : 0);
		}
		print(row.join(" "));
	}
}

main();


You are given a positive integer $$$n$$$. In one move, you can increase $$$n$$$ by one (i.e. make $$$n := n + 1$$$). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of $$$n$$$ be less than or equal to $$$s$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$n$$$ and $$$s$$$ ($$$1 \le n \le 10^{18}$$$; $$$1 \le s \le 162$$$).

For each test case, print the answer: the minimum number of moves you need to perform in order to make the sum of digits of $$$n$$$ be less than or equal to $$$s$$$.

let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, cb) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = cb(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = cb(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, cb) {
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb(i + a));
  return Array(a - b + 1).fill(0).map((v, i) => cb ? cb(a - i) : a - i);
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}

function max(a, b) {
  if (a > b) return a;
  return b;
}

(async () => {
  await inputPromise;
  let inp = input.split(/\D+/); r = 0;
  let t = +inp[r++];
  For(1, t, i => {
    let [n, s] = inp.slice(r, r = r + 2);
    let n0 = n;
    n = [...n];
    s = +s;
    let sum = eval(n.join('+'));
    while (sum > s) {
      let d = Arr(n.length - 1, 0).find(v => n[v] != 0);
      n[d--] = 0;
      while (1) {
        if (d < 0) {
          n = [1, ...n];
          break;
        }
        n[d]++;
        if (n[d] < 10) break;
        n[d--] = 0;
      }
      sum = eval(n.join('+'));
    }
    console.log(BigInt(n.join('')) - BigInt(n0) + '')
  })
})();

let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

function For(a, b, cb) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = cb(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = cb(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, cb) {
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb(i + a));
  return Array(a - b + 1).fill(0).map((v, i) => cb ? cb(a - i) : a - i);
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}

function max(a, b) {
  if (a > b) return a;
  return b;
}

(async () => {
  await inputPromise;
  let inp = input.split(/\D+/); r = 0;
  let t = +inp[r++];
  For(1, t, i => {
    let [n, s] = inp.slice(r, r = r + 2);
    let n0 = n;
    n = [0, ...n].map(v => +v);
    s = +s;
    let sum = n.sum();
    while (sum > s) {
      let d = Arr(n.length - 1, 0).find(v => n[v] != 0);
      while (1) {
        n[d--] = 0;
        n[d]++;
        if (n[d] < 10) break;
      }
      sum = n.sum();
    }
    console.log(BigInt(n.join('')) - BigInt(n0) + '')
  })
})();


Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back w tokens then he'll get  dollars. Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has n numbers x1, x2, ..., xn. Number xi is the number of tokens given to each worker on the i-th day. Help him calculate for each of n days the number of tokens he can save.

The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109).

Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day.

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

var n = line[0];
var a = line[1];
var b = line[2];

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

for (var i = 0; i < n; i++) {
    write(Math.floor(((line[i] * a) % b) / a));
    write(' ');
}

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '')
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function integers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) tokens[i]=parseInt(tokens[i]);
    return tokens;
}
function main() {
    var data = integers(readline())
    var n = data[0];
    var a = data[1];
    var b = data[2];
    var d = integers(readline());
    var res = [];
    for(var i=0; i<d.length; ++i) {
        var r = Math.floor(((d[i]*a)%b)/a);
        res.push(r);
    }
    print(res.join(" "));
}
main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function tokenizeIntegers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) tokens[i]=parseInt(tokens[i]);
    return tokens;
}
function main() {
    var data=tokenizeIntegers(readline())
    var numDays=data[0], p=data[1], q=data[2];
    var tokensPerDay=tokenizeIntegers(readline());
    var results = [];
    for(var dayIndex=0; dayIndex<numDays; ++dayIndex) {
        var tokens=tokensPerDay[dayIndex];
        var result = Math.floor(((p*tokens)%q)/p);
        results.push(result);
    }
    print(results.join(" "));
}

main();

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '');
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function tokenizeIntegers(s) {
    var tokens=tokenize(s);
    for(var i=0; i<tokens.length; ++i) {
        tokens[i]=parseInt(tokens[i]);
    }
    return tokens;
}
function main() {
    var data = tokenizeIntegers(readline());
    var numDays = data[0], p = data[1], q=data[2];
    var tokensPerDay=tokenizeIntegers(readline());
    var results = [];
    for(var dayIndex = 0; dayIndex < numDays; ++dayIndex) {
        var tokens=tokensPerDay[dayIndex];
        var result = Math.floor(((p*tokens)%q)/p);
        results.push(result);
    }
    print(results.join(" "));
}
main();

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

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

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

function main() {
	var data = tokenizeIntegers(readline());
	var numDays = data[0], p = data[1], q = data[2];

	var tokensPerDay = tokenizeIntegers(readline());
	var results = [];

	for (var dayIndex = 0; dayIndex < numDays; ++dayIndex) {
		var tokens = tokensPerDay[dayIndex];
		var result = Math.floor( ((p*tokens) % q) / p );
		results.push(result);
	}

	print(results.join(" "));
}

main();

var pa = readline().split(' ').map(function(x){return parseInt(x);});
write(readline().split(' ').map(function(x){return parseInt(((parseInt(x) * pa[1]) % pa[2]) / pa[1]);}).join(' '));

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '')
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function integers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) tokens[i]=parseInt(tokens[i]);
    return tokens;
}
function main() {
    var data = integers(readline())
    var n = data[0];
    var a = data[1];
    var b = data[2];
    var d = integers(readline());
    var res = [];
    for(var i=0; i<d.length; ++i) {
        var r = Math.floor(d[i]*a%b/b);
        res.push(r);
    }
    print(res.join(" "));
}

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) {
          tokens[i]=parseInt(tokens[i]);
     }
     return tokens;
}
function main() {
    var data = tokenizeIntegers(readline())
    var n = data[0];
    var a = data[1];
    var b = data[2];
    var d = tokenizeIntegers(readline());
    var res = [];
    for(var i=0; i<d.length; ++i) {
        var r = Math.floor(d[i]*a%b/a);
        res.push(r);
    }
    print(res.join(" "));
}

function trim(s) {
    return s.replace(/^\s+|\s+$/gm, '')
}
function tokenize(s) {
    return trim(s).split(/\s+/);
}
function integers(s) {
    var tokens = tokenize(s);
    for(var i=0; i<tokens.length; ++i) tokens[i]=parseInt(tokens[i]);
    return tokens;
}
function main() {
    var data = integers(readline())
    var n = data[0];
    var a = data[1];
    var b = data[2];
    var d = integers(readline());
    var res = [];
    for(var i=0; i<d.length; ++i) {
        var r = Math.floor(d[i]*a%b/a);
        res.push(r);
    }
    print(res.join(" "));
}

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]);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline());
	var numDays = data[0], p = data[1], q = data[2];

	var tokensPerDay = tokenizeIntegers(readline());
	var results = [];

	for (var dayIndex = 0; dayIndex < numDays; ++dayIndex) {
		var tokens = tokensPerDay[dayIndex];
		var result = (p*tokens) % q;
		results.push(result);
	}

	print(results.join(" "));
}

main();

var pa = readline().split(' ').map(function(x){return parseInt(x);});
write(readline().split(' ').map(function(x){return (parseInt(x) * pa[1]) % pa[2];}).join(' '));


Haha, try to solve this, SelectorUnlimited!— antontrygubO_oYour friends Alice and Bob practice fortune telling.Fortune telling is performed as follows. There is a well-known array $$$a$$$ of $$$n$$$ non-negative integers indexed from $$$1$$$ to $$$n$$$. The tellee starts with some non-negative number $$$d$$$ and performs one of the two operations for each $$$i = 1, 2, \ldots, n$$$, in the increasing order of $$$i$$$. The possible operations are: replace their current number $$$d$$$ with $$$d + a_i$$$ replace their current number $$$d$$$ with $$$d \oplus a_i$$$ (hereinafter $$$\oplus$$$ denotes the bitwise XOR operation)Notice that the chosen operation may be different for different $$$i$$$ and for different tellees.One time, Alice decided to start with $$$d = x$$$ and Bob started with $$$d = x + 3$$$. Each of them performed fortune telling and got a particular number in the end. Notice that the friends chose operations independently of each other, that is, they could apply different operations for the same $$$i$$$.You learnt that either Alice or Bob ended up with number $$$y$$$ in the end, but you don't know whose of the two it was. Given the numbers Alice and Bob started with and $$$y$$$, find out who (Alice or Bob) could get the number $$$y$$$ after performing the operations. It is guaranteed that on the jury tests, exactly one of your friends could have actually gotten that number.HacksYou cannot make hacks in this problem.

On the first line of the input, you are given one number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The following $$$2 \cdot t$$$ lines contain test cases. The first line of each test case contains three numbers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \le n \le 10^5$$$, $$$0 \le x \le 10^9$$$, $$$0 \le y \le 10^{15}$$$) — the length of array $$$a$$$, Alice's initial number (Bob's initial number is therefore $$$x+3$$$), and the number that one of the two friends got in the end. The second line of each test case contains $$$n$$$ numbers — the array $$$a$$$ ($$$0 \le a_i \le 10^9$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print the name of the friend who could get the number $$$y$$$: "Alice" or "Bob".

NoteIn the first test case, Alice could get $$$9$$$ using the following operations: $$$7 + 2 = 9$$$.In the second test case, Alice could get $$$2$$$ using this operations: $$$(0 + 1) \oplus 3 = 2$$$.In the third test case, Bob started with $$$x+3 = 0+3=3$$$ and could get $$$1$$$ this way: $$$(((3 + 1) + 2) \oplus 3) \oplus 4 = 1$$$.

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;
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

function main () {
	let T = rn();
	while (T--) {
		const [n, x, y] = rna();
		const a = rna();

		let k = x&1;
		for (let i = 0; i < n; i++) {
			k = k ^ a[i]&1;
		}

		console.log(k == (y&1) ? 'Alice' : 'Bob');
	}
}

Array(parseInt(readline())).fill().forEach(() => ((n, x, y) => print(['Alice',  'Bob'][(readline().split(' ').map(Number).reduce((a, b) => a ^ b, 0) ^ x ^ y) & 1]))(...readline().split(' ').map(Number)))

Array(parseInt(readline())).fill().forEach(() => ((n, x, y) => print(['Alice', 'Bob'][(readline().split(' ').map(Number).reduce((a, b) => a ^ b, 0) ^ x ^ y) & 1]))(readline().split(' ').map(Number)))

Array(parseInt(readline())).fill().forEach(() => ((n, x, y) => ['Alice', 'Bob'][(readline().split(' ').map(Number).reduce((a, b) => a ^ b, 0) ^ x ^ y) & 1])(readline().split(' ').map(Number)))


You are given an array $$$a$$$ of length $$$n$$$. We define the equality of the array as the number of indices $$$1 \le i \le n - 1$$$ such that $$$a_i = a_{i + 1}$$$. We are allowed to do the following operation:  Select two integers $$$i$$$ and $$$x$$$ such that $$$1 \le i \le n - 1$$$ and $$$1 \le x \le 10^9$$$. Then, set $$$a_i$$$ and $$$a_{i + 1}$$$ to be equal to $$$x$$$. Find the minimum number of operations needed such that the equality of the array is less than or equal to $$$1$$$.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10 ^ 5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10 ^ 5$$$

For each test case, print the minimum number of operations needed.

NoteIn the first test case, we can select $$$i=2$$$ and $$$x=2$$$ to form $$$[1, 2, 2, 1, 1]$$$. Then, we can select $$$i=3$$$ and $$$x=3$$$ to form $$$[1, 2, 3, 3, 1]$$$.In the second test case, we can select $$$i=3$$$ and $$$x=100$$$ to form $$$[2, 1, 100, 100, 2]$$$.

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

let ls = [];

function solve() {
    let l = 0;
    const t = parseInt(ls[l++]);
    for (let q = 0; q < t; q++){
        const n = parseInt(ls[l++]);
        const a = ls[l++].split(' ').map(it => parseInt(it));

        let lr = -1;
        for (let i = 0 ; i < n - 1; i++){
            if (a[i] == a[i + 1]){
                lr = i;
                break;
            }
        }

        let rr = -1;
        for (let i = n - 2; i >= 0; i--){
            if (a[i] == a[i + 1]){
                rr = i;
                break;
            }
        }

        if (lr == -1 || lr == rr|| a.length == 2){
            console.log(0);
        }
        else{
            console.log(Math.max(1, (rr - lr - 1)));
        }

    }
}

rl.on('line', (l) => ls.push(l));
rl.on('close', () => solve());

'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) {
  let first = -1,
      last = -1;
  for (let i = 0; i < n; i++) {
    if (first === -1 && a[i] === a[i - 1]) {
      first = i;
    }
    if (a[i] === a[i + 1]) {
      last = i;
    }
  }
  if (first === -1 || last < first) {
    console.log(0);
  } else {
    console.log(Math.max(1, last - first));
  }
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    const n = Number(await read());
    const a = (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);
}();

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

let ls = [];

function solve() {
    let l = 0;
    const t = parseInt(ls[l++]);
    for (let q = 0; q < t; q++){
        const n = parseInt(ls[l++]);
        const a = ls[l++].split(' ').map(it => parseInt(it));

        let lr = -1;
        for (let i = 0 ; i < n - 1; i++){
            if (a[i] == a[i + 1]){
                lr = i;
                break;
            }
        }

        let rr = -1;
        for (let i = n - 2; i >= 0; i--){
            if (a[i] == a[i + 1]){
                rr = i;
                break;
            }
        }

        if (lr == -1 || a.length == 2){
            console.log(0);
        }
        else{
            console.log(Math.max(1, (rr - lr - 1)));
        }

    }
}

rl.on('line', (l) => ls.push(l));
rl.on('close', () => solve());

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

let ls = [];

function solve() {
    let l = 0;
    const t = parseInt(ls[l++]);
    for (let q = 0; q < t; q++){
        const n = parseInt(ls[l++]);
        const a = ls[l++].split(' ').map(it => parseInt(it));

        let lr = -1;
        for (let i = 1 ; i < n; i++){
            if (a[i] == a[i - 1]){
                lr = i;
                break;
            }
        }

        let rr = -1;
        for (let i = n - 2; i >= 0; i--){
            if (a[i] == a[i + 1]){
                rr = i;
                break;
            }
        }

        if (lr == -1 || a.length == 2){
            console.log(0);
        }
        else if (lr == rr){
            console.log(1);
        }
        else{
            console.log(rr - lr);
        }
    }
}

rl.on('line', (l) => ls.push(l));
rl.on('close', () => solve());

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

let ls = [];

function solve() {
    let l = 0;
    const t = parseInt(ls[l++]);
    for (let q = 0; q < t; q++){
        const n = parseInt(ls[l++]);
        const a = ls[l++].split(' ').map(it => parseInt(it));

        let lr = -1;
        for (let i = 1 ; i < n; i++){
            if (a[i] == a[i - 1]){
                lr = i;
                break;
            }
        }

        let rr = -1;
        for (let i = n - 2; i >= 0; i--){
            if (a[i] == a[i + 1]){
                rr = i;
                break;
            }
        }

        if (lr == -1){
            console.log(0);
        }
        else if (lr == rr){
            console.log(1);
        }
        else{
            console.log(rr - lr);
        }
    }
}

rl.on('line', (l) => ls.push(l));
rl.on('close', () => solve());

'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, b) {
  const map = new Map();
  for (let i = 0; i < n; i++) {
    if (!map.has(a[i])) map.set(a[i], []);
    map.get(a[i]).push(i);
  }
  const flag = new Array(n).fill(0);
  new Array(n).fill(-1);
  const hasIndex = (i, j) => {
    let arr = map.get(i);
    while (arr.length && arr[arr.length - 1] > j) {
      arr.pop();
    }
    return !!arr.length;
  };
  for (let i = n - 1, j = n - 1; i >= 0; i--) {
    if (flag[j]) {
      if (!hasIndex(b[i], j - 1)) {
        console.log('NO');
        return;
      }
      while (flag[j] && b[i] !== a[j]) {
        j--;
      }
      if (a[j] !== b[i]) {
        console.log('NO');
        return;
      }
      if (flag[j]) {
        const k = map.get(b[i]).pop();
        flag[k] = 1;
      }
      j--;
    } else {
      if (a[j] !== b[i]) {
        if (!hasIndex(b[i], j - 1) || b[i] !== a[j + 1]) {
          console.log('NO');
          return;
        }
        const k = map.get(b[i]).pop();
        flag[k] = 1;
      } else {
        j--;
      }
    }
  }
  console.log('YES');
}

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

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


Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit left.  An 'R' indicates he should move one unit right.  A 'U' indicates he should move one unit up.  A 'D' indicates he should move one unit down.But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.

The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given.

If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.

NoteIn the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.

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

function counter (ch) {
    return function (total, x) {
        if (x === ch) {
            return total + 1;
        }
        return total;
        }
}

var pathL = path.reduce(counter('L'), 0);

var pathR = path.reduce(counter('R'), 0);

var pathU = path.reduce(counter('U'), 0);

var pathD = path.reduce(counter('D'), 0);

if (path.length % 2 !== 0) {
    print(-1);
} else if (pathL === pathR && pathU === pathD) {
    print(0);
} else {
    print((Math.abs(pathL - pathR) + Math.abs(pathU - pathD)) / 2);
}

var s = readline();
var solution = function ( s ) {
  if ( s.length%2 != 0 ) {
    return -1;
  }
  var step = function ( coord, c ) {
    switch ( c ) {
      case "L":
        --coord.x;
        break;
      case "R":
        ++coord.x;
        break;
      case "U":
        ++coord.y;
        break;
      case "D":
        --coord.y;
        break;
    }
    return coord;
  };
  var destination = [...s].reduce( ( coord, c ) => step( coord, c ), { x: 0, y: 0 } );
  var manhattanDistance = Math.abs( destination.x ) + Math.abs( destination.y );
  return manhattanDistance / 2;
};
print( solution( s ) );

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

function counter (ch) {
    return function (total, x) {
        if (x === 'L') {
            return total + 1;
        }
        return total;
        }
}

var pathL = path.reduce(counter('L'), 0);

var pathR = path.reduce(counter('R'), 0);

var pathU = path.reduce(counter('U'), 0);

var pathD = path.reduce(counter('D'), 0);

if (path.length % 2 !== 0) {
    print(-1);
} else if (pathL === pathR && pathU === pathD) {
    print(0);
} else {
    print(Math.abs(pathL - pathR) / 2 + Math.abs(pathU - pathD) / 2);
}

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

function counter (ch) {
    return function (total, x) {
        if (x === 'L') {
            return total + 1;
        }
        return total;
        }
}

var pathL = path.reduce(counter('L'), 0);

var pathR = path.reduce(counter('R'), 0);

var pathU = path.reduce(counter('U'), 0);

var pathD = path.reduce(counter('D'), 0);

if (path.length % 2 !== 0) {
    print(-1);
} else if (pathL === pathR && pathU === pathD) {
    print(0);
} else {
    print((Math.abs(pathL - pathR) + Math.abs(pathU - pathD)) / 2);
}

var s = readline();
var solution = function ( s ) {
  if ( s.length%2 != 0 ) {
    return -1;
  }
  var forward = [...s.substr( 0, s.length / 2 )];
  var backward = [...s.substr( s.length / 2, s.length / 2 )];
  var forwardHist = new Map( [ [ "L", 0 ], [ "R", 0 ], [ "U", 0 ], [ "D", 0 ] ] );
  var backwardHist = new Map( [ [ "L", 0 ], [ "R", 0 ], [ "U", 0 ], [ "D", 0 ] ] );
  forward.forEach( c => forwardHist.set( c, forwardHist.get( c ) + 1) );
  backward.forEach( c => backwardHist.set( c, backwardHist.get( c ) + 1) );
  return ( Math.abs( backwardHist.get( "L" ) - forwardHist.get( "R" ) ) +
    Math.abs( backwardHist.get( "R" ) - forwardHist.get( "L" ) ) +
    Math.abs( backwardHist.get( "U" ) - forwardHist.get( "D" ) ) +
    Math.abs( backwardHist.get( "D" ) - forwardHist.get( "U" ) )) / 2;
};
print( solution( s ) );


Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions. There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water w contiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?

The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Print a single integer — the maximum final height of the smallest flower.

NoteIn the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test.

var nmw = readline().split(' ').map(Number);
var n = nmw[0];
var m = nmw[1];
var w = nmw[2];
var a = readline().split(' ').map(Number);
var ap = [];

function check(x) {
	var mt = m;
	var p = 0;
	for (var i=0; i<n; i++) {
		if (i>=w) p -= ap[i-w];
		if (x-a[i]-p>0) {
			ap[i] = x-a[i]-p;
			p += ap[i];
			mt -= ap[i];
			if (mt<0) return 0;
		} else ap[i] = 0;
	}
	return 1;
}

var l = 1000000001;
for (var i=0; i<n; i++) {
	if (a[i]<l) l = a[i];
}
var u = l + m + 1;
var c = 0;
while (l<u) {
	c = Math.floor ( (u + l)/2 ); if (check(c)) l = c+1; else u = c;
}
print(l-1);

var nmw = readline().split(' ').map(Number);
var n = nmw[0];
var m = nmw[1];
var w = nmw[2];
var a = readline().split(' ').map(Number);
var ap = [];

function check(x) {
	var mt = m;
	var p = 0;
	for (var i=0; i<n; i++) {
		if (i>=w) p -= ap[i-w];
		if (x-a[i]-p>0) {
			ap[i] = x-a[i]-p;
			p += ap[i];
			mt -= ap[i];
			if (mt<0) return 0;
		} else ap[i] = 0;
	}
	return 1;
}

var l = 1000000;
for (var i=0; i<n; i++) {
	if (a[i]<l) l = a[i];
}
var u = l + m + 1;
var c = 0;
while (l<u) {
	c = Math.floor ( (u + l)/2 ); if (check(c)) l = c+1; else u = c;
}
print(l-1);


You are given a permutation $$$p$$$ of integers from $$$0$$$ to $$$n-1$$$ (each of them occurs exactly once). Initially, the permutation is not sorted (that is, $$$p_i>p_{i+1}$$$ for at least one $$$1 \le i \le n - 1$$$). The permutation is called $$$X$$$-sortable for some non-negative integer $$$X$$$ if it is possible to sort the permutation by performing the operation below some finite number of times:   Choose two indices $$$i$$$ and $$$j$$$ $$$(1 \le i \lt j \le n)$$$ such that $$$p_i \& p_j = X$$$.  Swap $$$p_i$$$ and $$$p_j$$$. Here $$$\&$$$ denotes the bitwise AND operation.Find the maximum value of $$$X$$$ such that $$$p$$$ is $$$X$$$-sortable. It can be shown that there always exists some value of $$$X$$$ such that $$$p$$$ is $$$X$$$-sortable.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ $$$(1 \le t \le 10^4)$$$  — the number of test cases. Description of test cases follows. The first line of each test case contains a single integer $$$n$$$ $$$(2 \le n \le 2 \cdot 10^5)$$$  — the length of the permutation. The second line of each test case contains $$$n$$$ integers $$$p_1, p_2, ..., p_n$$$ ($$$0 \le p_i \le n-1$$$, all $$$p_i$$$ are distinct)  — the elements of $$$p$$$. It is guaranteed that $$$p$$$ is not sorted. It is guaranteed that the sum of $$$n$$$ over all cases does not exceed $$$2 \cdot 10^5$$$.

For each test case output a single integer — the maximum value of $$$X$$$ such that $$$p$$$ is $$$X$$$-sortable.

Number.prototype.toInt = function () {
	return parseInt(this);
};
String.prototype.toNumber = function () {
	return +this;
}

const readline = require('readline');

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

class Input {

	constructor() {
		this._lineIndex = 0
		this._inputsBuffer = []
	}

	get _currentLine() {
		return this._lineIndex++;
	}

	buffer(value) {
		this._inputsBuffer.push(value);
	}

	readLine() {
		return this._inputsBuffer[this._currentLine];
	}

	readNumber() {
		return this.readLine().toNumber();
	}

	readArray() {
		return this.readLine().split(' ');
	}

	readIntArray() {
		return this.readArray().map(item => parseInt(item));
	}

}

const io = new Input();

rl.on('line', (input) => {
	io.buffer(input);
});

rl.on('close', () => {
	// const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
	for (let i = io.readLine(); i > 0; --i) {
		io.readLine();
		console.log(io.readIntArray().reduce((ans, value, index) => {
			if (value !== index)
				return ans & value;
			return ans;
		}, Number.MAX_SAFE_INTEGER));
	}
});

'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) {
  [...new Array(10).keys()];
  let res = -1;
  for (let i = 0; i < n; i++) {
    if (a[i] !== i) {
      if (res === -1) res = a[i];else res &= a[i];
    }
  }
  return res;
}

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

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

Number.prototype.toInt = function () {
	return parseInt(this);
};
String.prototype.toNumber = function () {
	return +this;
}

const readline = require('readline');

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

class Input {

	constructor() {
		this._lineIndex = 0
		this._inputsBuffer = []
	}

	get _currentLine() {
		return this._lineIndex++;
	}

	buffer(value) {
		this._inputsBuffer.push(value);
	}

	readLine() {
		return this._inputsBuffer[this._currentLine];
	}

	readNumber() {
		return this.readLine().toNumber();
	}

	readArray() {
		return this.readLine().split(' ');
	}

	readIntArray() {
		return this.readArray().map(item => parseInt(item));
	}

}

const io = new Input();

rl.on('line', (input) => {
	io.buffer(input);
});

rl.on('close', () => {
	// (function() {
	// const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
	io.readLine();
	io.readLine();
	console.log(io.readIntArray().reduce((ans, value, index) => {
		if (value !== index)
			return ans & value;
		return ans;
	}, Number.MAX_SAFE_INTEGER));
});

'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 p = [...new Array(10).keys()];
  function find(i) {
    while (i !== p[i]) {
      p[i] = p[p[i]];
      i = p[p[i]];
    }
    return i;
  }
  function union(i, j) {
    const [rooti, rootj] = [find(i), find(j)];
    if (rooti === rootj) return;
    p[rootj] = rooti;
  }
  for (let i = 0; i < n; i++) {
    if (a[i] !== i) union(i, a[i]);
  }
  let scc = new Map();
  for (let i = 0; i < n; i++) {
    const root = find(i);
    if (!scc.has(root)) scc.set(root, []);
    scc.get(root).push(i);
  }
  let nums = new Set();
  for (let [, arr] of scc) {
    if (arr.length <= 1) continue;
    let x = arr[0];
    for (let i = 1; i < arr.length; i++) {
      x &= arr[i];
    }
    nums.add(x);
  }
  if (nums.size > 1) return 0;else return [...nums][0];
}

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

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