Marin wants you to count number of permutations that are beautiful. A beautiful permutation of length $$$n$$$ is a permutation that has the following property: $$$$$$ \gcd (1 \cdot p_1, \, 2 \cdot p_2, \, \dots, \, n \cdot p_n) > 1, $$$$$$ where $$$\gcd$$$ is the greatest common divisor.A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3, 4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of test cases. Each test case consists of one line containing one integer $$$n$$$ ($$$1 \le n \le 10^3$$$).

For each test case, print one integer — number of beautiful permutations. Because the answer can be very big, please print the answer modulo $$$998\,244\,353$$$.

NoteIn first test case, we only have one permutation which is $$$[1]$$$ but it is not beautiful because $$$\gcd(1 \cdot 1) = 1$$$.In second test case, we only have one beautiful permutation which is $$$[2, 1]$$$ because $$$\gcd(1 \cdot 2, 2 \cdot 1) = 2$$$.

'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++) {
        const mod = 998244353;
        let n = parseInt(readline(), 10);

        if (n % 2 === 1) {
            output(0);
            continue;
        }

        let m = n / 2;
        let res = 1;
        for (let i = 1; i <= m; i++) {
            res *= i;
            res = res % mod;
        }

        let one = BigInt(res);
        let modd = BigInt(mod);
        let result = (one * one) % modd;

        output(result.toString());
    }
}

// problems/contest1658/B/src/ts/solution.ts
var lines = [];
require("readline").createInterface({
  input: process.stdin
}).on("line", (line) => lines.push(line));
process.stdin.on("end", () => {
  main(lines);
});
var MOD = 998244353;
var mul = (a, b) => Number(BigInt(a) * BigInt(b) % BigInt(MOD));
function main(lines2) {
  let i = 0;
  for (let t = Number(lines2[i++]); t > 0; t--) {
    const n = Number(lines2[i++]);
    console.log(solve(n));
  }
}
function fac(n) {
  let res = 1;
  for (let i = 1; i <= n; i++)
    res = mul(res, i);
  return res;
}
function solve(n) {
  if (n % 2 !== 0)
    return 0;
  const m = fac(n / 2);
  return mul(m, m);
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')
const N = Number(inputs[0])
for (let _ = 0, __ = 1; _ < N; _++) {
  const n = Number(inputs[__++])
  main(n)
}

function main(n) {
  const MOD = BigInt(998244353)
  if (n & 1) {
    console.log(0)
  } else {
    let res = 1n
    n = BigInt(n / 2)
    while (n) {
      res *= n--
    }
    res = res * res
    console.log(Number(res % MOD))
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var mod = 998244353;
	while(hasNext()){
		var N = nextInt();
		if(N % 2 == 1){
			myout(0);
			continue;
		}
		var v = 1;
		for(var i = 1; i <= N / 2; i++){
			v *= i;
			v %= mod;
			v *= i;
			v %= mod;
		}
		myout(v);
	}
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        output[i] = solve(n)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n) {
    if (n & 1) return 0

    n /= 2
    let now = 1
    for (let i = 1; i <= n; i++) {
        now = mul(now, i)
    }
    return mul(now, now)
}

const MOD = 998244353
const MOD_CUT = ((1 << 20) * (1 << 20)) % MOD
function add(a, b) {
    return (a + b) % MOD
}
function minus(a, b) {
    return add(add(a, -b), MOD)
}
function mul(a, b) {
    let r = (a >> 20) * (b >> 20) * MOD_CUT
        + (a & 0xfff00000) * (b & 0xfffff)
        + (a & 0xfffff) * b
    return r % MOD
}
function pow(a, b) {
    let r = 1
    let base = a
    while (b) {
        if (b & 1) {
            r = mul(r, base)
        }
        b >>= 1
        base = mul(base, base)
    }
    return r
}

var t = readline();

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

  if (n % 2 !== 0) print(0);
  else {
    n = n / 2;
    var ans = 1;
    for (var j = n; j > 0; j--) {
      ans *= j * j % 998244353;
      ans %= 998244353;
    }
    print(ans);
  }
}

var t = readline();

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

  if (n % 2 !== 0) print(0);
  else {
    n = Math.floor(n / 2);
    var ans = 1;
    for (var j = 1; j <= n; j++) {
      ans = (ans * j) % 998244353;
    }
    ans = (ans * ans) % 998244353;
    print(ans);
  }
}


Recently Vova found $$$n$$$ candy wrappers. He remembers that he bought $$$x$$$ candies during the first day, $$$2x$$$ candies during the second day, $$$4x$$$ candies during the third day, $$$\dots$$$, $$$2^{k-1} x$$$ candies during the $$$k$$$-th day. But there is an issue: Vova remembers neither $$$x$$$ nor $$$k$$$ but he is sure that $$$x$$$ and $$$k$$$ are positive integers and $$$k > 1$$$.Vova will be satisfied if you tell him any positive integer $$$x$$$ so there is an integer $$$k>1$$$ that $$$x + 2x + 4x + \dots + 2^{k-1} x = n$$$. It is guaranteed that at least one solution exists. Note that $$$k > 1$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$3 \le n \le 10^9$$$) — the number of candy wrappers Vova found. It is guaranteed that there is some positive integer $$$x$$$ and integer $$$k>1$$$ that $$$x + 2x + 4x + \dots + 2^{k-1} x = n$$$.

Print one integer — any positive integer value of $$$x$$$ so there is an integer $$$k>1$$$ that $$$x + 2x + 4x + \dots + 2^{k-1} x = n$$$.

NoteIn the first test case of the example, one of the possible answers is $$$x=1, k=2$$$. Then $$$1 \cdot 1 + 2 \cdot 1$$$ equals $$$n=3$$$.In the second test case of the example, one of the possible answers is $$$x=2, k=2$$$. Then $$$1 \cdot 2 + 2 \cdot 2$$$ equals $$$n=6$$$.In the third test case of the example, one of the possible answers is $$$x=1, k=3$$$. Then $$$1 \cdot 1 + 2 \cdot 1 + 4 \cdot 1$$$ equals $$$n=7$$$.In the fourth test case of the example, one of the possible answers is $$$x=7, k=2$$$. Then $$$1 \cdot 7 + 2 \cdot 7$$$ equals $$$n=21$$$.In the fifth test case of the example, one of the possible answers is $$$x=4, k=3$$$. Then $$$1 \cdot 4 + 2 \cdot 4 + 4 \cdot 4$$$ equals $$$n=28$$$.

//Candies

const {EOL} = require('os');

let inp = '';

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

process.stdin.on('end', () => {
    let lines = inp.split(EOL);

    let t = +lines[0];

    let f = (x) =>  {
    	for(let i = 2; i < 64; i++)  {
    		if(x % (Math.pow(2, i) - 1) == 0)  {
    			return (x / (Math.pow(2, i) - 1));
    		}
    	}
    }

    for(let i = 0; i < t; i++)  {
    	process.stdout.write(f(+lines[i + 1]) + EOL);
    }

    return;
});

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

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

    for (let i = 0; i < 60; i++) {
      powers.push(2**i);
    }
    return;
  }

  let n = +d;
  let x = n < 100 ? 1 : Math.floor(n / 3);

  for (let i = 2; i < powers.length; i++) {
    let t = powers[i] - 1;
    if (n % t === 0) {
      ans += `${n / t}\n`;
      break;
    }
  }

  c++;
});

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

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var input = parseInt(readline())
    //var a = readline().split(" ").map(x => parseInt(x))
    while (input--) {
        var n = parseInt(readline())
        var res = 0
        for (var i = 0; i < n; i++) {
            res += Math.pow(2, i)
            if (res != 1 && n % res == 0) {
                var a = n / res
                print(a)
                break;
            }
        }
    }

}

function solve(n) {
  let t = 3;
  while (t <= n) {
    const u = n % t;
    if (u === 0) {
      const x = n / t;
      return x;
    }
    t = t + t + 1;
  }
  throw Error('could not solve the problem');
}

function main(lines) {
  lines.shift();
  for (const line of lines) {
    let t = line.trim();
    if (line.length > 0) {
      const n = Number(t);
      const result = solve(n);
      console.log(result);
    }
  }
}

async function processLinesFromStream(rs, pf) {
  const content = [];
  rs.setEncoding("utf-8");
  for await (let chunk of rs) {
    content.push(chunk);
  }
  const lines = content.join('').split(/\n/);
  const result = pf(lines);
  return result;
}

processLinesFromStream(process.stdin, main);

