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

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
// console.log(input)
var T = readline();
// var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
  var n = readline()//.split(' ').map((x) => parseInt(x));
  // var a = readline().split(' ').map((x) => parseInt(x));
  var len = n.length;
  var val = Math.pow(10, len-1);
  // console.log(len, val)
  val = max(val, 0);
  // n -= 0;
  var ans = n - val;
  console.log(ans)

}

var tens = [];
    for (var i=0; i < 10; i++) {
        tens.push(Math.pow(10,i));
    }
    var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        var m = parseInt(readline());
        var i = 1;
        while (tens[i] && m >= tens[i]) {
            i++;
        }
        print(m-tens[i-1]);
    }

const main = () => {

	var t = readInt();
	var allans = [];
	for (var zz = 0; zz < t; zz++) {
		var m = readInt();
		var x = 1;
		while (x * 10 <= m) {
			x *= 10;
		}
		var ans = m - x;
		allans.push(ans);
	}
	multiLineArrayPrint(allans);

	return;
}

const readInt = () => parseInt(readline());
const readString = () => readline();
const readIntArr = () => readline().split(" ").map(zzzz => parseInt(zzzz));
const parseLong = (string) => { // javascript's largest long is < (1<<62)
	var n = string.length;
	var res = 0;
	for (var i = 0; i < n; i++) {
		res *= 10;
		res += parseInt(string[i]);
	}
	return res;
}
const readLong = () => parseLong(readLong());
const readLongArr = () => readline().split(" ").map(zzzz => parseLong(zzzz));
const oneLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join(' '));
const multiLineArrayPrint = (arr) => print(arr.map(zzzz => zzzz.toString()).join('\n'));
const multiLineArrayOfArraysPrint = (arr) => print(arr.map(yyyy => yyyy.map(zzzz => zzzz.toString()).join(' ')).join('\n'));
const makeArr = (defaultVal, dimensionsArr) => {
	var n = dimensionsArr.length;
	if (n === 1) return Array(dimensionsArr[0]).fill(defaultVal);
	else {
		var temp = [];
		for (var i = 0; i < dimensionsArr[0]; i++)
			temp.push(makeArr(defaultVal, dimensionsArr.slice(1)));
		return temp;
	}
}

for (_ = 0; _ < 1; _++) {
	main();
}

// newline for testing
 //newline for testing
// codeforces js cannot use "let" keyword. use "var" instead
// codeforces js cannot destructure arrays

t = parseInt(readline());

var ans =0, n ;

while(t--)
{
    ans =1;
    //n= prompt();
    n= parseInt(readline());

   while(ans*10<=n) ans*=10;

   print(n-ans);
   //console.log(n-ans);

}

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 n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

         e = '1'
        for(l = 0; l < k.length - 1; l++){
            e += '0'
        }
        e = Number(e)

        if(b < 10){
            console.log(b-1)
        }else{

            console.log(k.join('')-e)

        }

    }

});

// как меня заебала эта корявая платформа
// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node
// // cat .\input.txt | node .\script.js
const state = { i: 0 }
const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});
const ten_exp = (exp = 0) => 10 ** exp
rl.on('line', function (line) {
    if (state.i > 0) console.log((line - ten_exp(line.length - 1)).toString() + '\r')
    state.i++
})

const readline = require('readline');

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

function getRound(m) {
    let s = 0
    let base = 10
    let t = 0
    while (t <= m) {
        s++;
        t = Math.pow(base,s)
    }
    return  m - Math.pow(base,s - 1)
}
let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    const [n,...values] = lines
    for (let i = 0; i< n; i++) {
        const ans = getRound(values[i])
        console.log(ans)
    }
});

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];
    for(i = 1; i <= t; i++){
        var a = lines[i];
        var k = lines[i].split('').map(Number);
        if(a < 10){
            console.log(a - 1);
        }else{
            var fl = '1';
            var len = k.length;
            for(j = 1; j < len; j++){
                fl += '0';
            }
            console.log(a - fl);
        }
    }
});

"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 tests = parseInt(readline());
    for (let t = 0;t < tests; ++t) {
        var x = parseInt(readline());
        let prev = 1;
        let next = 1;
        let ans = 1;
        while (next <= x) {
            ans = Math.min(Math.abs(x-prev),Math.abs(x-next));
            prev = 10;
            next *= 10;
        }
        console.log(ans);
    }
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = readline().trim();
    let p = n.length,
      k = 10;
    if (p === 1) {
      console.log(parseInt(n) - 1);
      continue;
    }
    for (let i = 2; i < p; i++) k = k * 10;
    console.log(Math.abs(parseInt(n) - k));
  }
};
solve();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function 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 price = readline();
        let target = 0;
        if (price.length === 1) {
            target = 1
        } else {
            target = Number('1' + ('0').repeat(price.length - 1));
        }
        output(Number(price) - target);

    }
}

'use strict';

function solve(n, m, s) {
  return n - 10 ** (n.toString().length - 1);
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const n = Number(await read());
      res[i] = solve(n);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

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) {
    const k = Math.floor(Math.log10(n))
    return n - 10 ** k
}

//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 M = nextInt();
		var d = 0;
		var now = 1;
		while(true){
			if(now * 10 <= M){
				now *= 10;
			}else{
				break;
			}

		}
		myout(M - now);
	}
}

T = readline()
while (T--) {
   m = readline().split('').map(el => +el)

   if(m[0] !=1){
      m[0] = m[0] - 1
   }
   else{
      m.shift()
   }
   if(m.length){
      print(+m.join(''))
   }
   else{
      print('0')
   }

}

var limit = parseInt(readline());
for (var i = 0; i < limit; i++)
{
    var valueString = readline();
    var power = valueString.length;
    var value = parseInt(valueString);
    var roundNum = 1;
    for (var j = 1; j < power; j++)
    {
        roundNum *= 10;
    }
    var result = value - roundNum;
    print(result);
}

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 n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

         e = 1
        for(l = 0; l < k.length - 1; l++){
            e += '0'
        }
        if(b < 10){
            console.log(b-1)
        }else{

            console.log(k-e)

        }

    }

});

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 n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(b < 10){
            console.log(b-1)
        }else{

            console.log(k.join(''))

        }

    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL); /*your input text, split by lines*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(b < 10){
            console.log(b)
        }else{

            console.log(k.join(''))

        }

    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL); /*your input text, split by lines*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(k[0] === 0 && k.length > 1){
            k.splice(0,1)
        }
        console.log(k.join(''))

    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL); /*your input text, split by lines*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(k[0] === 0){
            k.splice(0,1)
        }
        console.log(k.join(''))

    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL); /*your input text, split by lines*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(k[0] === 0 && k.length < 1){
            k.splice(0,1)
        }
        console.log(k.join(''))

    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL); /*your input text, split by lines*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        if(k[0] === 0 && k.length <= 1){
            k.splice(0,1)
        }
        console.log(k.join(''))

    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL); /*your input text, split by lines*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split('').map(Number)
        b = lines[j]

        k[0] -= 1
        console.log(k.join(''))

    }

});

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL); /*your input text, split by lines*/
    var n = lines[0]
    for(j = 1; j <= n; j++){
        k = lines[j].split(" ").map(Number)

        a = Math.abs(k[0] - 1);
        b = Math.abs(k[2] - k[1]) + Math.abs(k[2] - 1);
          if (a < b) {
            console.log(1);
          } else if (b < a) {
            console.log(2);
          } else {
            console.log(3);
          }

    }

});