function solve(n) {
  let t = 3;
  while (t <= n) {
    const u = n % t;
    if (u === 0) {
      const x = n / t;
      return x;
    }
    t = t + t + 1;
  }
  throw Error('could not solve the problem');
}

function main(lines) {
  lines.shift();
  for (const line of lines) {
    const n = Number(line);
    const result = solve(n);
    console.log(result);
  }
}

function trim_line(s) {
  return s.trim();
}

function has_content(s) {
  return (s.length > 0);
}

async function processLinesFromStream(rs, pf) {
  const chunks = [];
  const encoding = 'utf-8';
  rs.setEncoding(encoding);
  for await (let chunk of rs) {
    chunks.push(chunk);
  }
  const empty = '';
  const newline = /\n/;
  const lines = chunks.join(empty)
                      .split(newline)
                      .map(trim_line)
                      .filter(has_content);
  const result = pf(lines);
  return result;
}

processLinesFromStream(process.stdin, main);

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

let calcMaxSq = (n, a, start) => {
  let res = 1;
  for (let i = n - 1; i > start; i++) {
    if (a[i] === a[start]) {
      res++;
    }
  }
  return res;
}

function solve(n) {
  let nums = [1];
  let k = 1;
  while (true) {
    k *= 2;
    let current = k + nums[nums.length - 1];
    if (n % current === 0) return n / current;
    nums.push(current);
  }
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    // let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(n);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

// Lang: Node.js
'use strict';
let x = '', y = 0;
let print = x => console.log(x);

process.stdin.on('data', inputStdin => x += inputStdin);
process.stdin.on('end', () => { x = x.split('\n'); main(); });
let readline = () => x[y++];

// ************************ Code Start ***************************

function main() {

  var Tc = parseInt(readline());
  for (; Tc--;) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

"use strict";

function print(x) {
  console.log(x);
}
let x = "", y = 0;

process.stdin.on("data", inputStdin => x += inputStdin);
process.stdin.on("end", () => {
  x = x.split("\n");
  main();
});
function readline() {
  return x[y++];
}

// ************************ Code Start ***************************

function main() {

  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

// Lang: Node.js
'use strict';
let x = '', y = 0;
let print = x => console.log(x);

process.stdin.on('data', inputStdin => x += inputStdin);
process.stdin.on('end', () => { x = x.split('\n'); main(); });
let readline = () =>  x[y++];

// ************************ Code Start ***************************

function main() {
  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ************************ Code Start ***************************

function main() {

  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

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

let inputString = "";
let currentLine = 0;

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

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

// ************************ Code Start ***************************

function main() {
  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let n = parseInt(readLine());
    for (var i = 0; i < n; i++) {
        let t = parseInt(readLine());
        let k = 2;
        while (true) {
            let x = t / (Math.pow(2, k) - 1);
            // console.log('x', x);
            if (Number.isInteger(x) == true) {
                console.log(x);
                break;
            }
            k++;
        }
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  //let [n, industry] = readline().split(" ").map(e => parseInt(e));

    let cases = parseInt(readline(), 10);
    for (var i = 0; i < cases; i++) {
      let d = [1,2]
      let sum = 3;
      const p = parseInt(readline(), 10);

      while (p % sum != 0) {
        d.push(d[d.length-1]*2);
        sum = d.reduce((a,b) => a+b, 0);
      }

      console.log(p / sum);
    }

}

var t = parseInt(readline());
for (var tc = 1; tc <= t; tc++) {
  var n = parseInt(readline());
  if (n % 3 == 0) print(n / 3);
  else if (n % 7 == 0) print(n / 7);
  else {
    var k = 2;
    var flag = true;
    while (flag == true) {
      var x = n / (Math.pow(2, k) - 1);

      if (x == Math.floor(x) && x > 0) {
        print(x);
        flag = false;
      }
      k++;
    }
  }
}

r=readline
n=+r()
while(n--){
    t=+r()
    for(i=2;i<t;i++)
    {
        p=Math.pow(2,i)-1
        if(t%p==0)
        {
            print(t/p)
            break
        }
    }
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var n = nextInt();
		var k = 2;
		var count = 3;
		while(true){
			if(n % count == 0){
				break;
			}
			k++;
			count += Math.pow(2,k - 1);
		}
		output[i] = n / count;
	}
	myout(myconv(output,9));
}

var testAmount = parseInt(readline());

var wrapperAmounts = [];
for (var i = 0; i < testAmount; i++) {
  wrapperAmounts.push(parseInt(readline()));
}

for (var i = 0; i < wrapperAmounts.length; i++) {
  for (var k = 2; k <= 29; k++) {
    var x = wrapperAmounts[i] / (Math.pow(2, k) - 1);
    if (x === Math.floor(x)) {
      print(x);
      break;
    }
  }
}

var n = Number(readline());
var inp;
for(var i = 0; i < n; i++){
    inp = Number(readline());
    var k = 3;
    while(inp%k !== 0){
    k = k*2 + 1
    }
    print(inp/k)

}

var t = parseInt(readline());

for(var qq = 0; qq < t; qq++) {
    var n = parseInt(readline());

    var k = 2;

    while (true) {
        var kk = (1 << k);
        var del = kk - 1;

        if (n === del || n % del === 0) {
            break;
        }
        k++;
    }

    var kkk = (1 << k);
    var x = n / (kkk - 1)

    print(x);
}

var t = parseInt(readline());
for (var tc = 1; tc <= t; tc++) {
  var n = parseInt(readline());
  var k = 2;
  var flag = true;
  while (flag == true) {
    var x = n / (Math.pow(2, k) - 1);

    if (x == Math.floor(x) && x > 0) {
      print(x);
      flag = false;
    }
    k++;
  }
}

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

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

    for (let i = 0; i < 60; i++) {
      powers.push(2**i);
    }
    return;
  }

  let n = +d;
  let x = Math.floor(n / 3);
  let curr = 0;

  for (let i = 0; i < powers.length; i++) {
    curr += powers[i] * x;

    if (curr === n) {
      ans += `${x}\n`;
      break;
    }

    if (curr > n) {
      x++;
      curr = 0;
      i = -1;
    }
  }

  c++;
});

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

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var input = parseInt(readline())
    while (input--) {
        var n = parseInt(readline())
        print(n)
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

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

let x = "", y = 0;
process.stdin.on("data", inputStdin => x += inputStdin);
process.stdin.on("end", () => x = x.split("\n"), main());
function readline() { return x[y++]; }

// ************************ Code Start *************************** //

function main() {

  var tc = parseInt(readline());
  for (; tc-- ;) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

"use strict";

function print(x) {
  console.log(x);
}
let x = "", y = 0;
function readline() {
  return x[y++];
}

// ************************ Code Start ***************************

function main() {

  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

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

let inputString = "";
let currentLine = 0;

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

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

// ************************ Code Start ***************************

function main() {
  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

var t = parseInt(readline());
for (var tc = 0; tc <= t; tc++) {
  var n = parseInt(readline());
  if (n % 3 == 0) print(n / 3);
}

var t = parseInt(readline());
var t = parseInt(readline());
for (var tc = 1; tc <= t; tc++) {
  var n = parseInt(readline());
  if (n % 3 == 0) print(n / 3);
  else if (n % 7 == 0) print(n / 7);
  else print(1);
}

var t = parseInt(readline());
for (var tc = 1; tc <= t; tc++) {
  var n = parseInt(readline());
  if (n % 3 == 0) print(n / 3);
  else print(n);
}

var t = parseInt(readline());
for (var tc = 1; tc <= t; tc++) {
  var n = parseInt(readline());
  if (n % 3 == 0) print(n / 3);
  else print(1);
}

function main()
{
  const testAmount = parseInt(readline());

  const wrapperAmounts = [];
  for (var i = 0; i < testAmount; i++) {
    wrapperAmounts.push(parseInt(readline()));
  }

  for (var i = 0; i < wrapperAmounts.length; i++) {
    for (var k = 2; k <= 29; k++) {
      const x = wrapperAmounts[i] / (Math.pow(2, k) - 1);
      if (x === Math.floor(x)) {
        print(x);
        break;
      }
    }
  }

  return 0;
}
main();


DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number xi, DZY will put it into the bucket numbered h(xi), where h(x) is the hash function. In this problem we will assume, that h(x) = x mod p. Operation a mod b denotes taking a remainder after division a by b.However, each bucket can contain no more than one element. If DZY wants to insert an number into a bucket which is already filled, we say a "conflict" happens. Suppose the first conflict happens right after the i-th insertion, you should output i. If no conflict happens, just output -1.

The first line contains two integers, p and n (2 ≤ p, n ≤ 300). Then n lines follow. The i-th of them contains an integer xi (0 ≤ xi ≤ 109).

Output a single integer — the answer to the problem.

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [p, n] = d.split(' ').map(Number);
    return;
  }

  if (h[+d % p]) {
    ans.push(c);
  }
  else {
    h[+d % p] = true;
  }

  c++;
});

rl.on('close', () => {
  if (!ans.length) {
    console.log(-1);
  }
  else {
    console.log(ans[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.num = function() {
		return Number(this.next().value);
	};
nl.nums = function() {
		return this.next().value.split(/\s/g).map(Number);
	};
nl.line = function() {
		return this.next().value;
	}

const sol = () => {
	 //using nl.next().value || for(let l of nl)
	let [p, n] = nl.nums();
	let st = new Set();
	let flag = -1;
	for(let i = 0; i < n; i++){
		let num = nl.num()%p;
		if (st.has(num)) {
			flag = i + 1;
			break;
		} else {
			st.add(num);
		}
	}
	console.log(flag);
};

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

;(function () {

	var p = readline().split(' ').map(Number);
	var n = +p[1];
	p = +p[0];

	var h = [];
	for (var i = 0; i < n; i++) {
		var s = +readline();

		if (h[s % p]) {
			print(i + 1);
			return;
		}

		h[s % p] = true;
	}

	print(-1);

}).call(this);

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		p = data[0], n = data[1], h = {};
	for (var i = 0; i < n; ++i) {
		var x = parseInt(readline()),
			k = x%p;
		if (h[k]) {
			print(i+1);
			return;
		}
		h[k] = true;
	}
	print(-1);
}

main();

var numbers = []

var firstLine = readline().split(" ").map(Number);
var p = firstLine[0];
var n = firstLine[1];
for(var i = 0; i < n; i ++){
	numbers.push(Number(readline()))
}

var hashes = []
var done = false

for(var i = 0; i <n; i++){
	var hash = numbers[i] % p
	if(hashes.indexOf(hash) !== -1){
		done = true
		print(i + 1)
		break
	}
	else{
		hashes.push(hash)
	}
}

if(!done){
print(-1)
}

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [p, n] = d.split(' ').map(Number);
    return;
  }

  if (h[+d % p]) {
    ans.push(c);
  }
  else {
    h[+d % p] = true;
  }

  c++;
});

rl.on('close', () => {
  if (!ans.length) {
    console.log(-1);
  }

  console.log(ans[0]);
});

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [p, n] = d.split(' ').map(Number);
    return;
  }

  if (h[+d]) {
    ans.push(c - 1);
  }
  else {
    h[+d] = true;
  }

  c++;
});

rl.on('close', () => {
  if (!ans.length) {
    console.log(-1);
  }

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

var numbers = []

var firstLine = readline().split(" ").map(Number);
var p = firstLine[0];
var n = firstLine[1];
for(var i = 0; i < n; i ++){
	numbers.push(Number(readline()))
}

var hashes = []

for(var i = 0; i <n; i++){
	var hash = numbers[i] % p
	if(hashes.indexOf(hash) !== -1){
		print(i + 1)
		break
	}
	else{
		hashes.push(hash)
	}
}

print(-1)


Two integer sequences existed initially — one of them was strictly increasing, and the other one — strictly decreasing.Strictly increasing sequence is a sequence of integers $$$[x_1 < x_2 < \dots < x_k]$$$. And strictly decreasing sequence is a sequence of integers $$$[y_1 > y_2 > \dots > y_l]$$$. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.They were merged into one sequence $$$a$$$. After that sequence $$$a$$$ got shuffled. For example, some of the possible resulting sequences $$$a$$$ for an increasing sequence $$$[1, 3, 4]$$$ and a decreasing sequence $$$[10, 4, 2]$$$ are sequences $$$[1, 2, 3, 4, 4, 10]$$$ or $$$[4, 2, 1, 10, 4, 3]$$$.This shuffled sequence $$$a$$$ is given in the input.Your task is to find any two suitable initial sequences. One of them should be strictly increasing and the other one — strictly decreasing. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing.If there is a contradiction in the input and it is impossible to split the given sequence $$$a$$$ to increasing and decreasing sequences, print "NO".

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 2 \cdot 10^5$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

If there is a contradiction in the input and it is impossible to split the given sequence $$$a$$$ to increasing and decreasing sequences, print "NO" in the first line. Otherwise print "YES" in the first line and any two suitable sequences. Note that the empty sequence and the sequence consisting of one element can be considered as increasing or decreasing. In the second line print $$$n_i$$$ — the number of elements in the strictly increasing sequence. $$$n_i$$$ can be zero, in this case the increasing sequence is empty. In the third line print $$$n_i$$$ integers $$$inc_1, inc_2, \dots, inc_{n_i}$$$ in the increasing order of its values ($$$inc_1 < inc_2 < \dots < inc_{n_i}$$$) — the strictly increasing sequence itself. You can keep this line empty if $$$n_i = 0$$$ (or just print the empty line). In the fourth line print $$$n_d$$$ — the number of elements in the strictly decreasing sequence. $$$n_d$$$ can be zero, in this case the decreasing sequence is empty. In the fifth line print $$$n_d$$$ integers $$$dec_1, dec_2, \dots, dec_{n_d}$$$ in the decreasing order of its values ($$$dec_1 > dec_2 > \dots > dec_{n_d}$$$) — the strictly decreasing sequence itself. You can keep this line empty if $$$n_d = 0$$$ (or just print the empty line). $$$n_i + n_d$$$ should be equal to $$$n$$$ and the union of printed sequences should be a permutation of the given sequence (in case of "YES" answer).

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    numbers.sort((x,y) => x-y);
    const increase = [];
    const decrease = [];
    for(let i = 0; i<numbers.length;i++) {
        if (increase.length == 0 ||numbers[i] > increase[increase.length-1]) {
            increase.push(numbers[i])
        } else if (decrease.length == 0 ||numbers[i] > decrease[decrease.length-1]){
            decrease.push(numbers[i]);
        }
        else {
            console.log('No');
            return;
        }
    }
    console.log("Yes");
    console.log(increase.length);
    console.log(increase.join(' '));
    console.log(decrease.length);
    console.log(decrease.reverse().join(' '));
}

readLines(2, doIt);

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ************************ Code Start ***************************

function main() {

  var t = parseInt(readline());
  var ar = readline().split(' ').map(x => parseInt(x));

  var ok = 0;
  ar.sort((a, b) => a - b);

  var m = [], n = [];
  for (var i = 0; i < ar.length; i++) {
    if (n.length == 0 || ar[i] > n[n.length - 1]) {
      n.push(ar[i]);
    }
    else if (m.length == 0 || ar[i] > m[m.length - 1]) {
      m.push(ar[i]);
    }
    else ok = 1;
  }
  print(ok ? 'NO' : "YES" + '\n' + m.length + '\n' + m.join(' ')
                          + '\n' + n.length + '\n' + n.reverse().join(' '));

}

var stdin = "";
process.stdin.resume();
process.stdin.setEncoding('ascii');
process.stdin.on('data', function (data) { stdin += data; });
process.stdin.on('end', function () { main(stdin); });

var stdin_row = 0, stdin_rows;
function readLine() { if (!stdin_rows) stdin_rows = stdin.split("\n"); return stdin_rows[stdin_row++]; } // to trim ?
function readLineVals() { return readLine().trim().split(/\s+/); }

const debug = 0
var log = console.log;
var dbg = debug ? console.log : _ => {};

/////////////// ignore above this line ////////////////////

function main(stdin) {
	var n = readLine() * 1;
	var vals = readLineVals();
	if (n!=vals.length)
		throw "input parsing pb "+n+" "+vals;

	vals = vals.sort((a,b)=> a-b);
	incr = [ vals[0] ];
	decr = [];

	for (var i =1; i<vals.length; i++) {
		if (vals[i]!=vals[i-1])
			incr.push(vals[i]);
		else
			// repeated elements are put in decreasing sequence
			decr.push(vals[i]);
	}

	decr = decr.sort((a,b)=> b-a);

	dbg(incr)
	dbg(decr)

	// make sure there is no triplicate
	for (var i =1; i<decr.length; i++) {
		if (decr[i]==decr[i-1]) {
			log("NO");
			return;
		}
	}

	log("YES");
	log(incr.length);
	log(incr.join(" "));
	log(decr.length);
	log(decr.join(" "));

}

//var input = readline()

var t = parseInt(readline());
var ar = readline().split(' ').map(x => parseInt(x));

var ok = 0;
ar.sort((a, b) => a - b);

var m = [], n = [];

for(var i=0; i<ar.length; i++) {
    if (n.length == 0 || ar[i] > n[n.length-1]) {
        n.push(ar[i]);
    } else if (m.length == 0 || ar[i] > m[m.length-1]){
        m.push(ar[i]);
    }
    else {
        ok = 1;
    }
}
print(ok ? 'NO' : "YES" +'\n'+  m.length  +'\n'+  m.join(' ')
                        +'\n'+  n.length  +'\n'+  n.reverse().join(' '));

//

//var input = readline()

var t = parseInt(readline())
var ar = readline().split(' ').map(x => parseInt(x))

var ok = 0
ar.sort((a, b) => a - b)

var m = [], n = [];

for(var i=0; i<ar.length; i++) {
    if (n.length == 0 || ar[i] > n[n.length-1]) {
        n.push(ar[i])
    } else if (m.length == 0 || ar[i] > m[m.length-1]){
        m.push(ar[i]);
    }
    else {
        ok = 1;
    }
}
print(ok ? 'NO' : "YES" +'\n'+ m.length  +'\n'+  m.join(' ') +'\n'+
                               n.length  +'\n'+  n.reverse().join(' '));

var t = parseInt(readline());
var ar = readline().split(' ').map(x => parseInt(x));

var ok = 0;
ar.sort((a, b) => a - b);

var m = [], n = [];
for(var i=0; i<ar.length; i++) {
  if (n.length == 0 || ar[i] > n[n.length-1]) {
    n.push(ar[i]);
  }
  else if (m.length == 0 || ar[i] > m[m.length - 1]) {
    m.push(ar[i]);
  }
  else ok = 1;
}
print(ok ? 'NO' : "YES" +'\n'+  m.length  +'\n'+  m.join(' ')
                        +'\n'+  n.length  +'\n'+  n.reverse().join(' '));

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    numbers.sort();
    const increase = [];
    const decrease = [];
    increase.push(numbers[0]);
    let inPrev = numbers[0];
    for(let i = 1; i<numbers.length;i++) {
        if (numbers[i] > inPrev) {
            increase.push(numbers[i])
            inPrev = numbers[i];
        } else {
            if (decrease.length == 0)
                decrease.push(numbers[i]);
            else {
                if (numbers[i] > decrease[decrease.length-1])
                    decrease.push(numbers[i]);
                else {
                    console.log('No');
                    return;
                }
            }
        }
    }
    console.log("Yes");
    console.log(increase.length);
    console.log(increase.join(' '));
    console.log(decrease.length);
    console.log(decrease.reverse().join(' '));
}

readLines(2, doIt);

//var input = readline()

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

var ok = 0
var dis = ar.sort((a, b) => b - a)
if(dis[0] > 2 ) ok = 1
else ok = 0

if(ok) {
    var duplicates = ar.reduce(function(x, y, z, A) {
        if (A.indexOf(y) !== z && x.indexOf(y) < 0) x.push(y); return x;
    },[]);

    print('YES')
    print(duplicates.length)
    print(duplicates.sort((a, b) => a - b).join(' '))

    var insert = [...new Set(ar)].sort((a, b) => b - a)
    print(insert.length)
    print(insert.join(' '))
}
else {
    print('NO')
}


Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities.To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities numbered a1, a2, ..., ak.Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another n - k cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble.Formally, Masha will pay x roubles, if she will open the bakery in some city b (ai ≠ b for every 1 ≤ i ≤ k) and choose a storage in some city s (s = aj for some 1 ≤ j ≤ k) and b and s are connected by some path of roads of summary length x (if there are more than one path, Masha is able to choose which of them should be used).Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of k storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.

The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 105, 0 ≤ k ≤ n) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then m lines follow. Each of them contains three integers u, v and l (1 ≤ u, v ≤ n, 1 ≤ l ≤ 109, u ≠ v) meaning that there is a road between cities u and v of length of l kilometers . If k > 0, then the last line of the input contains k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n) — the number of cities having flour storage located in. If k = 0 then this line is not presented in the input.

Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the n cities, print  - 1 in the only line.

NoteImage illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.

var input = readline().split(" ").map(i => +i);
var n = input[0];
var m = input[1];
var k = input[2];

var shortestRoad = new Map();
for (var i = 0; i < m; ++i) {
    input = readline().split(" ").map(i => +i);
    var u = input[0];
    var v = input[1];
    var l = input[2];

    if ( !shortestRoad.has(u) ) {
        shortestRoad.set(u, new Map());
    }

    if ( !shortestRoad.has(v) ) {
        shortestRoad.set(v, new Map());
    }

    if ( shortestRoad.get(u).has(v) ) {
        shortestRoad.get(u).set(v, Math.min(shortestRoad.get(u).get(v), l));
    } else {
        shortestRoad.get(u).set(v, l);
    }

    if ( shortestRoad.get(v).has(u) ) {
        shortestRoad.get(v).set(u, Math.min(shortestRoad.get(v).get(u), l));
    } else {
        shortestRoad.get(v).set(u, l);
    }
}

var minLength;
if (k) {
    var a = new Set(readline().split(" ").map(i => +i));
    a.forEach(ak => {
        if ( shortestRoad.has(ak) ) {
            shortestRoad.get(ak).forEach( (length, adjCity) => {
                if ( !a.has(adjCity) && ( !minLength || length < minLength ) ) {
                    minLength = length;
                }
            });
        }
    });
}