// cat .\input.txt | node .\script.js
const state = { data: [] };
const consume = (chunk) => {
    const chunk_string = chunk.toString()
    const split = chunk_string.split('\r\n').filter(v => v.length > 0)
    for (let i = 0; i < split.length; i++) {
        const element = split[i];
        if (element.indexOf(' ') == -1) {
            state.data.push(Number(element))
            continue
        }
        // if (element.indexOf(' ') > -1) {
        //     state.data.push(element.split(' ').map(Number))
        //     continue
        // }
    }
}
const commit = (answer) => process.stdout.write(answer);
const ten_ext = (exp = 0) => 10 ** exp
const main = (args) => {
    const { data } = state
    const range = data.shift()
    let result = ""
    for (let i = 0; i < range; i++) {
        const element = data[i];
        const etos = element.toString()
        const etosl = etos.length
        result += ((element - ten_ext(etosl - 1)).toString() + '\r\n')
    }
    commit(result)
};
process.stdin
    .on("data", consume)
    .on("end", main);

// cat .\input.txt | node .\script.js
const state = { data: [] };
const consume = (chunk) => {
    const chunk_string = chunk.toString()
    const split = chunk_string.split('\r\n').filter(v => v.length > 0)
    for (let i = 0; i < split.length; i++) {
        const element = split[i];
        if (element.indexOf(' ') == -1) {
            state.data.push(Number(element))
            continue
        }
        if (element.indexOf(' ') > -1) {
            state.data.push(element.split(' ').map(Number))
            continue
        }
    }
}
const commit = (answer) => process.stdout.write(answer);
const ten_ext = (exp = 0) => 10 ** exp
const main = (args) => {
    const { data } = state
    const range = data.shift()
    let result = ""
    for (let i = 0; i < range; i++) {
        const element = data[i];
        const etos = element.toString()
        const etosl = etos.length
        result += ((element - ten_ext(etosl - 1)).toString() + '\r\n')
    }
    commit(result)
};
process.stdin
    .on("data", consume)
    .on("end", main);

// cat .\input.txt | node .\script.js
const state = { data: [] };
const consume = (chunk) => {
    const chunk_string = chunk.toString()
    const split = chunk_string.split('\r\n').filter(v => v.length > 0)
    for (let i = 0; i < split.length; i++) {
        const element = split[i];
        if (element.indexOf(' ') == -1) {
            state.data.push(Number(element))
            continue
        }
        if (element.indexOf(' ') > -1) {
            state.data.push(element.split(' ').map(Number))
            continue
        }
    }
    state.input_counter++
}
const commit = (answer) => process.stdout.write(answer);
const ten_ext = (exp = 0) => 10 ** exp
const main = (args) => {
    const { data } = state
    const range = data.shift()
    for (let i = 0; i < range; i++) {
        const element = data[i];
        const etos = element.toString()
        const etosl = etos.length
        commit((element - ten_ext(etosl - 1)).toString() + '\r\n')
    }
};
process.stdin
    .on("data", consume)
    .on("end", main);

const readline = require('readline');

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

function getRound(m) {
    let s = 0
    let base = 10
    let t = 0
    while (t < m) {
        t = Math.pow(base,++s)
    }
    return m === t ? 0 : m - Math.pow(base,s - 1)
}
let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    const [n,...values] = lines
    for (let i = 0; i< n; i++) {
        const ans = getRound(values[i])
        console.log(ans)
    }
});

const readline = require('readline');

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

function getRound(m) {
    let s = 0
    let base = 10
    let t = 0
    while (t < m) {
        t = Math.pow(base,++s)
    }
    return m - Math.pow(base,--s)
}
let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    const [n,...values] = lines
    for (let i = 0; i< n; i++) {
        const ans = getRound(values[i])
        console.log(ans)
    }
});

const readline = require('readline');

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

function getRound(m) {
    let s = 0
    let base = 10
    let t = 0
    while (t < m) {
        t = Math.pow(base,++s)
    }
    return m - (t/10)
}
let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    const [n,...values] = lines
    for (let i = 0; i< n; i++) {
        const ans = getRound(values[i])
        console.log(ans)
    }
});

T = readline()
while (T--) {
   m = readline().split('').map(el => +el)

   if(m[0] !=1){
      m[0] = m[0] - 1
   }
   else{
      m.shift()
   }
   if(m.length){
      print(m.join(''))
   }
   else{
      print('0')
   }

}

var tens = [];
    for (var i=0; i < 10; i++) {
        tens.push(Math.pow(10,i));
    }
    var tests = parseInt(readline());
    for (var t=0; t < tests; t++) {
        var m = parseInt(readline());
        var i = 1;
        while (tens[i] && m > tens[i]) {
            i++;
        }
        print(m-tens[i-1]);
    }


// n = glass container width, k = glass height, b = |filled glass liquid height|, s = |total liquid height|
function solve(n, k, b, s){
    // const FIRST_GLASS = (k+1) * b - 1;
    // const REST_GLASS = b - 1;
    const FIRST_GLASS = k * (b+1) - 1;
    const REST_GLASS = k - 1;
    const MIN_CAPACITY = k * b;
    const MAX_CAPACITY = FIRST_GLASS + ((n-1) * REST_GLASS);
    if(s < MIN_CAPACITY || s > MAX_CAPACITY) return [-1]; // RTE if not arr

    const result = Array(n).fill(0);

    for(let i=0;i<n;i++){
        let cmp = s;
        if(i===0){
            cmp = Math.min(s, FIRST_GLASS);
        }
        else {
            cmp = Math.min(s, REST_GLASS);
        }
        s-=cmp;
        result[i] = cmp;
    }
    return result;
}

function test(){
    console.log(solve(1, 6, 3, 100));
    console.log(solve(3, 6, 3, 12));
    console.log(solve(3, 6, 3, 19));
    console.log('hello CF')
}

// test();

/* --------------------------------------- submit ------------------------------------------ */

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

let data = ``;

process.stdin.on('data', string=>data+=string);
process.stdin.on('end', () => {
    const dataLines = data.split(EOL);
    B1715(dataLines);
});

/* --------------------------------------- local test ------------------------------------------

let data = `8
1 6 3 100
3 6 3 12
3 6 3 19
5 4 7 38
5 4 7 80
99978 1000000000 100000000 1000000000000000000
1 1 0 0
4 1000000000 1000000000 1000000000000000000`;

const dataLines = data.split('\n');
console.log(B1715(dataLines));

*/

/* --------------------------------------- boilerplate ------------------------------------------ */

function convertNumberArray(str){ // '  12   43 123 4 ' >> [12, 43, 123, 4]
    return str.replace(/ +/g, " ").trim().split(' ').map(string => Number(string));
}
function printArray(arr){ // [12, 43, 123, 4] >> '12 43 123 4'
    return arr.join(' ');
}
function B1715(input){
    let result = '';
    const tests = Number(input[0]);
    for(let i=1; i<=tests; i++){
        const [n, k, b, s] = convertNumberArray(input[i]);
        // process.stdout.write(solve(n, k, b, s) + '\n'); // array printing error
        process.stdout.write(printArray(solve(n, k, b, s)) + '\n');
        result+=solve(n, k, b, s) + '\n'
    }
    return result;
}

/*
answer
-1
-1
0 0 19
0 3 3 3 29
-1
-1
0
0 0 0 1000000000000000000

*/

var tests = parseInt(readline());
    var n, k, b, s;

    for (var t=0; t < tests; t++) {
        var nkbs = readline().split(' ').map(x=>parseInt(x));
        n = nkbs[0];
        k = nkbs[1];
        b = nkbs[2];
        s = nkbs[3];

        if (s < k * b || s > k * b + n * (k-1)) {
            print(-1);
            continue;
        }
        var ans = [];
        var sum = s;
        var first = b * k;
        first += Math.min(sum - b*k, k-1);
        ans.push(first);
        sum -= first;
        while (sum > 0) {
            var next = Math.min(k-1, sum);
            ans.push(next);
            sum -= next;
        }
        while (ans.length < n) {
            ans.push(0);
        }
        print(ans.join(' '));
    }

// n = glass container width, k = glass height, b = |filled glass liquid height|, s = |total liquid height|
function solve(n, k, b, s){
    // const FIRST_GLASS = (k+1) * b - 1;
    // const REST_GLASS = b - 1;
    const FIRST_GLASS = k * (b+1) - 1;
    const REST_GLASS = k - 1;
    const MIN_CAPACITY = k * b;
    const MAX_CAPACITY = FIRST_GLASS + ((n-1) * REST_GLASS);
    if(s < MIN_CAPACITY || s > MAX_CAPACITY) return -1;

    const result = Array(n).fill(0);

    for(let i=0;i<n;i++){
        let cmp = s;
        if(i===0){
            cmp = Math.min(s, FIRST_GLASS);
        }
        else {
            cmp = Math.min(s, REST_GLASS);
        }
        s-=cmp;
        result[i] = cmp;
    }
    return result;
}

function test(){
    console.log(solve(1, 6, 3, 100));
    console.log(solve(3, 6, 3, 12));
    console.log(solve(3, 6, 3, 19));
    console.log('hello CF')
}

// test();

/* --------------------------------------- submit ------------------------------------------ */

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

let data = ``;

process.stdin.on('data', string=>data+=string);
process.stdin.on('end', () => {
    const dataLines = data.split(EOL);
    B1715(dataLines);
});

/* --------------------------------------- local test ------------------------------------------ */

// let data = `8
// 1 6 3 100
// 3 6 3 12
// 3 6 3 19
// 5 4 7 38
// 5 4 7 80
// 99978 1000000000 100000000 1000000000000000000
// 1 1 0 0
// 4 1000000000 1000000000 1000000000000000000`;

// const dataLines = data.split('\n');
// console.log(B1715(dataLines));

/* --------------------------------------- boilerplate ------------------------------------------ */

function convertNumberArray(str){ // '  12   43 123 4 ' >> [12, 43, 123, 4]
    return str.replace(/ +/g, " ").trim().split(' ').map(string => Number(string));
}
function B1715(input){
    let result = '';
    const tests = Number(input[0]);
    for(let i=1; i<=tests; i++){
        const [n, k, b, s] = convertNumberArray(input[i]);
        process.stdout.write(solve(n, k, b, s) + '\n');
        result+=solve(n, k, b, s) + '\n'
    }
    return result;
}

/*
answer
-1
-1
0 0 19
0 3 3 3 29
-1
-1
0
0 0 0 1000000000000000000

*/


const n = Number(readline());
const s = Array.from(readline().substring(0, n), c => c === "b");
const t = Array.from(readline().substring(0, n), c => c === "b");
const results = (() => {
  if (s.concat(t).reduce((a, b) => a ^ b)) return null;
  var abs = [];
  var bas = [];
  for (var i = 0; i < n; i++)
    if (s[i] ^ t[i]) {
      if (t[i]) abs.push(i);
      else bas.push(i);
    }
  var results = [];
  while (abs.length >= 2)
    results.push([abs.pop(), abs.pop()]);
  while (bas.length >= 2)
    results.push([bas.pop(), bas.pop()]);
  if (abs.length) {
    if (!bas.length) return null;
    var x = abs.pop();
    results.push([x, x], [x, bas.pop()]);
  }
  return results;
})();
if (results) {
  print(results.length);
  for (var result of results)
    print(`${result[0] + 1} ${result[1] + 1}`);
} else print("-1");


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

let c = 0;

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

  const [a1, b1, c1, d1] = d.split(" ").map(Number);
  const ans = Number(a1 < b1) + Number(a1 < c1) + Number(a1 < d1);
  console.log(ans);

  // const numbers = d.split(" ").map(Number);
  // let me = numbers[0];
  // const ans = numbers.filter((x) => x > me).length;

  // console.log(ans);

  c++;
});

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

var n = readline();
var arr = [];
var s = 0;
for(var i = 0; i < n; i++){
    arr[i] = readline().split(' ').map(i=>Number(i));
    for(var j = 0; j < arr[i].length; j++){
        if(arr[i][0]<arr[i][j]){
            s+=1;

        }
    }
    print(s);
    s=0;
}

var limit = parseInt(readline());
    for (var i = 0; i < limit; i++) {
        var caseArray = readline().split(" ");
        var a = parseInt(caseArray[0]);
        var count = 0;
        for (var j = 1; j < caseArray.length; j++) {
            var value = parseInt(caseArray[j]);
            if (value > a)
                count++;
        }
        print(count);
    }

var t = parseInt(readline());

for (var test = 0; test < t; test++) {
    var inp = readline().split(' ');
    var a = parseInt(inp[0]);
    var b = parseInt(inp[1]);
    var c = parseInt(inp[2]);
    var d = parseInt(inp[3]);

    var ans = (b > a) + (c > a) + (d > a);

    print(ans);
}