print(minLength || "-1");

'use strict';
const retInt = function(x) { return parseInt(x);};
let e = readline();
while (e !== undefined) {
  let numbers = e.split(" ").map(retInt);
  const n = numbers[0];
  const m = numbers[1];
  const k = numbers[2];

  const adjList = [];
  if (n === 1 || m <= 0) {
     print(-1);
     e.readline();
     continue;
  }

  for (let i = 0; i < m; i++) {
    numbers = readline().split(" ").map(retInt);
    adjList.push(numbers);
  }

  if (k > 0) {
    numbers = readline().split(" ").map(retInt);
    const hm = {};
    for (const num of numbers) {
      hm[num] = true;
    }
    let max = 9999999999;
    let min = 9999999999;
    for (const edge of adjList) {
      const u = edge[0];
      const v = edge[1];
      const l = edge[2];
      if ( (hm[u] && !hm[v]) || (!hm[u] && hm[v]) ) {
        min = l < min ? l : min;
      }
    }
    if (min === max) min = -1;
    print(min);
  } else {
    print('-1');
  }
  e = readline();
}

var input = readline().split(" ").map(i => +i);
var n = input[0];
var m = input[1];
var k = input[2];

var shortestRoad = new Map();
for (var i = 0; i < m; ++i) {
    input = readline().split(" ").map(i => +i);
    var u = input[0];
    var v = input[1];
    var l = input[2];
    if ( !shortestRoad.has(u) ) {
        shortestRoad.set(u, new Map());
    }
    if ( !shortestRoad.has(v) ) {
        shortestRoad.set(v, new Map());
    }
    if ( !shortestRoad.get(u).has(v) ) {
        shortestRoad.get(u).set(v, Math.min(shortestRoad.get(u).get(v), l));
    } else {
        shortestRoad.get(u).set(v, l);
    }
    if ( !shortestRoad.get(v).has(u) ) {
        shortestRoad.get(v).set(u, Math.min(shortestRoad.get(v).get(u), l));
    } else {
        shortestRoad.get(v).set(v, l);
    }
}

var minLength;
if (k) {
    var a = new Set(readline().split(" ").map(i => +i));
    a.forEach(ak => {
        if ( shortestRoad.has(ak) ) {
            shortestRoad.get(ak).forEach( (length, adjCity) => {
                if ( !a.has(adjCity) && ( !minLength || length < minLength ) ) {
                    minLength = length;
                }
            });
        }
    });
}

print(minLength || "-1");