var t = readline();
for(var  i =0 ; i < t ; i++){
    var inputs = readline().split(' '),
        counter = 0,
        timur = inputs[0],
        participants = inputs.slice(1);
        for(var j = 0 ; j < participants.length ; j++){
            if(parseInt(participants[j]) > parseInt(timur) ){
                counter++;
            }
        }
        print(counter);
}

var testCase=+readline(),counter
for(var i=0;i<testCase;i++){
    var sequence=readline().split(" ")
    var b=sequence[0]
    var a=sequence.sort((a,b)=>a-b)
    print(4-a.indexOf(b)-1)
}

test = readline();

while (test--) {
    input = readline().split(" ").map(x => parseInt(x));
    Timur = input[0];
    participantsInFront = 0;

    for (var i = 1; i <= 3; i++) {
        if (Timur < input[i]) {
            participantsInFront++;
        }
    }
    print(participantsInFront)
}

T = readline()
while (T--) {
   n = readline().split(' ').map(a => +a)
   a = n[0]
   b = n[1]
   c = n[2]
   d = n[3]

   ans = 0
   if(b>a)
      ans++
   if(c>a)
      ans++
   if(d>a)
      ans++

   print(ans)
}

// как меня заебала эта корявая платформа
// https://stackoverflow.com/questions/20086849/how-to-read-from-stdin-line-by-line-in-node
// // cat .\input.txt | node .\script.js
const state = { i: 0 }
const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});
const ten_exp = (exp = 0) => 10 ** exp
rl.on('line', function (line) {
    if (state.i > 0) {
        let data = line.split(' ').map(Number)
        let above = []
        for (let i = 1; i < data.length; i++) {
            const sample = data[0]
            const element = data[i];
            if (element > sample) above.push(element)

        }
        console.log(above.length)
    }
    state.i++
})

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];
    for(i = 1; i <= t; i++){
        var k = lines[i].split(' ').map(Number);
        var ans = 0;
	    for(j = 1; j < 4; j++){
            if(k[j] > k[0]){
	            ans++;
            }
	    }
	    console.log(ans);
    }
});

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];
	for(i = 1; i <= t; i++){
	        var k = lines[i].split(' ').map(Number);
	        var a = k[0];
	        var ans = 0;
	        for(j = 1; j < 4; j++){
	            if(k[j] > a){
	                ans++;
	            }
	        }
	        console.log(ans);
	}
});

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 numbers = d.split(" ").map(Number);
  let me = numbers[0];
  const ans = numbers.filter((x) => x > me).length;

  console.log(ans);

  c++;
});

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

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

const res = [];
rl.on('line', (line) => {
    const [timur, ...rest] = line.split(' ').map((n) => parseInt(n));
    if (rest.length !== 3) return;
    console.log(rest.filter(n => n > timur).length);
}).on('close', () => {
    process.exit();
});

'use strict';

function solve(a) {
  const [x, ...arr] = a;
  let res = 0;
  for (let num of a) if (num > x) res++;
  return res;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

const main = (input) => {
  input = input.split('\n')

  const t = Number(input[0])
  for (let i = 0; i < t; i++) {
    const [a, b, c, d] = input[i + 1].split(' ').map((x) => parseInt(x))

    let ans = 0
    ans += b > a ? 1 : 0
    ans += c > a ? 1 : 0
    ans += d > a ? 1 : 0

    console.log(ans)
  }
}

main(require('fs').readFileSync(0).toString())

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

let input = [];
let ans = [];

readline.on('line', line => {
    input.push(line);
}).on('close', () => {
    let cases = input.slice(1).map(v=>v.split(' ').map(Number));

    for (let c of cases) {
        ans.push(c.filter(v=>v>c[0]).length);
    }
    console.log(ans.join('\n'));

});

const { readFileSync } = require("fs")

let x = readFileSync("./input.fd0138e687.txt","utf-8").match(/(\d+\s){3}\d+/g)

for(let e of x){
   let [b,...a] = e.split(" ")
   console.log( a.filter(e=>+e>+b).length )
}

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});
let data = [];
let dataIdx = 0;

rl.on('line', function (line) {
  //input,
  data.push(...line.trim().split(' '));
}).on('close', function () {
  //output
  main();
  process.exit();
});

function input() {
  return data[dataIdx++];
}

function output(value) {
  try {
    process.stdout.write(value);
  } catch (err) {
    process.stdout.write(value.toString());
  }
}
//////////////////////////////////////////////////////////

function main() {
  //ps start!

  let t = Number(input());
  while (t--) {
    let [a, b, c, d] = [
      Number(input()),
      Number(input()),
      Number(input()),
      Number(input()),
    ];

    let result = 0;
    if (b > a) {
      result++;
    }
    if (c > a) {
      result++;
    }
    if (d > a) {
      result++;
    }
    output(result + '\n');
  }
}

"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const T = readline()
  for (let i = 0; i < T; i++) {
    const arr = readline().split(' ').map(Number)
    let result = 0
    for (let i = 1; i < arr.length; i++) {
      if (arr[i] > arr[0]) result++
    }
    console.log(result)
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function 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 [a,b,c,d] = readline().split(' ').map(Number);
        let r = 0;
        if (b > a) r++;
        if (c > a) r++;
        if (d > a) r++;
        output(r);
    }
}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0]
    for(j = 1; j <= n; j ++){
        var s = lines[j].split(' ').map(Number)
        var a = s[0]
        var b = s[1]
        var c = s[2]
        var d = s[3]
        var e = 0
        for(l = 1; l <= 4; l++){
        if(a < s[l]){
            e+=1
        }
        }
        console.log(e)
    }

});

function Solution() {
  let t = 0;
  const n = Number(lines[t++]);

  const res = [];
  for (let i = 0; i < n; i++) {
    const arr = lines[t++].split(' ').map((item) => Number(item));
    let count = 0;
    for (let z = 0; z < arr.length; z++) {
      if (arr[z] > arr[0]) count += 1;
    }
    res[i] = count;
  }

  return res.join('\n');
}

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', () => {
  console.log(Solution());
});

const rdline = require('readline');

const rl = rdline.createInterface({
    input: process.stdin
});

let lines = [];
rl.on('line', (line) => {
    lines.push(line);
}).on('close', () => {
    // input in lines
    solve();
});

let line = 0;
const readline = () => lines[line++];

solve = () => {
    const t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        n = 0;
        const s = readline().split(" ").map(Number);
        for (let j = 1; j < s.length; j++) {
            if (s[j] > s[0]) {
                n++;
            }
        }
        console.log(n);
    }
}

//Setup
let i = ''
let a;
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*/
  //console.log(lines);
  a=lines