Polycarp has spent the entire day preparing problems for you. Now he has to sleep for at least $$$a$$$ minutes to feel refreshed.Polycarp can only wake up by hearing the sound of his alarm. So he has just fallen asleep and his first alarm goes off in $$$b$$$ minutes.Every time Polycarp wakes up, he decides if he wants to sleep for some more time or not. If he's slept for less than $$$a$$$ minutes in total, then he sets his alarm to go off in $$$c$$$ minutes after it is reset and spends $$$d$$$ minutes to fall asleep again. Otherwise, he gets out of his bed and proceeds with the day.If the alarm goes off while Polycarp is falling asleep, then he resets his alarm to go off in another $$$c$$$ minutes and tries to fall asleep for $$$d$$$ minutes again.You just want to find out when will Polycarp get out of his bed or report that it will never happen.Please check out the notes for some explanations of the example.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. The only line of each testcase contains four integers $$$a, b, c, d$$$ ($$$1 \le a, b, c, d \le 10^9$$$) — the time Polycarp has to sleep for to feel refreshed, the time before the first alarm goes off, the time before every succeeding alarm goes off and the time Polycarp spends to fall asleep.

For each test case print one integer. If Polycarp never gets out of his bed then print -1. Otherwise, print the time it takes for Polycarp to get out of his bed.