//Actual Code
function stringToNumber(array){
    for (var i = 0; i < array.length; i++){
        array[i]=parseInt(array[i])
    }

    return array
}
var numTestes = a[0]
numTestes = parseInt(numTestes)
var testData = []
for(c=1;c<=numTestes;c++){
    testData.push(stringToNumber(a[c].split(" ")))
}

for(b=0;b<numTestes;b++){
    var ans = 0
    for(a=1;a<4;a++){
      if(testData[b][0]<testData[b][a]){
        ans++
      }

    }

    console.log(ans)

}

//End of Code

})

// Parsing input: https://codeforces.com/blog/entry/78878
process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

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

function main() {
    // Actual body code
    var T = parseInt(readLine());

    for (var t = 0; t < T; ++t) {
        let l = readLine();
        var xs = l.trim().split(" ").map(x => parseInt(x, 10));
        var a = xs[0];
        console.log(xs.slice(1).map(x => a < x).reduce((x, y) => x + y));
    }
}

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

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

    main();
});

const solve = (arr)=>{
     let a = arr[0],cnt = 0;
     for(let i=1;i<4;i++){
          if(arr[i]>a) cnt++;
     }
     return cnt;
}

function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       console.log(solve(arr));
  }
}
main();

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let a = nl.nums();
		let x = a.shift();
		let c = a.reduce((ac, e) => ac + ((e>x)?1:0), 0);
		ans.push(c);
	}
	console.log(ans.join('\n'));
};

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

/* Common Template Starts */
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++];
}
/* Common Template Ends */

function main() {
    let n = readline()

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

        let row = readline().split(' ')

        if (parseInt(row[0]) < parseInt(row[1])) {
            participants++
        }

        if (parseInt(row[0]) < parseInt(row[2])) {
            participants++
        }

        if (parseInt(row[0]) < parseInt(row[3])) {
            participants++
        }

        console.log(participants)
    }
}

/**
 * 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 solve() {
    let t = readSingleInt();
    while(t--)
    {
        let n  = readIntArray();
        let cnt = 0;
        for(let i=1;i<n.length;i++)
        {
            if(n[0]<n[i]){
                cnt++;
            }
        }
        console.log(cnt);

    }

}

'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 findKthLargest(nums, k) {
    k = nums.length - k;
    const quickSelect = (l, r) => {
        let pivot = nums[r];
        let p = l;
        for (let i = l; i < r; i++) {
            if (nums[i] <= pivot) {
                swapper(nums, p, i);
                p++;
            }
        }
        swapper(nums, p, r);

        if (p > k) return quickSelect(l, p - 1);
        else if (p < k) return quickSelect(p + 1, r);
        else return nums[p];
    };

    return quickSelect(0, nums.length - 1);
};

function swapper(array, a, b) {
    const temp = array[b];
    array[b] = array[a];
    array[a] = temp;
};

function main() {
    const n = parseInt(readline());
    for(var i=0; i<n; i++){
        const nums = readline().split(" ").map(r => parseInt(r));
        var count = 0;
        var num = nums[0];
        for(var j=1; j<4; j++){
            if(nums[j]>num){
                count++;
            }
        }
        foo(String(count));
    }
}
function foo(x) {
    process.stdout.write(x);   // without auto '\n' (newline)
    console.log();  // with auto '\n' (newline)
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function readline() {
  return standardInputString[currentLine++];
}
function print(data) {
  console.log(data);
}

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let q = parseInt(readline());
  for (let i = 0; i < q; i++) {
    let input = readline().split(" ").map(Number);
    print(R(input));
  }
}

function R(arr) {
  let count = 0;
  for (let i = 1; i < arr.length; i++) {
    if (arr[i] > arr[0]) count++;
  }
  return count;
}

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

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}
var T = readline();
for(var qe=1;qe<=T;qe++) {
  //var n = readline()//.split(' ').map((x) => parseInt(x));
  var [a,b,c,d] = readline().split(' ').map((x) => parseInt(x));
  var ans = 0;
  if(b > a) ans++
  if(c > a) ans++
  if(d > a) ans++
  console.log(ans)
  //fs.appendFileSync('output.txt', ans+'\r\n');

}
//

//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 list = [];
		for(var i = 0; i < 4; i++){
			list.push({
				no : i,
				v : nextInt()
			});
		}
		list.sort(function(a,b){
			return b.v - a.v;
		});
		for(var i = 0; i < 4; i++){
			if(list[i].no == 0){
				myout(i);
				break;
			}
		}
	}
}

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

function solve(arr) {
    let ans = 0
    for (let i = 1; i < arr.length; i++) {
        if (arr[i] > arr[0]) ans++
    }
    return ans
}

"use strict";

  let t = +(readline());

  for(let i=0;i<t;i++){
     solve(readline().split(' '));
  }

  function solve(dist){
     let cnt=0;

     for(let i=1;i<4;i++){

       if( +dist[i] > +dist[0])cnt++;
     }

      print(cnt);
  }

"use strict";

        let x = +(readline());

        for(let i = 0; i < x; i++) {
            marathone(readline().split(' '));
        }

        function marathone(distances) {
            let counter = 0;
            for(let i = 1; i < 4; i++) {
                let timurDistance = +distances[0];

                if(timurDistance < +distances[i]) {
                    counter++;
                }
            }

            print(counter);
        }

"use strict";

  let t = +(readline());

  for(let i=0;i<t;i++){
     solve(readline().split(' '));
  }

  function solve(dist){
     let cnt=0;

     for(let i=1;i<4;i++){

       if( (dist[i]) > (dist[0]))cnt++;
     }

      print(cnt);
  }

"use strict";

  let t = +(readline());

  for(let i=0;i<t;i++){
     solve(readline().split(' '));
  }

  function solve(dist){
     let cnt=0;

     for(let i=1;i<4;i++){

       if( +dist[i] > +dist[0])cnt++;
     }
      print(dist[0]);
      print(cnt);
  }

"use strict";

  let t = +(readline());

  for(let i=0;i<t;i++){
     solve(readline().split(' '));
  }

  function solve(dist){
     let cnt=0;

     for(let i=1;i<4;i++){
       if( dist[i] > dist[0])cnt++;
     }

      print(cnt);
  }

"use strict";

  let t = +(readline());

  for(let i=0;i<t;i++){
     solve(readline().split(' '));
  }

  function solve(dist){
     let cnt=0;

     for(let i=1;i<4;i++){
       if( dist[i] < dist[0])cnt++;
     }

      print(cnt);
  }

const state = { data: [] };
const consume = (chunk) => {
  const chunk_string = chunk.toString()
  const split = chunk_string.split('\r\n')
  split.forEach(e => {
    if (e.length == 1) e = Number(e)
    if (e.length > 1) e = e.split(' ').map(Number)
    state.data.push(e)
  })
  state.input_counter++
}
const commit = (answer) => process.stdout.write(answer);
const main = (args) => {
  let { data } = state
  const size = data.shift()
  data = data.slice(0, size)
  const target = data.reduce((a, e, i) => [...a, e[0]], [])
  const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))
  const results = sorted.map((e, i) => e.indexOf(target[i]))
  // console.log(results)
  results.forEach(e => commit(e + '\r\n'))
  return
};
process.stdin
  .on("data", consume)
  .on("end", main);

const state = { data: [] };
const consume = (chunk) => {
  const chunk_string = chunk.toString()
  const split = chunk_string.split('\r\n')
  split.forEach(e => {
    if (e.length == 1) e = Number(e)
    if (e.length > 1) e = e.split(' ').map(Number)
    state.data.push(e)
  })
  state.input_counter++
}
const commit = (answer) => process.stdout.write(answer);
const main = (args) => {
  const { data } = state
  const size = data.shift()
  const target = data.reduce((a, e, i) => [...a, e[0]], [])
  const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))
  const results = sorted.map((e, i) => e.indexOf(target[i]))
  // console.log(results)
  results.slice(0, size).forEach(e => commit(e + '\r\n'))
  return
};
process.stdin
  .on("data", consume)
  .on("end", main);

const state = { data: [] };
const consume = (chunk) => {
  const chunk_string = chunk.toString()
  const split = chunk_string.split('\r\n')
  split.forEach(e => {
    if (e.length == 1) e = Number(e)
    if (e.length > 1) e = e.split(' ').map(Number)
    state.data.push(e)
  })
  state.input_counter++
}
const commit = (answer) => process.stdout.write(answer);
const main = (args) => {
  const { data } = state
  data.shift()
  const target = data.reduce((a, e, i) => [...a, e[0]], [])
  const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))
  const results = sorted.map((e, i) => e.indexOf(target[i]))
  // console.log(results)
  results.forEach(e => commit(e + '\r\n'))
  return
};
process.stdin
  .on("data", consume)
  .on("end", main);

const state = { data: [] };
const consume = (chunk) => {
  const chunk_string = chunk.toString()
  const split = chunk_string.split('\r\n')
  split.forEach(e => {
    if (e.length == 1) e = Number(e)
    if (e.length > 1) e = e.split(' ').map(Number)
    state.data.push(e)
  })
  state.input_counter++
}
const commit = (answer) => process.stdout.write(answer);
const main = (args) => {
  const { data } = state
  data.shift()
  const target = data.reduce((a, e, i) => [...a, e[0]], [])
  const sorted = data.map(e => Array.from(e).sort((a, b) => b - a))
  const results = sorted.map((e, i) => e.indexOf(target[i]))
  commit(results.join('\r\n'))
};
process.stdin
  .on("data", consume)
  .on("end", main);

var state = { data: [] };
var element, i, j = null;
function consume(chunk) {
  try {
    var chunk_string = chunk.toString("utf-8");
    var split = chunk_string.split('\r\n');
    for (i = 0; i < split.length; i++) {
      element = split[i];
      if (element.length == 1) {
        element = parseInt(element);
      }
      if (element.length > 1) {
        element = element.split(' ');
        for (j = 0; j < element.length; j++) {
          element[j] = parseInt(element[j]);
        }
      }
      state.data.push(element);
    }
    return;
  } catch (error) {
    process.stdout.write(error.message);
  }
}
function commit(answer) {
  try {
    process.stdout.write(answer);
    return;
  } catch (error) {
    process.stdout.write(error.message);
  }
}
function main() {
  try {

    var data = state.data;
    var target = [];
    var results = [];
    var sorted = [];
    // data.reduce((a, e, i) => [...a, e[0]], []);
    // sorted.map((e, i) => e.indexOf(target[i]));
    //data.map(e => e.sort((a, b) => b - a));
    // results.forEach(e => commit(e + '\r\n'));
    data.shift();
    for (i = 0; i < data.length; i++) {
      element = data[i];
      target.push(element[0]);
    }
    for (i = 0; i < data.length; i++) {
      element = data[i];
      sorted.push(element.sort((a, b) => b - a));
    }
    for (i = 0; i < sorted.length; i++) {
      element = sorted[i];
      results.push(element.indexOf(target[i]));
    }
    for (i = 0; i < results.length; i++) {
      const element = results[i];
      commit(element + '\n');
    }
    return;
  } catch (error) {
    process.stdout.write(error.message);
  }
}
process.stdin
  .on("data", consume)
  .on("end", main);

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

const read = () => new Promise(res => {
    rl.on('line', (line) => res(line));
});

async function main()
{
    const n = await read();
    for (let i = 0; i < n; i++) {
        const line = await read();
        const [timur, ...rest] = line.split(' ').map((n) => parseInt(n));
        process.stdout.write(`${rest.filter(n => n > timur).length}`);
    }
}

main();


const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    const [n, m] = lines[i+1].split(' ').map(x => +x)
    if (n === 1) {
      console.log(0)
    } else {
      if (n === 2) {
        console.log(m)
      } else {
        console.log(m * 2)
      }
    }
  }
}

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("inputString", inputString)

    //console.log("typeof inputString", typeof inputString)
    const tests = inputString.slice(1).map(item => item.split(" ").map(Number));

    //console.log("tests", tests);

    let result = [];

    for (let i = 0; i < tests.length; i++) {
        //console.log("tests[i]", tests[i]);
        const [n, m] = tests[i];

        if (n === 1) {
            result.push(0);
        } else if (n === 2) {
            result.push(m);
        } else {
            result.push(m * 2);
        }
    }

    result.forEach(item => console.log(item));
}

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

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

let main = () => {
    let t = parseInt(readline());
    while( t > 0 ){
    	let [n, m] = readline().split(" ").map(Number);
    	if( n === 1 )
    		console.log(0);
    	else if( n ===  2 )
    		console.log(m);
    	else
    		console.log(2*m);
    	t = t-1;
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readLine() {
    return inputString[currentLine++];
}
/*****************************************************************/
function main() {
    let t = readLine();
    t = parseInt(t);
    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 solve(n,m) {
    if (n == 1) return 0;
    if (n == 2) return m;
    return 2*m;
}
var tc = Number(readline())
while (tc--) {
  var inputArr = readline().split(" ").map(function(a) { return +a })
  var n = inputArr[0]
  var m = inputArr[1]
  print(solve(n,m))
}

'use strict';

const parseProblem = (line, problem) => {
    if (!problem.T || problem.T === 0) {
        problem.T = parseInt(line);
        return problem;
    }

    const cases = problem.cases;

    //if (cases.length === 0 || cases[cases.length - 1].arr) {
        cases.push({
            s: line
        });
    /*} else {
        cases[cases.length - 1].arr = line;
    }*/

    const isProcessing = cases.length < problem.T;// || !cases[cases.length - 1].arr;
    problem.isProcessing = isProcessing;

    return problem;
};

const solve = data => {
    const [n, m] = data.s.split(' ').map(i => +i);
    let sum = (n == 1) ? 0 : m;

    if(n > 2) {
        sum = 2 * m;
    }

    return sum;
}

const solveCases = cases => {
    for (let index = 0; index < cases.length; index++) {
        const result = solve(cases[index]);
        console.log(result);
    }
};

const main = () => {
    const readline = require('readline');

    let problem = {
        T: 0,
        cases: [],
        isProcessing: true
    };

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

    rl.on('line', line => {
        problem = parseProblem(line, problem);

        if (!problem.isProcessing) {
            rl.close();
        }
    }).on('close', () => {
        solveCases(problem.cases);
        process.exit(0);
    });
};

if (!module.parent) {
    main();
}

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});
rl.on('line', (line) => {
  const l = line.split(' ').map(v => +v);
  if (l.length > 1) {
    if (l[0] === 1) {
      process.stdout.write(`0\n`);
    } else if (l[0] === 2) {
      process.stdout.write(`${l[1]}\n`);
    } else if (l[0] > 2) {
      process.stdout.write(`${l[1] * 2}\n`);
    }
  }
});