NoteIn the first testcase Polycarp wakes up after $$$3$$$ minutes. He only rested for $$$3$$$ minutes out of $$$10$$$ minutes he needed. So after that he sets his alarm to go off in $$$6$$$ minutes and spends $$$4$$$ minutes falling asleep. Thus, he rests for $$$2$$$ more minutes, totaling in $$$3+2=5$$$ minutes of sleep. Then he repeats the procedure three more times and ends up with $$$11$$$ minutes of sleep. Finally, he gets out of his bed. He spent $$$3$$$ minutes before the first alarm and then reset his alarm four times. The answer is $$$3+4 \cdot 6 = 27$$$.The second example is almost like the first one but Polycarp needs $$$11$$$ minutes of sleep instead of $$$10$$$. However, that changes nothing because he gets $$$11$$$ minutes with these alarm parameters anyway.In the third testcase Polycarp wakes up rested enough after the first alarm. Thus, the answer is $$$b=9$$$.In the fourth testcase Polycarp wakes up after $$$5$$$ minutes. Unfortunately, he keeps resetting his alarm infinitely being unable to rest for even a single minute :(

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 main() {
    // console.log("typeof inputString", typeof inputString)
    //console.log("inputString", inputString)

    const tests = inputString.slice(1).map(testStr => testStr.split(" ").map(Number));
    let result = [];
    tests.forEach(test => {
        const a = BigInt(test[0]);
        const b = BigInt(test[1]);
        const c = BigInt(test[2]);
        const d = BigInt(test[3]);
        let totalSleepAmount;
        let totalTime;

        if (b >= a) {
            console.log(b.toString());
            return;
        }

        totalSleepAmount = b;
        totalTime = b;

        if (c <= d) {
            console.log(-1);
            return;
        }

        const cycleSleepTime = BigInt(c - d);
        let cyclesCount = BigInt((a - totalSleepAmount) / cycleSleepTime);
        cyclesCount = cyclesCount * cycleSleepTime < a - totalSleepAmount ? cyclesCount + BigInt(1) : cyclesCount;
        totalSleepAmount += cyclesCount * cycleSleepTime;

        console.log((cyclesCount * c + b).toString());
    });
}

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 main() {
    // console.log("typeof inputString", typeof inputString)
    //console.log("inputString", inputString)

    const tests = inputString.slice(1).map(testStr => testStr.split(" ").map(Number));
    let result = [];
    tests.forEach(test => {
        //const [_, __, c, d] = test;
        const a = BigInt(test[0]);
        const b = BigInt(test[1]);
        const c = BigInt(test[2]);
        const d = BigInt(test[3]);
        let totalSleepAmount;
        let totalTime;

        if (b >= a) {
            //result.push(b);
            console.log(b.toString());
            return;
        }

        totalSleepAmount = b;
        totalTime = b;

        if (c <= d) {
            //result.push(-1);
            console.log(-1);
            return;
        }

        if (!c) {
            console.log(-1);
            return;
        }

        const cycleSleepTime = BigInt(c - d);
        let cyclesCount = BigInt((a - totalSleepAmount) / cycleSleepTime);
        cyclesCount = cyclesCount * cycleSleepTime < a - totalSleepAmount ? cyclesCount + BigInt(1) : cyclesCount;
        totalSleepAmount += cyclesCount * cycleSleepTime;

        console.log((cyclesCount * c + b).toString());
    });

    //result.forEach(r => console.log(r));
}

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 main() {
    // console.log("typeof inputString", typeof inputString)
    //console.log("inputString", inputString)

    const tests = inputString.slice(1).map(testStr => testStr.split(" ").map(Number));
    let result = [];
    tests.forEach(test => {
        const a = BigInt(test[0]);
        const b = BigInt(test[1]);
        const c = BigInt(test[2]);
        const d = BigInt(test[3]);
        let totalSleepAmount;
        let totalTime;

        if (b >= a) {
            console.log(b.toString());
            return;
        }

        totalSleepAmount = b;
        totalTime = b;

        if (c <= d) {
            console.log(-1);
            return;
        }

        // if (!c) {
        //     console.log(-1);
        //     return;
        // }

        const cycleSleepTime = BigInt(c - d);
        let cyclesCount = BigInt((a - totalSleepAmount) / cycleSleepTime);
        cyclesCount = cyclesCount * cycleSleepTime < a - totalSleepAmount ? cyclesCount + BigInt(1) : cyclesCount;
        totalSleepAmount += cyclesCount * cycleSleepTime;

        console.log((cyclesCount * c + b).toString());
    });
}

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i < Number(q[0]) + 1; i++) {
        console.log(solve(q[i].split(' ').map(str => BigInt(str))).toString())
    }
}
function solve([a, b, c, d]) {
    if ((a > b) && (c <= d)) {
        return -1
    }
    if (a <= b) {
        return b
    }
    let times = (a - b) / (c - d);
    if (times * (c - d) < a - b) {
        times += 1n;
    }
    return b + times * c;
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

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

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

  let [a, b, c, d] = data.split(' ').map(BigInt);
  let ans = b;
  let r = a - b;

  if (r <= 0n) {
    console.log(ans.toString());
    return;
  }

  if (c <= d) {
    console.log(-1);
    return;
  }

  let temp = r / (c - d);
  if (temp * (c - d) < r) {
    temp += 1n;
  }

  ans += temp * c;

  console.log(ans.toString());
  count++;
});

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const [a, b, c, d] = lines[i+1].split(' ').map(x => BigInt(x))
    if (a <= b) {
      console.log(b.toString(10))
    } else {
      if (c <=  d) {
        console.log(-1)
      } else {
        let t = a - b
        let f = c - d
        let p = (t - (t % f) ) / f
        if (t % f !== BigInt(0)) {
          p++
        }
        const add = p * c
        console.log((b + add).toString(10))
      }
    }
  }
}

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

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function main() {
    // console.log("typeof inputString", typeof inputString)
    //console.log("inputString", inputString)

    const tests = inputString.slice(1).map(testStr => testStr.split(" ").map(Number));
    let result = [];
    tests.forEach(test => {
        //const [_, __, c, d] = test;
        const a = test[0];
        const b = test[1];
        const c = test[2];
        const d = test[3];
        let totalSleepAmount;
        let totalTime;

        if (b >= a) {
            //result.push(b);
            console.log(b);
            return;
        }

        totalSleepAmount = b;
        totalTime = b;

        if (c <= d) {
            //result.push(-1);
            console.log(-1);
            return;
        }

        if (!c) {
            console.log(-1);
            return;
        }

        const cycleSleepTime = c - d;
        const cyclesCount = Math.ceil((a - totalSleepAmount) / cycleSleepTime);
        totalSleepAmount += cyclesCount * cycleSleepTime;

        console.log(cyclesCount * c + b);
    });

    //result.forEach(r => console.log(r));
}

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 main() {
    // console.log("typeof inputString", typeof inputString)
    //console.log("inputString", inputString)

    const tests = inputString.slice(1).map(testStr => testStr.split(" ").map(Number));
    let result = [];
    tests.forEach(test => {
        //const [_, __, c, d] = test;
        const a = test[0];
        const b = test[1];
        const c = test[2];
        const d = test[3];
        let totalSleepAmount;
        let totalTime;

        if (b >= a) {
            //result.push(b);
            console.log(b.toString());
            return;
        }

        totalSleepAmount =b;
        totalTime = b;

        if (c < d) {
            //result.push(-1);
            console.log(-1);
            return;
        }

        let count = 0;
        let prevTotalSleepAmount  = 0;
        // while (totalSleepAmount < a && prevTotalSleepAmount !== totalSleepAmount) {
        //     prevTotalSleepAmount = totalSleepAmount;
        //     totalSleepAmount = totalSleepAmount + (c - d);
        //     totalTime += c;
        //     count++;
        // }
        const cyclesCount = Math.trunc((a - b) / (c - d));
        totalSleepAmount += cyclesCount * (c - d);
        if (totalSleepAmount >= a) {
            console.log(cyclesCount * c + b);
        } else {
            console.log(cyclesCount * c + c + b);
        }
        //result.push(totalTime);
        //console.log(totalTime.toString());
        return;
    });

    //result.forEach(r => console.log(r));
}

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 main() {
    // console.log("typeof inputString", typeof inputString)
    //console.log("inputString", inputString)

    const tests = inputString.slice(1).map(testStr => testStr.split(" ").map(Number));
    let result = [];
    tests.forEach(test => {
        //const [_, __, c, d] = test;
        const a = BigInt(test[0]);
        const b = BigInt(test[1]);
        const c = BigInt(test[2]);
        const d = BigInt(test[3]);
        let totalSleepAmount;
        let totalTime;

        if (b >= a) {
            //result.push(b);
            console.log(b.toString());
            return;
        }

        totalSleepAmount = BigInt(b);
        totalTime = BigInt(b);

        if (d >= c) {
            //result.push(-1);
            console.log(-1);
            return;
        }

        let count = 0;
        while (totalSleepAmount < a && count < 1000) {
            totalSleepAmount += c - d;
            totalTime += c;
            count++;
        }
        //result.push(totalTime);
        console.log(totalTime.toString());
        return;
    });

    //result.forEach(r => console.log(r));
}

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 main() {
    // console.log("typeof inputString", typeof inputString)
    //console.log("inputString", inputString)

    const tests = inputString.slice(1).map(testStr => testStr.split(" ").map(Number));
    let result = [];
    tests.forEach(test => {
        //const [_, __, c, d] = test;
        const a = test[0];
        const b = test[1];
        const c = test[2];
        const d = test[3];
        let totalSleepAmount;
        let totalTime;

        if (b >= a) {
            //result.push(b);
            console.log(b.toString());
            return;
        }

        totalSleepAmount =b;
        totalTime = b;

        if (c < d) {
            //result.push(-1);
            console.log(-1);
            return;
        }

        let count = 0;
        let prevTotalSleepAmount  = 0;
        // while (totalSleepAmount < a && prevTotalSleepAmount !== totalSleepAmount) {
        //     prevTotalSleepAmount = totalSleepAmount;
        //     totalSleepAmount = totalSleepAmount + (c - d);
        //     totalTime += c;
        //     count++;
        // }
        const cyclesCount = Math.ceil((a - b) / (c - d));
        //totalSleepAmount += cyclesCount * (c - d);
        // if (totalSleepAmount >= a) {
        //     console.log(cyclesCount * c + b);
        // } else {
        //     console.log(cyclesCount * c + c + b);
        // }
        console.log(cyclesCount * c + b);
        //result.push(totalTime);
        //console.log(totalTime.toString());
        return;
    });

    //result.forEach(r => console.log(r));
}

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 main() {
    // console.log("typeof inputString", typeof inputString)
    //console.log("inputString", inputString)

    const tests = inputString.slice(1).map(testStr => testStr.split(" ").map(Number));
    let result = [];
    tests.forEach(test => {
        //const [_, __, c, d] = test;
        const a = test[0];
        const b = test[1];
        const c = test[2];
        const d = test[3];
        let totalSleepAmount;
        let totalTime;

        if (b >= a) {
            //result.push(b);
            console.log(b.toString());
            return;
        }

        totalSleepAmount = b;
        totalTime = b;

        if (c <= d) {
            //result.push(-1);
            console.log(-1);
            return;
        }

        if (!c) {
            console.log(-1);
            return;
        }

        const cycleSleepTime = c - d;
        const cyclesCount = Math.round((a - totalSleepAmount) / cycleSleepTime);
        totalSleepAmount += cyclesCount * (c - d);

        console.log(totalSleepAmount >= a ? cyclesCount * c + b : cyclesCount * c + c + b);
    });

    //result.forEach(r => console.log(r));
}

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 main() {
    // console.log("typeof inputString", typeof inputString)
    //console.log("inputString", inputString)

    const tests = inputString.slice(1).map(testStr => testStr.split(" ").map(Number));
    let result = [];
    tests.forEach(test => {
        //const [_, __, c, d] = test;
        const a = test[0];
        const b = test[1];
        const c = test[2];
        const d = test[3];
        let totalSleepAmount;
        let totalTime;

        if (b >= a) {
            //result.push(b);
            console.log(b.toString());
            return;
        }

        totalSleepAmount =b;
        totalTime = b;

        if (d >= c) {
            //result.push(-1);
            console.log(-1);
            return;
        }

        let count = 0;
        let prevTotalSleepAmount  = 0;
        // while (totalSleepAmount < a && prevTotalSleepAmount !== totalSleepAmount) {
        //     prevTotalSleepAmount = totalSleepAmount;
        //     totalSleepAmount = totalSleepAmount + (c - d);
        //     totalTime += c;
        //     count++;
        // }
        const cyclesCount = Math.floor((a - totalSleepAmount) / (c - d));
        totalSleepAmount += cyclesCount * (c - d);
        if (totalSleepAmount >= a) {
            console.log(cyclesCount * c + b);
        } else {
            console.log(cyclesCount * c + c + b);
        }
        //result.push(totalTime);
        //console.log(totalTime.toString());
        return;
    });

    //result.forEach(r => console.log(r));
}

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 main() {
    // console.log("typeof inputString", typeof inputString)
    //console.log("inputString", inputString)

    const tests = inputString.slice(1).map(testStr => testStr.split(" ").map(Number));
    let result = [];
    tests.forEach(test => {
        //const [_, __, c, d] = test;
        const a = test[0];
        const b = test[1];
        const c = test[2];
        const d = test[3];
        let totalSleepAmount;
        let totalTime;

        if (b >= a) {
            //result.push(b);
            console.log(b.toString());
            return;
        }

        totalSleepAmount =b;
        totalTime = b;

        if (c < d) {
            //result.push(-1);
            console.log(-1);
            return;
        }

         if (!c) {
            console.log(-1);
        }

        let count = 0;
        let prevTotalSleepAmount  = 0;
        // while (totalSleepAmount < a && prevTotalSleepAmount !== totalSleepAmount) {
        //     prevTotalSleepAmount = totalSleepAmount;
        //     totalSleepAmount = totalSleepAmount + (c - d);
        //     totalTime += c;
        //     count++;
        // }
        const cyclesCount = Math.ceil((a - b) / (c - d));
        //totalSleepAmount += cyclesCount * (c - d);
        // if (totalSleepAmount >= a) {
        //     console.log(cyclesCount * c + b);
        // } else {
        //     console.log(cyclesCount * c + c + b);
        // }
        console.log(cyclesCount * c + b);

        //result.push(totalTime);
        //console.log(totalTime.toString());
        return;
    });

    //result.forEach(r => console.log(r));
}

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i < Number(q[0]) + 1; i++) {
        console.log(solve(q[i].split(' ').map(str => Number(str))))
    }
}
function solve([a,b,c,d]) {
    if (c < d) {
        return -1
    }
    const times = Math.ceil((a - b) / (c - d));
    return b + times * c;
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    console.log(input)
    A(input);
})

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i < Number(q[0]) + 1; i++) {
        console.log(solve(q[i].split(' ').map(str => Number(str))))
    }
}
function solve([a,b,c,d]) {
    if ((a > b) && (c <= d)) {
        return -1
    }
    if (a <= b) {
        return b
    }
    const times = Math.ceil((a - b) / (c - d));
    return b + times * c;
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i < Number(q[0]) + 1; i++) {
        console.log(solve(q[i].split(' ').map(str => BigInt(str))).toString().slice(0, -1))
    }
}
function solve([a, b, c, d]) {
    if ((a > b) && (c <= d)) {
        return -1
    }
    if (a <= b) {
        return b
    }
    let times = (a - b) / (c - d);
    if (times * c < a - b) {
        times += 1n;
    }
    return b + times * c;
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i < Number(q[0]) + 1; i++) {
        console.log(solve(q[i].split(' ').map(str => BigInt(str))).toString().slice(0, -1))
    }
}
function solve([a, b, c, d]) {
    if ((a > b) && (c <= d)) {
        return -1
    }
    if (a <= b) {
        return b
    }
    let times = (a - b) / (c - d);
    if (times * (c - d) < a - b) {
        times += 1n;
    }
    return b + times * c;
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i < Number(q[0]) + 1; i++) {
        console.log(solve(q[i].split(' ').map(str => Number(str))))
    }
}
function solve([a,b,c,d]) {
    if ((a > b) && (c <= d)) {
        return -1
    }
    if (a <= b) {
        return b
    }
    const times = Math.ceil((a - b) / (c - d));
    return b + times * c;
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    console.log(input)
    A(input);
})

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i < Number(q[0]) + 1; i++) {
        console.log(solve(q[i].split(' ').map(str => Number(str))))
    }
}
function solve([a, b, c, d]) {
    if ((a > b) && (c <= d)) {
        return -1
    }
    if (a <= b) {
        return b
    }
    const times = Math.ceil((a - b) / (c - d));
    return BigInt(b + times * c);
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i < Number(q[0]) + 1; i++) {
        console.log(solve(q[i].split(' ').map(str => Number(str))))
    }
}
function solve([a, b, c, d]) {
    if ((a > b) && (c <= d)) {
        return -1
    }
    if (a <= b) {
        return b
    }
    const times = Math.ceil((a - b) / (c - d));
    return String(BigInt(b) + BigInt(times * c));
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i < Number(q[0]) + 1; i++) {
        console.log(solve(q[i].split(' ').map(str => Number(str))))
    }
}
function solve([a, b, c, d]) {
    if ((a > b) && (c <= d)) {
        return -1
    }
    if (a <= b) {
        return b
    }
    const times = Math.ceil((a - b) / (c - d));
    return Number(BigInt(b) + BigInt(times * c));
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i < Number(q[0]) + 1; i++) {
        console.log(solve(q[i].split(' ').map(str => Number(str))))
    }
}
function solve([a, b, c, d]) {
    if ((a > b) && (c <= d)) {
        return -1
    }
    if (a <= b) {
        return b
    }
    const times = Math.ceil((a - b) / (c - d));
    return b + times * c;
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

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

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

  let [a, b, c, d] = data.split(' ').map(Number);
  let ans = b;
  let r = a - b;

  if (r <= 0) {
    console.log(ans);
    return;
  }

  if (c <= d) {
    console.log(-1);
    return;
  }

  ans += Math.ceil(r / (c - d)) * c;

  console.log(ans);
  count++;
});

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

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

  let [a, b, c, d] = data.split(' ').map(BigInt);
  let ans = b;
  let r = a - b;

  if (r <= 0n) {
    console.log(ans.toString());
    return;
  }

  if (c <= d) {
    console.log(-1);
    return;
  }

  let temp = r / (c - d);
  if (temp < r) {
    temp += 1n;
  }

  ans += temp * c;

  console.log(ans.toString());
  count++;
});