var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
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;}}
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		if(N == 1){
			output[i] = 0;
			continue;
		}
		var M = one[1];
		if(N == 2){
			output[i] = M;
		}else{
			output[i] = M * 2;
		}
	}
	myout(myconv(output,9));
}

// 5
// 1 100
// 2 2
// 5 5
// 2 1000000000
// 1000000000 1000000000

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function writeLine(str) {
    process.stdout.write(`${str}\n`);
}

function main() {
    let t = Number(readLine());
    while(t--) {
        const [n, m] = readLine().split(' ').map(num => Number(num));
        if (n == 1) {
            writeLine(0);
        } else if (n == 2) {
            writeLine(m);
        } else {
            writeLine(m*2);
        }
    }
}

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

    main();
});

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

function main() {
    const n = parseInt(readline());
    const pairs = [];
    for (let i = 0; i < n; i++) {
        pairs.push(readline().split(' ').map(o => parseInt(o)));
    }

    pairs.forEach(([n, m]) => {
        if (n === 1) {
            console.log(0);
        } else if (n === 2) {
            console.log(m);
        } else {
            console.log(m * 2);
        }
    })
}

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 [n, m] = d.split(" ").map(Number);

  console.log(Math.min(2, n - 1) * m);

  // if (n === 1) {
  //   console.log(0);
  //   return;
  // }

  // if (n === 2) {
  //   console.log(m);
  //   return;
  // }

  // console.log(m * 2);
  c++;
});

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 [n, m] = d.split(" ").map(Number);

  if (n === 1) {
    console.log(0);
    return;
  }

  if (n === 2) {
    console.log(m);
    return;
  }

  console.log(m * 2);
  c++;
});

// node template.js < A-small.in > A-small.out

function main() {
    var tests = 1;
    tests = nextInt();

    for (let t = 1; t <= tests; t++) {
        let N = nextInt(), M = nextInt();

        let result = 0;
        if (N>1) result = M;
        if (N>2) result = M*2;

        print(result);
    }
}

// ------- Template ------------------
function newTensor(dimensions, value) {
    let res = [];
    let dim = dimensions[0], subdim = dimensions.slice(1);
    if (subdim.length == 0) {
        for(let i = 0; i < dim; i++) {
            res.push(value);
        }
    } else {
        for(let i = 0; i < dim; i++) {
            res.push(newTensor(subdim, value));
        }
    }
    return res;
}

if (!String.prototype.startsWith) {
    Object.defineProperty(String.prototype, 'startsWith', {
        value: function(search, rawPos) {
            var pos = rawPos > 0 ? rawPos|0 : 0;
            return this.substring(pos, pos + search.length) === search;
        }
    });
}
if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(search, this_len) {
        if (this_len === undefined || this_len > this.length) {
            this_len = this.length;
        }
        return this.substring(this_len - search.length, this_len) === search;
    };
}

var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(/[\s]+/);
        curToken = 0;
    }
    return curTokens[curToken++];
}

function nextInt() {
    return parseInt(next());
}

// code for nodejs
var inputBuffer = '', curLine = 0;

function readline() {
    return inputBuffer[curLine++];
}

function print(data) {
    process.stdout.write(data + '\n');
}

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

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

process.stdin.on('end', function () {
    inputBuffer = inputBuffer.split(/[\s]+/);
    main();
});

// Sample code to perform I/O:

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

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

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

/**
 *
 * @param {*} str
 * @param {*} seperator
 */
function splitter(str, seperator = '') {
    return str.trim().split(seperator);
}

/**
 *
 * @param {*} arr
 */
function strToNumArr(arr = []) {
    return arr.map(num => Number(num));
}

/**
 *
 * @param {*} num1
 * @param {*} num2
 */
function matrixArray(num1, num2) {
    return Array(num1).fill(Array(num2));
}

let log = function () {
    return Function.prototype.bind.call(console.log, console, '');
}();

function removeEmptyItem(arr, index) {
    return arr.slice(0, index).concat(arr.slice(index + 1, arr.length));
}

function range(min, max) {

    let arr = [];
    for (let index = min; index < max; index++) {
        arr.push(index);

    }
    return arr;
}

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

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

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

    let inputs = str.split('\n');
    let t = +inputs[0].trim();
    for (let index = 1; index <= t; index++) {
        const element = inputs[index].trim().split(' ');
        let n = +element[0];
        let sum = +element[1];
        if (n > 2) {
            console.log(2 * sum);
        }
        else {
            console.log((n - 1) * sum);
        }
    }

}

'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
6

**/

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

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

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

    for(let r=0;r<range;r++) {
        let [m,n] = readline().split(" ").map(Number);

        console.log(Math.min(2, (m-1)) * n);
    }
}

var x=parseInt(readline());

while(x--){
  var arr=readline().split(' ').map(x => parseInt(x));
  if(arr[0]<=1)
    print("0");
  else if(arr[0]===2)
    print(arr[1]);
  else
    print(2*arr[1]);

}

var testCaseCount = parseInt(readline());

var currentTestCase = 1;

while(currentTestCase <= testCaseCount) {
    var input = readline().split(" ");
    var n = parseInt(input[0]);
    var m = parseInt(input[1]);

    var result = findResult(n, m);

    print(result);

    currentTestCase += 1;
}

function findResult(n, m) {
    if (n < 2) {
        return 0;
    }

    if (n == 2) {
        return m;
    }

    return 2*m;
}

var t = parseInt(readline());

for (var tc = 0; tc < t; tc++) {
  var nm = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nm[0],
    m = nm[1];
  if (n == 2) print(m);
  else if (n == 1) print(0);
  else print(m * 2);
}

var testCases = readline();
for(var i =0; i< testCases; i++) {
    var line =  readline().split(" ");
    var arrayLength = line[0], arraySum = line[1];
    print( arrayLength >= 3? arraySum*2: (arrayLength == 1? 0 : arraySum));
}

var testCases = readline();

for(var i =0; i< testCases; i++) {
    var line =  readline().split(" ");
    var arrayLength = line[0], arraySum = line[1];
    if(arrayLength >= 3) {
        print(arraySum*2)
    } else {
        if(arrayLength == 1) {
            print(0);
        }
        else {
            print(arraySum);
        }
    }
}

for(var t=Number(readline());t;t--){
 var a = readline().trim().split(/\s/).map(x=>Number(x));
 print((a[0]==1)?0:(a[0]==2)?a[1]:2*a[1]);
}

function solve(n,m) {
    if (n <= 2) return m;
    return 2*m;
}
var tc = Number(readline())
while (tc--) {
  var inputArr = readline().split(" ").map(function(a) { return +a })
  var n = inputArr[0]
  var m = inputArr[1]
  print(solve(n,m))
}

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("inputString", inputString)

    //console.log("typeof inputString", typeof inputString)
    const tests = inputString.slice(1).map(item => item.split(" ").map(Number));

    //console.log("tests", tests);

    let result = [];

    for (let i = 0; i < tests.length; i++) {
        //console.log("tests[i]", tests[i]);
        const [n, m] = tests[i];

        if (n === 1) {
            result.push(0);
        } else if (n === 2) {
            result.push(m);
        } else {
            result.push(m * 2);
        }
    }

    result.forEach(item => console.log(item));
}

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", chunk => input_stdin += chunk.trim());

process.stdin.on("end", () => {
    input_stdin_array = input_stdin.trim().split("\n").map(str => str.trim());
    main()
})

readLine = () => {
    return input_stdin_array[input_currentline++];
}

main = () => {
    let t = parseInt(readLine());
    while( t-- ){
    	let [n, m] = readLine().split(" ").map(x => parseInt(x));
    	if( n === 1 )
    		console.log(0);
    	else if( n ===  2 )
    		console.log(m);
    	else
    		console.log(2*m);
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", chunk => input_stdin += chunk.trim());

process.stdin.on("end", () => {
    input_stdin_array = input_stdin.trim().split("\n").map(str => str.trim());
    main()
})

readLine = () => {
    return input_stdin_array[input_currentline++];
}

main = () => {
    let t = parseInt(readLine());
    while( t > 0 ){
    	let [n, m] = readLine().split(" ").map(Number);
    	if( n === 1 )
    		console.log(0);
    	else if( n ===  2 )
    		console.log(m);
    	else
    		console.log(2*m);
    	t = t-1;
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", chunk => input_stdin += chunk.trim());

process.stdin.on("end", () => {
    input_stdin_array = input_stdin.trim().split("\n").map(str => str.trim());
    main()
})

readLine = () => {
    return input_stdin_array[input_currentline++];
}

main = () => {
    let t = parseInt(readLine());
    while( t > 0 ){
    	let [n, m] = readLine().split(" ").map(x => parseInt(x));
    	if( n === 1 )
    		console.log(0);
    	else if( n ===  2 )
    		console.log(m);
    	else
    		console.log(2*m);
    	t = t-1;
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on("data", chunk => input_stdin += chunk.trim());

process.stdin.on("end", () => {
    input_stdin_array = input_stdin.trim().split("\n").map(str => str.trim());
    main()
})

readLine = () => {
    return input_stdin_array[input_currentline++].trim();
}

main = () => {
    let t = parseInt(readLine());
    while( t > 0 ){
    	let [n, m] = readLine().split(" ").map(x => parseInt(x));
    	if( n === 1 )
    		console.log(0);
    	else if( n ===  2 )
    		console.log(m);
    	else
    		console.log(2*m);
    	t = t-1;
    }
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readLine() {
    return inputString[currentLine++];
}
/*****************************************************************/
function main() {
    let 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);
        }
    }
}

'use strict';

const parseProblem = (line, problem) => {
    if (!problem.T || problem.T === 0) {
        problem.T = parseInt(line);
        return problem;
    }

    const cases = problem.cases;

    //if (cases.length === 0 || cases[cases.length - 1].arr) {
        cases.push({
            s: line
        });
    /*} else {
        cases[cases.length - 1].arr = line;
    }*/

    const isProcessing = cases.length < problem.T;// || !cases[cases.length - 1].arr;
    problem.isProcessing = isProcessing;

    return problem;
};

const solve = data => {
    const [n, m] = data.s.split(' ').map(i => +i);
    let sum = (n == 1) ? 0 : m;

    if(m == n && n > 2) {
        sum = 2 * m;
    }

    return sum;
}

const solveCases = cases => {
    for (let index = 0; index < cases.length; index++) {
        const result = solve(cases[index]);
        console.log(result);
    }
};

const main = () => {
    const readline = require('readline');

    let problem = {
        T: 0,
        cases: [],
        isProcessing: true
    };

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

    rl.on('line', line => {
        problem = parseProblem(line, problem);

        if (!problem.isProcessing) {
            rl.close();
        }
    }).on('close', () => {
        solveCases(problem.cases);
        process.exit(0);
    });
};

if (!module.parent) {
    main();
}

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin
});
rl.on('line', (line) => {
  const l = line.split(' ').map(v => +v);
  if (l.length > 1) {
    if (l[0] === 1) {
      process.stdout.write(`0\n`);
    } else if (l[0] === 2) {
      process.stdout.write(`${l[1]}\n`);
    } else if (l[0] > 2) {
      process.stdout.write(`${l[1] + l[0]}\n`);
    }
  }
});

'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++];
}
/**
    5
1 100
2 2
5 5
2 1000000000
1000000000 1000000000

**/

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

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

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

    for(let r=0;r<range;r++) {
        let [x, y] = readline().split(" ").map(Number);

        if(x === 1) {
            console.log(0);
            continue;
        }

        if(x === 2) {
            console.log(y);
            continue;
        }

        //if(x === y) {
        console.log(x + y);
        //}
    }
}

'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++];
}
/**
    5
1 100
2 2
5 5
2 1000000000
1000000000 1000000000

**/

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

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

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

    for(let r=0;r<range;r++) {
        let [x, y] = readline().split(" ").map(Number);

        if(x === 1) {
            console.log(0);
            continue;
        }

        if(x === 2) {
            console.log(y);
            continue;
        }

        if(x === y) {
            console.log(y + y);
            continue;
        } else {
            console.log(y+y+1);
            continue;
        }
    }
}

'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
6

**/

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

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

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

    for(let r=0;r<range;r++) {
        let [m,n] = readline().split(" ").map(Number);

        console.log(Math.min(2, n*(m-1)));
    }
}