A colored stripe is represented by a horizontal row of n square cells, each cell is pained one of k colors. Your task is to repaint the minimum number of cells so that no two neighbouring cells are of the same color. You can use any color from 1 to k to repaint the cells.

The first input line contains two integers n and k (1 ≤ n ≤ 5·105; 2 ≤ k ≤ 26). The second line contains n uppercase English letters. Letter "A" stands for the first color, letter "B" stands for the second color and so on. The first k English letters may be used. Each letter represents the color of the corresponding cell of the stripe.

Print a single integer — the required minimum number of repaintings. In the second line print any possible variant of the repainted stripe.

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], k = data[1],
		s = trim(readline()),
		ribbon = new Array(n);
	for (var i = 0; i < n; ++i) {
		ribbon[i] = s.charCodeAt(i)-65;
	}
	var newRibbon = new Array(n);
	newRibbon[0] = s.charAt(0);
	if (k != 2) {
		var cost = 0;
		for (var i = 1; i <= n-2; ++i) {
			var a = ribbon[i-1], b = ribbon[i], c = ribbon[i+1];
			if (b == a) {
				for (b = 0; b < k; ++b) {
					if (b != a && b != c) {
						ribbon[i] = b;
						break;
					}
				}
				++cost;
			}
			newRibbon[i] = String.fromCharCode(65+ribbon[i]);
		}
		if (n != 1 && ribbon[n-1] == ribbon[n-2]) {
			for (var b = 0; b < k; ++b) {
				if (b != ribbon[n-2]) {
					ribbon[n-1] = b;
					break;
				}
			}
			++cost;
		}
		newRibbon[n-1] = String.fromCharCode(65+ribbon[n-1]);
		print(cost);
		print(newRibbon.join('').toUpperCase());
		return;
	} else {
		var dp = new Array(n);
		dp[0] = new Array(2);
		for (var c = 0; c < 2; ++c) {
			dp[0][c] = (ribbon[0] == c ? 0 : 1);
		}
		for (var i = 1; i < n; ++i) {
			dp[i] = [n, n];
			for (var c = 0; c < 2; ++c) {
				dp[i][c] = Math.min(dp[i][c], (ribbon[i] == c ? 0 : 1) +
						dp[i-1][c == 0 ? 1 : 0]);
			}
		}
		var best = dp[n-1][0], c = 0;
		if (dp[n-1][1] < best) {
			best = dp[n-1][1];
			c = 1;
		}
		for (var i = n-1; i >= 0; --i) {
			newRibbon[i] = String.fromCharCode(65+c);
			c = (c == 0 ? 1 : 0);
		}
		print(best);
		print(newRibbon.join(''));
	}
}

main();

var nk = readline().split(' ').map(Number);
var n = nk[0];
var k = nk[1];
var s = readline();
if (k == 2){
	var count1 = 0;
	var count2 = 0;
	if (n%2 == 0) {
		var s1 = 'AB'.repeat(n/2);
		var s2 = 'BA'.repeat(n/2);
	} else {
		var s1 = 'AB'.repeat(n/2) + 'A';
		var s2 = 'BA'.repeat(n/2) + 'B';
	}
	for (var i=0; i<n; i++) {
		if (s[i] != s1[i]) count1++;
		else count2++;
	}
	if (count2>count1){
		print(count1);
		print(s1);
	} else {
		print(count2);
		print(s2);
	}
} else {
	s = s.split('');
	var count = 0;
	for (var i=0; i<n-1; i++) {
	if (s[i] == s[i+1]) {
	count++;
	if (i == n-2){
			if (s[i] == 'A') s[i+1] = 'B';
			else s[i+1] = 'A';
		} else {
			if (s[i] != 'A' && s[i+2] != 'A') s[i+1] = 'A';
			if (s[i] != 'B' && s[i+2] != 'B') s[i+1] = 'B';
			if (s[i] != 'C' && s[i+2] != 'C') s[i+1] = 'C';
		}
	}
}
print(count);
print(s.join(''));
}


Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise.However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0, 1, 0, 1}, {1, 0, 1}, and {1, 0, 1, 0} are alternating sequences, while {1, 0, 0} and {0, 1, 0, 1, 1} are not.Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have.

The first line contains the number of questions on the olympiad n (1 ≤ n ≤ 100 000). The following line contains a binary string of length n representing Kevin's results on the USAICO.

Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring.

NoteIn the first sample, Kevin can flip the bolded substring '10000011' and turn his string into '10011011', which has an alternating subsequence of length 5: '10011011'.In the second sample, Kevin can flip the entire string and still have the same score.

var x = readline();
var n = readline();
var ans = 1;
for(var i=1; i<n.length; i++) {
    if(n[i] != n[i-1]) ans++;
}
var add = 0;
if(n.length == 1) {
    print(1);
} else {
    var pos = -1;
    for(var i=1; i<n.length; i++) {
        if(n[i] == n[i-1]) {
            if(pos == -1) {pos = i; add = 1;}
            else add = 2;
        }
    }
    print(ans+add);
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const s = getLine()[0]

  let lastZero = 0
  let lastOne = 0
  const L = []
  const R = []

  for (let i = 0; i < n; ++i) {
    if (s[i] === '0') {
      lastZero = lastOne + 1
      L[i] = lastZero
    } else {
      lastOne = lastZero + 1
      L[i] = lastOne
    }
  }

  lastZero = lastOne = 0
  for (let i = n - 1; i >= 0; --i) {
    if (s[i] === '0') {
      lastZero = lastOne + 1
      R[i] = lastZero
    } else {
      lastOne = lastZero + 1
      R[i] = lastOne
    }
  }

  let ans = 0
  let i = 0
  while (i < n) {
    let j = i + 1
    const a = i
    while (j < n && s[j - 1] !== s[j]) {
      j ++
    }

    const b = j - 1
    const cur = b - a + 1

    const best = calc(a, b, s, L, R)
    ans = Math.max(ans, cur + best)
    i = j
  }
  print(ans)
}

function calc(a, b, s, L, R) {
  const n = s.length
  let one = (a - 1 >= 0 ? L[a - 1] - (s[a] === s[a - 1] ? 1 : 0): 0)
  one += (b + 1 < n ? R[b + 1] - (s[b] === s[b + 1] ? 1 : 0): 0)

  const left =  (s[a] === '0' ? '1' : '0')
  const right = (s[b] === '0' ? '1' : '0')

  let two = (a - 1 >= 0 ? L[a - 1] - (left === s[a - 1] ? 1 : 0): 0)
  two += (b + 1 < n ? R[b + 1] - (right === s[b + 1] ? 1 : 0): 0)

  return Math.max(one, two)
}

var input = readline().split(' ').map(Number), n = input[0];
var str = readline();

var counter = 0;
for (var i = 1; i < str.length; i++) {
    if (str[i] != str[i-1]) counter++;
}
write(Math.min(counter + 3, n));

var x = readline();
var n = readline();
var ans = 1;
for(var i=1; i<n.length; i++) {
    if(n[i] != n[i-1]) ans++;
}
var add = 0;
if(n.length == 1) {
    print(1);
} else {
    if(n[0] == n[1]) add = 1;
    if(n[n.length-1] == n[n.length-2]) add = 1;
    var pos = -1;
    for(var i=1; i<n.length; i++) {
        if(n[i] == n[i-1]) {
            if(pos == -1) pos = i;
            else add = 2;
        }
    }
    print(ans+add);
}

var x = readline();
var n = readline();
var ans = 1;
for(var i=1; i<n.length; i++) {
    if(n[i] != n[i-1]) ans++;
}
var add = 0;
if(n.length == 1) {
    print(1);
} else {
    if(n[0] == n[1]) add = 1;
    if(n[n.length-1] == n[n.length-2]) add = 1;

    for(var i=1; i<n.length-1; i++) {
        if(n[i] == n[i-1] && n[i+1] == n[i]) add = 2;
    }
    print(ans+add);
}

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const n = getInt()
  const s = getLine()[0]

  let lastZero = 0
  let lastOne = 0
  const L = [[0,0]]
  const R = []
  R[n] = [0, 0]

  for (let i = 0; i < n; ++i) {
    let best = 0
    L[i + 1] = []
    if (s[i] === '0') {
      best = lastOne + 1
      L[i + 1][0] = best
      L[i + 1][1] = lastZero + 1
      lastZero = best
    } else {
      best = lastZero + 1
      L[i + 1][0] = lastOne + 1
      L[i + 1][1] = best
      lastOne = best
    }
  }

  lastZero = lastOne = 0
  for (let i = n - 1; i >= 0; --i) {
    let best = 0
    R[i] = []
    if (s[i] === '0') {
      best = lastOne + 1
      R[i][0] = best
      R[i][1] = lastZero + 1
      lastZero = best
    } else {
      best = lastZero + 1
      R[i][0] = lastOne + 1
      R[i][1] = best
      lastOne = best
    }
  }

  let ans = 0
  let i = 0
  while (i < n) {
    let j = i + 1
    const a = i
    while (j < n && s[j - 1] !== s[j]) {
      j ++
    }
    const b = j - 1
    const cur = Math.max(b - a - 2, 0)
    const best = calc(b, a, s, L, R)
    ans = Math.max(ans, cur + best)
    i ++
  }
  print(ans)
}

function calc(a, b, s, L, R) {
  const left = (s[a] != '0' ? 0 : 1)
  const right = (s[b] != '0' ? 1: 0)

  return Math.max(R[a][left] + L[b][right], R[a][!left ? 1 : 0] + L[b][!right ? 1 : 0])
}

var input = readline().split(' ').map(Number), n = input[0];
var str = readline();
var arr = str.split('');

if (str.indexOf('000') >= 0) {
    var k = str.indexOf('000');
    arr[k+1] = '1';
} else if (str.indexOf('111') >= 0) {
    k = str.indexOf('111');
    arr[k+1] = '0';
} else if (str.substr(0,2) == '00') {
    arr[0] = '1';
} else if (str.substr(0,2) == '11') {
    arr[1] = '0';
} else if (str.substr(-2,2) == '00') {
    arr[arr.length - 1] = '1';
} else if (str.substr(-2,2) == '11') {
    arr[arr.length - 1] = '0';
}
var counter = 0;
for (var i = 1; i < str.length; i++) {
    if (arr[i] != arr[i-1]) counter++;
}
write(counter+1);


Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time period. For each query, we know its time... and nothing else, because Polycarpus has already accidentally removed the user IDs corresponding to the requests from the database. Thus, it is now impossible to determine whether any two requests are made by the same person or by different people.But wait, something is still known, because that day a record was achieved — M simultaneous users online! In addition, Polycarpus believes that if a user made a request at second s, then he was online for T seconds after that, that is, at seconds s, s + 1, s + 2, ..., s + T - 1. So, the user's time online can be calculated as the union of time intervals of the form [s, s + T - 1] over all times s of requests from him.Guided by these thoughts, Polycarpus wants to assign a user ID to each request so that:  the number of different users online did not exceed M at any moment,  at some second the number of distinct users online reached value M,  the total number of users (the number of distinct identifiers) was as much as possible. Help Polycarpus cope with the test.

The first line contains three integers n, M and T (1 ≤ n, M ≤ 20 000, 1 ≤ T ≤ 86400) — the number of queries, the record number of online users and the time when the user was online after a query was sent. Next n lines contain the times of the queries in the format "hh:mm:ss", where hh are hours, mm are minutes, ss are seconds. The times of the queries follow in the non-decreasing order, some of them can coincide. It is guaranteed that all the times and even all the segments of type [s, s + T - 1] are within one 24-hour range (from 00:00:00 to 23:59:59).

In the first line print number R — the largest possible number of distinct users. The following n lines should contain the user IDs for requests in the same order in which the requests are given in the input. User IDs must be integers from 1 to R. The requests of the same user must correspond to the same identifiers, the requests of distinct users must correspond to distinct identifiers. If there are multiple solutions, print any of them. If there is no solution, print "No solution" (without the quotes).

NoteConsider the first sample. The user who sent the first request was online from 17:05:53 to 17:06:02, the user who sent the second request was online from 17:05:58 to 17:06:07, the user who sent the third request, was online from 17:06:01 to 17:06:10. Thus, these IDs cannot belong to three distinct users, because in that case all these users would be online, for example, at 17:06:01. That is impossible, because M = 2. That means that some two of these queries belonged to the same user. One of the correct variants is given in the answer to the sample. For it user 1 was online from 17:05:53 to 17:06:02, user 2 — from 17:05:58 to 17:06:10 (he sent the second and third queries), user 3 — from 22:39:47 to 22:39:56.In the second sample there is only one query. So, only one user visited the network within the 24-hour period and there couldn't be two users online on the network simultaneously. (The time the user spent online is the union of time intervals for requests, so users who didn't send requests could not be online in the network.)

var InputReader = (function () {
    function InputReader() {
        this.index = 0;
        this.tokenizer = [];
    }
    InputReader.prototype.next = function () {
        while (this.tokenizer == null || this.index == this.tokenizer.length) {
            this.tokenizer = readline().split(" ");
            this.index = 0;
        }
        var res = this.tokenizer[this.index++];
        return res;
    };
    InputReader.prototype.nextInt = function () {
        return parseInt(this.next());
    };
    InputReader.prototype.nextFloat = function () {
        return parseFloat(this.next());
    };
    return InputReader;
})();

function main() {
    var input = new InputReader();

    var n = input.nextInt();
    var m = input.nextInt();
    var t = input.nextInt();

    t--;
    var ts = [], id = [];
    ts[-1] = -100000;
    id[-1] = 0;
    var p = -1;
    var online = 1;
    var record = false;
    for (var i = 0; i < n; i++) {
        var hours, minutes, seconds;
        var time = input.next();
        var val = time.split(":").map(function (el) {
            return parseInt(el);
        });
        ts[i] = val[0] * 3600 + val[1] * 60 + val[2];
        id[i] = id[i - 1] + 1;
        online++;
        while (ts[p] + t < ts[i]) {
            online -= id[p] != id[p + 1];
            p++;
        }
        if (online == m) record = true;
        if (online > m) {
            id[i] = id[i - 1];
            online--;
        }
    }
    if (!record) {
        print("No solution");
    } else {
        print(id[n - 1]);
        id.forEach(function (el) {
            print(el);
        });
    }
}

main();