var readNumber = () => +readline();
var readStr = () => readline();
var n = readNumber();

for (var i = 0; i < n; i++) {
    readNumber();
    var array = readStr().split('');
    paint(array);
}

function paint(input) {
    var firstPaintedIndex = -1;
    adjacentColor = "R";
    for (var index = 0; index < input.length; index++) {
        if (input[index] != '?') {
            firstPaintedIndex = index;
            adjacentColor = input[index];
            break;
        }
    }

    if (firstPaintedIndex != -1) {
        //paint left
        for (var index = firstPaintedIndex - 1; index >= 0; index--) {
            input[index] = adjacentColor == 'B' ? 'R' : 'B';
            adjacentColor = input[index];
        }

        adjacentColor = input[firstPaintedIndex]
    }
    //paint right
    for (var index = firstPaintedIndex + 1; index < input.length; index++) {
        var current = input[index];
        if (current == '?') {
            input[index] = adjacentColor == 'B' ? 'R' : 'B';
        }
        adjacentColor = input[index];
    }

    print(input.join(''));
}

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

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

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

const rev = c => c == 'B' ? 'R' : 'B';

function main () {
	let t = rl();
	while (t--) {
		let n = rl();
		let s = rl().split('');

		if (s[0] == '?') {
			let i = 0;
			while (i < n && s[i] == '?') i++;
			if (i == n) s[0] = 'B';
			else if (i % 2 == 1) s[0] = rev(s[i]);
			else s[0] = s[i];
		}

		for (let i = 1; i < n; i++) {
			if (s[i] == '?') {
				s[i] = rev(s[i - 1]);
			}
		}

		console.log(s.join(''));
	}
}

const input = [];

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

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

rl.on('close', doWork);

let line = 0;

function lineToStrArray(split = ' ') {
  const val = input[line].split(split);
  line += 1;
  return val;
}

function lineToNumArray(split = ' ') {
  const val = input[line].split(split).map(e => +e);
  line += 1;
  return val;
}

function doWork() {
  const [t] = lineToNumArray();

  for (let t1 = 0; t1 < t; t1 += 1) {
    const [n] = lineToNumArray();
    const [str] = lineToStrArray();

    const splitStr = str.split('');

    if (splitStr.every(e => e === '?')) {
      splitStr[0] = 'R';
    }

    while (splitStr.includes('?')) {
      let next = null;
      for (let i = 0; i < splitStr.length; i += 1) {
        if (splitStr[i] !== '?') {
          next = splitStr[i] === 'B' ? 'R' : 'B';
        } else if (next !== null) {
          splitStr[i] = next;
          next = splitStr[i] === 'B' ? 'R' : 'B';
        }
      }
      next = null;
      for (let i = splitStr.length - 1; i >= 0; i -= 1) {
        if (splitStr[i] !== '?') {
          next = splitStr[i] === 'B' ? 'R' : 'B';
        } else if (next !== null) {
          splitStr[i] = next;
          next = splitStr[i] === 'B' ? 'R' : 'B';
        }
      }
    }
    console.log(splitStr.join(''));
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
	let numberOfLines = parseInt(readline(), 10) * 2
	for(let i = 0; i < numberOfLines; i++) {
		let x = readline().trim()
		if(i % 2 === 1) {
			console.log(solve(x))
		}
		// print(solve(x))
		// fs.appendFileSync("output.txt", `Case #${i+1}: ${solve(x)}` + "\n")
	}

}

function solve(str) {
    let arr = str.split("");
	let numOfUnknown = 0
	let queue = []
	for(let i = 0; i < arr.length; i++) {
		if(arr[i] !== "?") queue.push(i)
		else numOfUnknown++
	}
	if(numOfUnknown > 0 && !queue.length) {
		arr[0] = "B"
		queue.push(0)
	}
	while(queue.length && numOfUnknown) {
		let current = queue.pop()
		if(current > 0 && arr[current - 1] === "?") {
			if(arr[current] === "B") arr[current-1] = "R"
			else arr[current-1] = "B"
			queue.push(current - 1)
			numOfUnknown--
		}
		if(current < arr.length - 1 && arr[current + 1] === "?") {
			if(arr[current] === "B") arr[current + 1] = "R"
			else arr[current + 1] = "B"
			queue.push(current + 1)
			numOfUnknown--
		}
	}

	return arr.join("")
}

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

	main()
})

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

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

function main() {
	let t = readint()
	loop(t)(_ => {
		let n = readint()
		let s = readline()
		let indB = s.indexOf('B')
		let indR = s.indexOf('R')
		let ans = ''
		if (indB === -1 && indR === -1) {
			loop(n)(i => ans += 'BR'[i%2])
		} else {
			let ind = Math.max(indB, indR);
			s = s.split('')
			loop(ind + 1, n)(i => {
				if (s[i] === '?') s[i] = s[i-1] === 'R' ? 'B' : 'R'
			})
			loop(ind - 1, -1)(i => {
				if (s[i] === '?') s[i] = s[i+1] === 'R' ? 'B' : 'R'
			})
			ans = s.join('')
		}
		print(ans)
	})
}

var t = parseInt(readline())
while(t--){
    var n=parseInt(readline())
    var v=readline().split('')

    for(var i=n-2;~i;i--)
        if(v[i]==='?')
            v[i]= (v[i+1]==='R')?'B':'R'

    for(var i=1;i<n;i++)
        if(v[i]==='?')
            v[i]= (v[i-1]==='B')?'R':'B'

    var res=v.join('')
    if(res ==='?')res='B'
    print(res)
}

var readNumber = () => +readline();
var readStr = () => readline();
var n = readNumber();

for(var i = 0; i < n; i++) {
    readNumber();
    var array = readStr().split('');
    paint(array);
}

function paint(input){
    var firstPaintedIndex=1;
    adjacentColor="R";
    for(var index=0;index<input.length;index++){
        if(input[index]!='?'){
            firstPaintedIndex=index;
            adjacentColor=input[index];
            break;
        }
    }

    //paint left
    for(var index=firstPaintedIndex-1;index>=0;index--){
        input[index]=adjacentColor=='B'?'R':'B';
        adjacentColor=input[index];
    }

    adjacentColor=input[firstPaintedIndex]
    //paint right
    for(var index=firstPaintedIndex+1;index<input.length;index++){
        var current=input[index];
        if(current=='?'){
            input[index]=adjacentColor=='B'?'R':'B';
        }
        adjacentColor=input[index];
    }

    print(input.join(''));
}

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

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

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

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


const readline = require('readline');

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

let tests = [];
rl.on('line', (line) => {
  tests.push(line.split(' '));
}).on('close', () => {
  for (i = 1; i < tests.length; i++) {

    const getMinDel = (ch) => {
      if (ch % 2 === 0) {
        return 2
      } else if (ch % 3 === 0) {
        return 3
      } else if (ch % 5 === 0) {
        return 5
      } else if (ch % 7 === 0) {
        return 7
      } else {
        for (x = 11; x <= ch; x++) {
          if (ch % x === 0) {
            return x;
          }
        }
      };
    }

    const k = +tests[i][1] - 1;
    let n = +tests[i][0] + getMinDel(+tests[i][0]);

    process.stdout.write(`${n + (2 * k)}\n`);
  }
});

'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({
            t: 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, k] = data.t.split(' ').map(i => +i);
    let num = n;
    let i = 1;

    num += f(num);
    num += (k - 1) * 2;

    return num;
}

const f = n => {
    for(let i = 2; i <= Math.pow(n, 2); i++) {
        if(n % i == 0) return i;
    }
    return n;
}

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

function divisors(n, k) {
  if (n % 2 != 0) {
    var divisor;
    for (var i = 2; i <= n; i++) {
      if (n % i == 0) {
        divisor = i;
        break;
      }
    }
    n += divisor;
    k--;

    n += 2 * k;
  } else {
    n += 2 * k;
  }
  return n;
}
var t = parseInt(readline());

for (var tc = 0; tc < t; tc++) {
  var nk = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nk[0],
    k = nk[1];
  var res = divisors(n, k);
  print(res);
}

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

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

  let [n, k] = d.split(' ').map(Number);

  for (let i = 2; i <= n; i++) {
    if (n % i === 0) {
      n += i;
      break;
    }
  }
  k--;

  n += k * 2;

  ans += `${n}\n`;

  c++;
});

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

var t = Number(readline());
var inp;
for(var i = 0; i < t ; i++){
    inp = readline().split(' ').map(cur => Number(cur));
        for (var j = 2; j <= inp[0] ; j++){
            if(inp[0]%j === 0) break;
        }
        print(inp[0] + j + 2*(inp[1] - 1));
    }

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
  3
5 1
8 2
3 4

**/

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

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

        let count = 0;

        for(let i=2;i<=n;i++) {
            if( n % i === 0) {
                n+=i;
                break;
            }
        }

        console.log( n + (2 * (k - 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 c = parseInt(readLine());
    for (var j = 0; j < c; j++) {
        let arr = readLine()
            .split(' ')
            .map(value => parseInt(value))
        var n = arr[0];
        var k = arr[1];
        // console.log("n vs k: ", n, k);
        if (n % 2 == 0) {
            console.log(n + 2 * k);
        } else {
            let f = 0;
            for (var i = 2; i * i <= n; i++) {
                if (n % i == 0) {
                    n += i;
                    f = 1;
                    break;
                }
            }
            // console.log("f: ", f);
            if (f == 0) {
                n += n;
            };
            console.log(n + (k - 1) * 2);
        }
    }
}

const readline = require('readline');

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

let tests = [];
rl.on('line', (line) => {
  tests.push(line.split(' '));
}).on('close', () => {
  for (i = 1; i < tests.length; i++) {

    const getMinDel = (ch) => {
      for (j = 2; j <= 9; j++) {
        if (ch % j === 0) {
          return j;
        }
      }
    }

    const k = +tests[i][1];
    let newN = +tests[i][0] + getMinDel(+tests[i][0]);

    process.stdout.write(`${newN + 2 * (k - 1)}\n`);
  }
});

const readline = require('readline');

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

let tests = [];
rl.on('line', (line) => {
  tests.push(line.split(' '));
}).on('close', () => {
  for (i = 1; i < tests.length; i++) {

    const getMinDel = (ch) => {
      for (j = 2; j <= 9; j++) {
        if (ch % j === 0) return j;
      }
    }

    const k = +tests[i][1] - 1;
    let n = +tests[i][0] + getMinDel(+tests[i][0]);

    process.stdout.write(`${n + (2 * k)}\n`);
  }
});

const readline = require('readline');

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

let tests = [];
rl.on('line', (line) => {
  tests.push(line.split(' '));
}).on('close', () => {
  for (i = 1; i < tests.length; i++) {

    const getMinDel = (ch) => {
      if (ch % 2 === 0) {
        return 2
      } else if (ch % 3 === 0) {
        return 3
      } else if (ch % 5 === 0) {
        return 5
      } else if (ch % 7 === 0) {
        return 7
      } else {
        return ch;
      }
    }

    const k = +tests[i][1] - 1;
    let n = +tests[i][0] + getMinDel(+tests[i][0]);

    process.stdout.write(`${n + (2 * k)}\n`);
  }
});

const readline = require('readline');

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

let tests = [];
rl.on('line', (line) => {
  tests.push(line.split(' '));
}).on('close', () => {
  for (i = 1; i < tests.length; i++) {

    const getMinDel = (ch) => {
      if (ch % 2 === 0) return 2;
      if (ch < 10) return ch;
      if (ch % 3 === 0) return 3;
      if (ch % 5 === 0) return 5;
    }

    const k = +tests[i][1];
    let newN = +tests[i][0] + getMinDel(tests[i][0]);

    process.stdout.write(`${newN + 2 * k - 1}\n`);
  }
});

const readline = require('readline');

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

let tests = [];
rl.on('line', (line) => {
  tests.push(line.split(' '));
}).on('close', () => {
  for (i = 1; i < tests.length; i++) {

    const getMinDel = (ch) => {
      if (ch % 2 === 0) return 2;
      if (ch < 10) return ch;
      if (ch % 3 === 0) return 3;
      if (ch % 5 === 0) return 5;
    }

    const k = +tests[i][1];
    let newN = +tests[i][0] + getMinDel(+tests[i][0]);

    process.stdout.write(`${newN + 2 * (k - 1)}\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++];
}
/**
  3
5 1
8 2
3 4

**/

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

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

        if(x % y === 0) {
            console.log(x + (x / y));
        } else {
            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++];
}
/**
  3
5 1
8 2
3 4

**/

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

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

        if(x % y === 0) {
            console.log(x + (x / y));
        } else {
            console.log(x *  y + (Math.floor(x/y)));
        }
    }

}

var t = Number(readline());
var inp;
for(var i = 0; i < t ; i++){
    inp = readline().split(' ').map(cur => Number(cur));
    if (inp[0]%2 === 0){
        print(inp[0] + 2*inp[1])
    }else{
        var d = inp[0];
        for (var j = 3; j <= Math.sqrt(inp[0]); j += 2){
            (inp[0]%j === 0) ? d = j : null;
        }
        print(inp[0] + d + 2*(inp[1] - 1));
    }
}


print(function() {
    var data = rn();
    var n = data[0];
    var s = data[1];
    var cities=[];
    for(var i=0; i<n; ++i) {
        data = rn();
        var x = data[0];
        var y = data[1];
        var k = data[2];
        cities.push({key1 : x*x+y*y, key2 : k});
    }
    cities.sort(function(a, b) {
        return a.key1-b.key1;
    });
    var sum=s;
    for(var i=0; i<n; ++i) {
        sum+=cities[i].key2;
        if(sum>=1000000) {
            return Math.sqrt(cities[i].key1);
        }
    }
    return -1;
}());
function rn() {
    return readline().split(' ').map(Number);
}

function main() {

    var first = readline().split(' ').map(Number);
    var n=first[0],s=first[1];
    var arr=[];
    for(var m=0;m<n;m++){
        var second = readline().split(' ').map(Number);
        arr.push(second);
    }

    var newarr=[];
    for(var j=0;j<n;j++){
        var temp=[];
        temp.push(Math.sqrt(Math.pow(arr[j][0],2)+Math.pow(arr[j][1],2)));
        temp.push(arr[j][2]);

        newarr.push(temp);
    }

    newarr.sort(sortFunction);

    function sortFunction(a, b) {
        if (a[0] === b[0]) {
            return 0;
        }
        else {
            return (a[0] < b[0]) ? -1 : 1;
        }
    }

    var sum=0;
    for(var i=0;i<n;i++){
        sum+=newarr[i][1];
    }

    if((sum+s)<1000000){
        print(-1);
    }else {
        for( j=0;j<n;j++){
            s+=newarr[j][1];
            if(s>=1000000){
                print(newarr[j][0]);
                break;
            }
        }
    }
}

main();

var firstLine = readline().split(" ").map(Number);
var n = firstLine[0];
var s = firstLine[1];

function city(x, y, p){
	this.x = x
	this.y = y
	this.p = p
	this.distance = function(){return Math.sqrt(this.x*this.x + this.y*this.y)}
}

// city.prototype.distance = function(){
// 	return Math.sqrt(this.x*this.x + this.y*this.y)
// }

var cities = []

for(i = 0; i < n; i++){
	data = readline().split(" ").map(Number);
	cities.push(new city(data[0], data[1], data[2]))
}

cities.sort(function(a,b){return a.distance() - b.distance()})

var notMega = true
var myDistance = 0

while(notMega && cities.length !== 0 ){
	nextCity = cities.shift()
	s += nextCity.p
	if(s >= 1000000){
		notMega = false
		myDistance = nextCity.distance()
	}
}

if(notMega){
	print(-1)
}
else{
	print(myDistance)
}

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());
	var numCities = data[0], totalPopulation = data[1];
	var cities = [];
	for (var i = 0; i < numCities; ++i) {
		data = tokenizeIntegers(readline());
		var x = data[0], y = data[1], population = data[2];
		cities.push({ distanceSquared: x*x + y*y, population: population });
	}
	cities.sort(function (a, b) {
		return a.distanceSquared - b.distanceSquared;
	});
	for (var i = 0; i < cities.length; ++i) {
		totalPopulation += cities[i].population;
		if (totalPopulation >= 1000000) {
			print(Math.sqrt(cities[i].distanceSquared));
			return;
		}
	}
	print(-1);
}

main();

print(function() {
    var data = rn();
    var n = data[0];
    var s = data[1];
    var cities=[];
    for(var i=0; i<n; ++i) {
        data = rn();
        var x = data[0];
        var y = data[1];
        var k = data[2];
        cities.push({key1 : x*x+y*y, key2 : k});
    }
    cities.sort(function(a, b){
        return a.key1-b.key1
    });
    var sum=s;
    for(var i=0; i<cities.length; ++i) {
        sum+=cities[i].key2;
        if(sum>=1000000) {
            return Math.sqrt(cities[i].key1);

        }
    }
    return -1;
}());
function rn() {
    return readline().split(' ').map(Number);
}

print(function() {
    var data = rn();
    var n = data[0];
    var s = data[1];
    var cities=[];
    for(var i=0; i<n; ++i) {
        data = rn();
        var x = data[0];
        var y = data[1];
        var k = data[2];
        cities.push([ x*x+y*y,  k]);
    }
    cities.sort(function(a, b){
        return a[0]-b[0];
    });
    var sum=s;
    for(var i=0; i<cities.length; ++i) {
        sum+=cities[i][1];
        if(sum>=1000000) {
            return Math.sqrt(cities[i][0]);

        }
    }
    return -1;
}());
function rn() {
    return readline().split(' ').map(Number);
}

print(function() {
    var data = rn();
    var n = data[0];
    var s = data[1];
    var cities=[];
    for(var i=0; i<n; ++i) {
        data = rn();
        var x = data[0];
        var y = data[1];
        var k = data[2];
        cities.push([x*x+y*y, k]);
    }
    cities.sort(function(a, b) {
        return a[0]-b[0];
    });
    var sum=s;
    for(var i=0; i<n; ++i) {
        sum+=cities[i][1];
        if(sum>=1000000) {
            return Math.sqrt(cities[i][0]);
        }
    }
    return -1;
}());
function rn() {
    return readline().split(' ').map(Number);
}

print(function() {
    var data = rn();
    var n = data[0];
    var s = data[1];
    var cities=[];
    for(var i=0; i<n; ++i) {
        data = rn();
        var x = data[0];
        var y = data[1];
        var k = data[2];
        cities.push([ (x*x+y*y,  k)]);
    }
    cities.sort(function(a, b){
        return a[0]-b[0];
    });
    var sum=s;
    for(var i=0; i<cities.length; ++i) {
        sum+=cities[i][1];
        if(sum>=1000000) {
            return Math.sqrt(cities[i][0]);

        }
    }
    return -1;
}());
function rn() {
    return readline().split(' ').map(Number);
}

print(function() {
    var data = rn();
    var n = data[0];
    var s = data[1];
    var cities=[];
    for(var i=0; i<n; ++i) {
        data = rn();
        var x = data[0];
        var y = data[1];
        var k = data[2];
        cities.push({key1 : x*x+y*y, key2 : k});
    }
    cities.sort(function(a, b){
        return a.key1-b.key1
    });
    var sum=s;
    for(var i=0; i<cities.length; ++i) {
        sum+=cities[i].key2;
        if(sum>=1000000) {
            print(Math.sqrt(cities[i].key1));
            return;
        }
    }
    print(-1);
}());
function rn() {
    return readline().split(' ').map(Number);
}

print(function() {
    var n = +readline();
    var s = +readline();
    var cities=[];
    for(var i=0; i<n; ++i) {
        var data = rn();
        var x = data[0];
        var y = data[1];
        var k = data[2];
        cities.push({key1 : x*x+y*y, key2 : k});
    }
    cities.sort(function(a, b){
        return a.key1-b.key1
    });
    var sum=s;
    for(var i=0; i<cities.length; ++i) {
        sum+=cities[i].key2;
        if(sum>=1000000) {
            print(Math.sqrt(cities[i].key1));
            return;
        }
    }
    print(-1);
}());
function rn() {
    return readline().split(' ').map(Number);
}

print(function() {
    var n = +readline();
    var s = +readline();
    var cities=[];
    for(var i=0; i<n; ++i) {
        var x = +readline();
        var y = +readline();
        var k = +readline();
        cities.push({key1 : x*x+y*y, key2 : k});
    }
    cities.sort(function(a, b){
        return a.key1-b.key1
    });
    var sum=s;
    for(var i=0; i<cities.length; ++i) {
        sum+=cities[i].key2;
        if(sum>=1000000) {
            print(Math.sqrt(cities[i].key1));
            return;
        }
    }
    print(-1);
}());
function rn() {
    return readline().split(' ').map(Number);
}

function main() {

    var first = readline().split(' ').map(Number);
    var n=first[0],s=first[1];
    var arr=[];
    for(var m=0;m<n;m++){
        var second = readline().split(' ').map(Number);
        arr.push(second);
    }

    var newarr=[];
    for(var j=0;j<n;j++){
        var temp=[];
        temp.push(Math.sqrt(Math.pow(arr[j][0],2)+Math.pow(arr[j][1],2)));
        temp.push(arr[j][2]);

        newarr.push(temp);
    }

    newarr.sort(sortFunction);

    function sortFunction(a, b) {
        if (a[0] === b[0]) {
            return 0;
        }
        else {
            return (a[0] < b[0]) ? -1 : 1;
        }
    }

    var sum=0;
    for(var i=0;i<n;i++){
        sum+=newarr[i][1];
    }

    if((sum+s)<1000000){
        print(-1);
    }else {
        for( j=0;j<n;j++){
            s+=newarr[j][1];
            if(s>1000000){
                print(newarr[j][0]);
                break;
            }
        }
    }
}

main();

var firstLine = readline().split(" ").map(Number);
var n = firstLine[0];
var s = firstLine[1];

function city(x, y, p){
	this.x = x
	this.y = y
	this.p = p
	this.distance = function(){return Math.sqrt(this.x*this.x + this.y*this.y)}
}

// city.prototype.distance = function(){
// 	return Math.sqrt(this.x*this.x + this.y*this.y)
// }

var cities = []

for(i = 0; i < n; i++){
	data = readline().split(" ").map(Number);
	cities.push(new city(data[0], data[1], data[2]))
}

cities.sort(function(a,b){return a.distance - b.distance})

var notMega = true
var myDistance = 0

while(notMega && cities.length !== 0 ){
	nextCity = cities.shift()
	s += nextCity.p
	if(s >= 1000000){
		notMega = false
		myDistance = nextCity.distance()
	}
}

if(notMega){
	print(-1)
}
else{
	print(myDistance)
}


function countingSort(arr, n){

    var min = arr[0];
    var max = arr[0];

    for(var i = 0; i < n; i++) {
        if(arr[i] < min ) {
            min = arr[i]
        } else if(arr[i] > max)
            max = arr[i]
    }

    var i = min;
    var j = 0;
    var len = arr.length;
    var count = [];

    for (var i = 0; i <= max; i++) {
        count[i] = 0;
    }
    for (var i = 0; i < len; i++) {
        count[arr[i]] += 1;
    }
    for (var i = min; i <= max; i++) {
        while (count[i] > 0) {
            arr[j] = i;
            j++;
            count[i]--;
        }
    }
    return arr;
}

var input = readline().split(' ');
var n = +input[0];
var m = +input[1];
// print(n)

var A = new Array(m + 1);
var copy = new Array(n).fill(0);
for (var i=0; i < A.length; i++){
    A[i] = copy.slice(0);
}

for (var i = 0; i < n; i++) {
    var row = readline().split('');
    for (var j = m - 1 ; j > -1; j--) {
        if(row[j] == '0') A[j][i] = 0;
        else {
            A[j][i] = Math.max(A[j + 1][i] + 1,A[j][i])
        }
    }
}

var maxArea = 0;
for (var i = 0; i < m; i++) {
    A[i] = countingSort(A[i],n);
    for (var j = 0; j < n; j++)
        if (A[i][j] * (n - j) > maxArea) maxArea = A[i][j] * (n - j)
}
print(maxArea);

// Generated by CoffeeScript 1.4.0
(function() {
  var a, i, j, l, m, n, readints, res, x, z, z0, z1, zn, _i, _j, _k, _l, _len, _ref, _ref1, _results;

  readints = function() {
    var x, _i, _len, _ref, _results;
    _ref = readline().split(' ');
    _results = [];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      x = _ref[_i];
      _results.push(x | 0);
    }
    return _results;
  };

  _ref = readints(), n = _ref[0], m = _ref[1];

  a = (function() {
    var _i, _results;
    _results = [];
    for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {
      _results.push(readline());
    }
    return _results;
  })();

  l = (function() {
    var _i, _results;
    _results = [];
    for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {
      _results.push(0);
    }
    return _results;
  })();

  z = (function() {
    _results = [];
    for (var _i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--){ _results.push(_i); }
    return _results;
  }).apply(this);

  z1 = Array(n);

  res = 0;

  for (i = _j = _ref1 = m - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {
    zn = z0 = 0;
    for (_k = 0, _len = z.length; _k < _len; _k++) {
      x = z[_k];
      if (a[x][i] === '0') {
        l[x] = 0;
        z[z0++] = x;
      } else {
        l[x]++;
        z1[zn++] = x;
      }
    }
    for (j = _l = 0; 0 <= zn ? _l < zn : _l > zn; j = 0 <= zn ? ++_l : --_l) {
      res = Math.max(res, l[z1[j]] * (zn - j));
      z[z0++] = z1[j];
    }
  }

  print(res);

}).call(this);

// Generated by CoffeeScript 1.4.0
(function() {
  var a, i, j, l, m, n, readints, res, x, z, z0, z1, zn, _i, _j, _k, _l, _len, _ref, _ref1, _results;

  readints = function() {
    var x, _i, _len, _ref, _results;
    _ref = readline().split(' ');
    _results = [];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      x = _ref[_i];
      _results.push(x | 0);
    }
    return _results;
  };

  _ref = readints(), n = _ref[0], m = _ref[1];

  a = (function() {
    var _i, _results;
    _results = [];
    for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {
      _results.push(readline().split(''));
    }
    return _results;
  })();

  l = (function() {
    var _i, _results;
    _results = [];
    for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {
      _results.push(0);
    }
    return _results;
  })();

  z = (function() {
    _results = [];
    for (var _i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--){ _results.push(_i); }
    return _results;
  }).apply(this);

  z1 = Array(n);

  res = 0;

  for (i = _j = _ref1 = m - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {
    zn = z0 = 0;
    for (_k = 0, _len = z.length; _k < _len; _k++) {
      x = z[_k];
      if (a[x][i] === '0') {
        l[x] = 0;
        z[z0++] = x;
      } else {
        l[x]++;
        z1[zn++] = x;
      }
    }
    for (j = _l = 0; 0 <= zn ? _l < zn : _l > zn; j = 0 <= zn ? ++_l : --_l) {
      res = Math.max(res, l[z1[j]] * (zn - j));
      z[z0++] = z1[j];
    }
  }

  print(res);

}).call(this);

// Generated by CoffeeScript 1.4.0
(function() {
  var a, i, j, l, m, n, readints, res, x, z, z0, z1, zn, _i, _j, _k, _l, _len, _ref, _ref1, _results;

  readints = function() {
    var x, _i, _len, _ref, _results;
    _ref = readline().split(' ');
    _results = [];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      x = _ref[_i];
      _results.push(x | 0);
    }
    return _results;
  };

  _ref = readints(), n = _ref[0], m = _ref[1];

  a = (function() {
    var _i, _results;
    _results = [];
    for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {
      _results.push(readline());
    }
    return _results;
  })();

  l = (function() {
    var _i, _results;
    _results = [];
    for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {
      _results.push(0);
    }
    return _results;
  })();

  z = (function() {
    _results = [];
    for (var _i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--){ _results.push(_i); }
    return _results;
  }).apply(this);

  z1 = Array(n);

  res = 0;

  for (i = _j = _ref1 = m - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {
    zn = z0 = 0;
    for (_k = 0, _len = z.length; _k < _len; _k++) {
      x = z[_k];
      if (a[x].charAt(i) === '0') {
        l[x] = 0;
        z[z0++] = x;
      } else {
        l[x]++;
        z1[zn++] = x;
      }
    }
    for (j = _l = 0; 0 <= zn ? _l < zn : _l > zn; j = 0 <= zn ? ++_l : --_l) {
      res = Math.max(res, l[z1[j]] * (zn - j));
      z[z0++] = z1[j];
    }
  }

  print(res);

}).call(this);

var line = readline().split(' ');
var n = parseInt(line[0]);
var m = parseInt(line[1]);
var i, j, acc;
var counts = new Array(m);
for (j = 0; j < m; j++) {
  counts[j] = new Int16Array(5001);
}

for (i = 0; i < n; i++) {
  line = readline();
  acc = line[m-1] === '0' ? 0 : 1;
  counts[m-1][acc]++;
  for (j = m-2; j >= 0; j--) {
    if (line[j] === '1') {
      counts[j][++acc]++;
    } else {
      acc = 0;
    }
  }
}

var maxArea = 0;

for (j = 0; j < m; j++) {
  acc = 0;
  for (i = 5000; i > 0; i--) {
    acc += counts[j][i];
    if (acc*i > maxArea) {
      maxArea = acc*i;
    }
  }
}

print(maxArea);

// Generated by CoffeeScript 1.4.0
(function() {
  var a, i, l, m, n, readints, res, x, z, z0, z1, zn, _i, _j, _k, _l, _len, _len1, _ref, _ref1, _results;

  readints = function() {
    var x, _i, _len, _ref, _results;
    _ref = readline().split(' ');
    _results = [];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      x = _ref[_i];
      _results.push(x | 0);
    }
    return _results;
  };

  _ref = readints(), n = _ref[0], m = _ref[1];

  a = (function() {
    var _i, _results;
    _results = [];
    for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {
      _results.push(readline().split(''));
    }
    return _results;
  })();

  l = (function() {
    var _i, _results;
    _results = [];
    for (_i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--) {
      _results.push(0);
    }
    return _results;
  })();

  z = (function() {
    _results = [];
    for (var _i = 0; 0 <= n ? _i < n : _i > n; 0 <= n ? _i++ : _i--){ _results.push(_i); }
    return _results;
  }).apply(this);

  res = 0;

  for (i = _j = _ref1 = m - 1; _ref1 <= 0 ? _j <= 0 : _j >= 0; i = _ref1 <= 0 ? ++_j : --_j) {
    z0 = [];
    z1 = [];
    for (_k = 0, _len = z.length; _k < _len; _k++) {
      x = z[_k];
      if (a[x][i] === '0') {
        z0.push(x);
        l[x] = 0;
      } else {
        z1.push(x);
        l[x]++;
      }
    }
    zn = z1.length;
    for (_l = 0, _len1 = z1.length; _l < _len1; _l++) {
      x = z1[_l];
      res = Math.max(res, l[x] * zn);
      zn--;
    }
    z = z0.concat(z1);
  }

  print(res);

}).call(this);

function countingSort(arr, n){

    var min = arr[0];
    var max = arr[0];

    for(var i = 0; i < n; i++) {
        if(arr[i] < min ) {
            min = arr[i]
        } else if(arr[i] > max)
            max = arr[i]
    }

    var i = min;
    var j = 0;
    var len = arr.length;
    var count = [];

    for (var i = 0; i <= max; i++) {
        count[i] = 0;
    }
    for (var i = 0; i < len; i++) {
        count[arr[i]] += 1;
    }
    for (var i = min; i <= max; i++) {
        while (count[i] > 0) {
            arr[j] = i;
            j++;
            count[i]--;
        }
    }
    return arr;
}

var input = readline().split(' ');
var n = +input[0];
var m = +input[1];
// print(n)

var A = new Array(m + 1);
var copy = new Array(n).fill(0);
for (var i=0; i < A.length; i++){
    A[i] = copy.slice(0);
}

for (var i = 0; i < n; i++) {
    var row = readline().split('');
    for (var j = m - 1 ; j > -1; j--) {
        if(row[j] == '0') A[j][i] = 0;
        else {
            A[j][i] = Math.max(A[j + 1][i] + 1,A[j][i])
        }

    }
}

var maxArea = 0;
for (var i = 0; i < m - 1; i++) {
    A[i] = countingSort(A[i],n)
    for (var j = 0; j < n; j++)
        if (A[i][j] * (n - j) > maxArea) maxArea = A[i][j] * (n - j)
}
print(maxArea);

function countingSort(arr, n){
    var min = arr[0];
    var max = arr [0];

    for(i; i < n; i++) {
        if(arr[i] < min ) {
            min = arr[i]
        } else if(arr[i] > max)
            max = arr[i]
    }

    var i = min;
    var j = 0;
    var len = arr.length;
    var count = [];

    for (i; i <= max; i++) {
        count[i] = 0;
    }
    for (i = 0; i < len; i++) {
        count[arr[i]] += 1;
    }
    for (i = min; i <= max; i++) {
        while (count[i] > 0) {
            arr[j] = i;
            j++;
            count[i]--;
        }
    }
    return arr;
};

var input = readline().split(' ');
var n = +input[0];
var m = +input[1];
// print(n)

var A = {};

//  var row = readline().split('');

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

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

    for (var j = 0; j < m; j++) {
        if (!A[j]) A[j] = [];
        if (row[j] == 0 || j == 0) { A[j][i] = Number(row[j]); continue; }
        A[j][i] = Math.max((A[j - 1][i] + 1), Number(row[j]));
    }
}

var maxArea = 0;
for (var i = 0; i < m; i++) {
    A[i] = countingSort(A[i],n)
    for (var j = 0; j < n; j++)
        if (A[i][j] * (n - j) > maxArea) maxArea = A[i][j] * (n - j)
}
print(maxArea);

var input = readline().split(' ');
var n = +input[0];
var m = +input[1];
// print(n)

var A = new Array(m + 1);
var copy = new Array(n).fill(0);
for (var i=0; i < A.length; i++){
    A[i] = copy.slice(0);
}

for (var i = 0; i < n; i++) {
    var row = readline().split('');
    for (var j = m - 1 ; j > -1; j--) {
        if(row[j] == '0') A[j][i] = 0;
        else {
            A[j][i] = Math.max(A[j + 1][i] + 1,A[j][i])
        }
    }
}

var maxArea = 0;
for (var i = 0; i < m; i++) {
    A[i].sort()
    for (var j = 0; j < n; j++)
        if (A[i][j] * (n - j) > maxArea) maxArea = A[i][j] * (n - j)
}
print(maxArea);

var line = readline().split(' ');
var n = parseInt(line[0]);
var m = parseInt(line[1]);
var rows = new Array(n);
var i, j;

for (i = 0; i < n; i++) {
  line = readline().split(' ');
  rows[i] = new Int8Array(m);
  rows[i][m-1] = parseInt(line[m-1]);
  for (j = m-2; j >= 0; j--) {
    if (line[j] === '1') {
      rows[i][j] = 1 + rows[i][j+1];
    }
  }
}

var maxArea = 0, area;
var cmp = function (a, b) {
  return a[j] - b[j];
};

for (j = 0; j < m; j++) {
  rows.sort(cmp);
  for (i = 0; i < n; i++) {
    area = (n-i)*rows[i][j];
    if (area > maxArea) {
      maxArea = area;
    }
  }
}

print(maxArea);


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], e= 0
    for(j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j]
        }else{
            var k = lines[j].split(' ').sort(function(a, b){return a-b}).map(Number)
            console.log(k[k.length- 1] - k[0])
        }
    }
});

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 * 2; j++){
        if(j % 2 === 0){
            var a = lines[j].split(' ').sort(function(a, b){return a-b}).map(Number)
            console.log(a[a.length - 1] - a[0])

        }
    }
});

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

let num = -1;
const rows = [];
rl.on('line', line => {
    if (num < 0) {
        num = parseInt(line.trim());
    } else {
        rows.push(line.trim());
        if (rows.length === num*2) {
            dealInput(rows);
        }
    }
});
const dealInput = (rows) => {
    let location = []
    rows.forEach(item => {
        location.push(item.split(' '))
    })
    location.forEach((item,index) => {
        if(index%2 !== 0) {
            let max = Math.max(...item)
            let min = Math.min(...item)
            console.log(max-min);
        }
    })
    rl.close();
};

rl.on('close', () => {
    process.exit(0);
});

let line = '';
process.stdin.on('data', c => line += c);
process.stdin.on('end', () => {
    let input = line.trim().split('\n');
    for (let i = 1; i < input.length;) {
        let arrayLength = input[i];
        i += 1;
        let row = input[i].split(' ').map(x => Number(x));
        row.sort((a, b) => a - b);
        console.log(row[arrayLength - 1] - row[0]);
        i += 1;
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let tests = parseInt(readline());
  while (tests--) {
    let len = parseInt(readline());
    let arr = readline().split(' ').map(Number);
    console.log(Math.max(...arr)-Math.min(...arr));
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let tests = parseInt(readline());
  while (tests--) {
    let len = parseInt(readline());
    let arr = readline()
      .split(' ')
      .map(Number)
      .sort((a, b) => {
        return a - b;
      });
    console.log(arr[len - 1] - arr[0]);
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let tests = parseInt(readline());
  while (tests--) {
    let len = parseInt(readline());
    let arr = readline()
      .split(' ')
      .sort((a, b) => {
        return a - b;
      });
    console.log(arr[len - 1] - arr[0]);
  }
}

let line = '';
process.stdin.on('data', c => line += c);
process.stdin.on('end', () => {
    let input = line.trim().split('\n');
    for (let i = 1; i < input.length;) {
        const arrayLength = input[i];
        i += 1;
        let row = input[i].split(' ').map(x => Number(x));
        row.sort((a, b) => a - b);
        console.log(row[arrayLength - 1] - row[0]);
        i += 1;
    }
});

let buf='';

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

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    for(let i=1;i<=2*t;i+=2)
    {
        let arr=line[i+1].split(' ').map(x=>{ return parseInt(x) });
        let mx=0;
        let mn=1e10;
        for(let j=0;j<arr.length;j++)
        {
            mx=Math.max(mx,arr[j]);
            mn=Math.min(mn,arr[j]);
        }
        console.log(mx-mn);
    }
})

let buf='';

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

process.stdin.on('end',function(){
    let line=buf.split('\n');
    let t=parseInt(line[0]);
    for(let i=1;i<=2*t;i+=2)
    {
        let arr=line[i+1].split(' ').map(x=>{ return parseInt(x) });
        let mx=0;
        let mn=1e10;
        for(let j=0;j<arr.length;j++)
        {
            mx=Math.max(mx,arr[j]);
            mn=Math.min(mn,arr[j]);
        }
        // let ans=0;
        // console.log(mx);
        // for(let j=0;j<arr.length;j++)
        // {
        //     ans+=mx-arr[j];
        // }
        console.log(mx-mn);
        // console.log(arr);
    }
    // console.log(line);
})

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++){
		nl.num();
		let a = nl.nums();
		//let min = a.reduce((a, b) => (a < b)?a:b, 1000000000);
		//let max = a.reduce((a, b) => (a > b)?a:b, 0);
		let min = Math.min.apply(null, a);
		let max = Math.max.apply(null, a);
		ans.push(max - min);
	}
	console.log(ans.join('\n'));
};

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

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		nl.num();
		let a = nl.nums();
		let min = a.reduce((a, b) => (a < b)?a:b, 1000000000);
		let max = a.reduce((a, b) => (a > b)?a:b, 0);
		ans.push(max - min);
	}
	console.log(ans.join('\n'));
};

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

let data = "";

process.stdin.on("data", (c) => (data += c));
process.stdin.on("end", () => {
  let [_, ...input] = data
    .trim()
    .split(/\n/)
    .map((el) => el.trim());

  input = input.filter((el, idx) => idx % 2 !== 0);

  input = input.map((el) =>
    el
      .trim()
      .split(" ")
      .map((el) => +el.trim())
      .sort((a, b) => a - b)
  );

  input.forEach((el) => {
    console.log(el[el.length - 1] - el[0]);
  });
});

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 % 2 !== 0) {
    c++;
    return;
  }

  const digits = d.split(" ").map(Number);
  const min = Math.min(...digits);
  const max = Math.max(...digits);
  console.log(max - min);

  c++;
});

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

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

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

readline.on('line', line => {
    input.push(line);
}).on('close', () => {
    for (let i = 2; i < input.length; i+=2) {
        let nums = input[i].split(' ').map(Number);
        let [min, max] = [Math.min(...nums), Math.max(...nums)];
        ans.push(max-min);
    }
    console.log(ans.join('\n'));
});

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

const readline = () => inputString[currentLine++]
// Common Template Ends //

// Driver Function Starts //
const main = () => {
    console.clear()
    let t = parseInt(readline())
    while (t--) {
        let n = parseInt(readline())
        let a = readline().split(' ').map(Number)
        console.log(solve(n, a))
    }
}
// Driver Function Ends //

// MAIN LOGIC
const solve = (n, arr) => {
    if( n == 1 ) return 0
    if( n == 2 ) return Math.abs( arr[0] - arr[1] )

    arr = sortArray( arr )

    let min = minOfArray( arr )
    let max = maxOfArray( arr )

    return max - min
}

const isOdd         = (num) => num & 1
const isEven        = (num) => !(num & 1)
const minOfArray    = (arr) => Math.min.apply(null, arr)
const maxOfArray    = (arr) => Math.max.apply(null, arr)
const uniqueArray   = (arr) => [...new Set(arr)]
const sortArray     = (arr) => arr.sort((a, b) => a - b)
const sumOfArray    = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)

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

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = nextIntArray(N);
		var max = 0;
		var min = Math.pow(10, 9) + 1;
		for(var i = 0; i < N; i++){
			max = Math.max(max, list[i]);
			min = Math.min(min, list[i]);
		}
		myout(max - min);
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        solve();
    }
}

let count=0;
function solve() {
    let str = readLine();

    let c = readLine();

    var d = c.split(' ');
    var digits = d.map(iNum => parseInt(iNum, 10));

    count = Math.max(...digits) - Math.min(...digits);
    console.log(count)

}

var i = -1
require('readline').createInterface(process.stdin,process.stdout).on('line', (line) => {
  if (++i && !(i%2)) {
    const a = line.split(" ").map(Number);
    console.log(Math.max(...a) - Math.min(...a))
  };
});

process.stdin.resume();

process.stdin.setEncoding('utf8');

var input = '';

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

function main(input){
    input = input.split("\n");
    let z = 0;
    let testCases = +input[z++];
    for (let i = 0; i < testCases; i++) {
        let arrSize = +input[z++];
        let arr = input[z++].split(' ').map(t=>Number(t));
        let max = Math.max(...arr);
        let min = Math.min(...arr);
        console.log(max-min);
    }
}

/*
===== READ INPUT DATA START =====
=================================
*/

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

let inputString = '';

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

process.stdin.on('end', (_) => {
  const lines = inputString.trim().split('\n').map((string) => string.trim()).filter(Boolean);
  main(lines);
});

/*
===== READ INPUT DATA END =====
===============================
*/

function main(lines) {
  let index = 0;
  let T = Number(lines[index++]);
  let N;
  let arr;

  while (T--) {
    N = Number(lines[index++]);
    arr = lines[index++].split(' ').map(Number);
    solve(N, arr);
  }
}

function solve(N, arr) {
  const [minVal, maxVal] = [Math.min(...arr), Math.max(...arr)];

  console.log(maxVal - minVal);
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});
function readLine() {
  return inputString[currentLine++];
};
process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });
  main();
  // cmd: node cp.js < input.txt > output.txt
});
function main() {
  let t = parseInt(readLine());
  while (t--) {
    solve();
  }
}
function solve() {
  let len=readLine();
  let arr=readLine().split(" ");
  arr.sort((a,b)=>parseInt(a)-parseInt(b));;
  console.log(arr[len-1]-arr[0]);
}

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

function _main() {

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

	let t = inputReader.readNumber();

	function solve(){
	    let n = inputReader.readNumber();
	    let a = inputReader.readArray();
	    let max = Math.max(...a);
	    let min = Math.min(...a);
	    console.log(max - min);
	}

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

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readArray() {
		return _inputLines[_lineNumber++].split(' ');
	}

	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	return {
		readArray,
		readNumber,
	}
}

var di
var stdin_input = ""
process.stdin.resume()
process.stdin.setEncoding("ascii")
process.stdin.on("data", (input) => { stdin_input += input })
process.stdin.on("end", () => { main() })

const rl = () => di.next().value.trim(); //Read line
const rn = () => +rl(); //Read number
const ra = () => rl().split(' '); //Read array
const rna = () => ra().map(x => +x); //Read array of numbers
const l = i => {console.log(i)} //Return answer

const main = () => {
  di = stdin_input.split('\n').values()
  let T = rn();
  while (T--) {
    const _ = rn();
    const a = rna();
    l(Math.max(...a) - Math.min(...a));
	}
}

/* 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() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){
        const n = +(readline());
        const arr = readline().split(' ');

        plusOneSubset(arr)

    }
}
const plusOneSubset= (arr)=>{

    let arrNum = arr.map(el=>parseInt(el));

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

    let cSum = 0;
    for(let i =0; i+1<arrNum.length; ++i){
        cSum+= arrNum[i+1] - arrNum[i];
    }
    console.log(cSum);
}

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*/

    let count = 2;
    for (let i = 0; i < lines[0]; ++i) {
        let total = 0;
        const arr = lines[count].split(' ').map((el) => +el);

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

        const len = arr.length;

        if (len > 1) {
            const max = arr[0];
            for (let i = 1; i < len; ++i) {
                const curDiff = max - arr[i];
                total += curDiff;
                for (let j = i + 1; j < len; ++j) {
                    arr[j] += curDiff;
                }
            }
        }
        console.log(total);

        count += 2;
    }
});

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

var T = readline();
for(var q=1;q<=T;q++) {
    let n = readline();
    let a = readline().split(" ").map(w => parseInt(w))
    var max = -1, min = 100000000000;
    for(var i=0;i<a.length;i++) {
      max = Math.max(max, a[i])
	  min = Math.min(min,a[i])
    }
    console.log(max-min)
}

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

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

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

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

let solve = async () => {
    const tsc = await readInt();
    for(let sc = 0; sc < tsc; sc++) {
        const n = await readInt();
        const a = await readIntArray();
        a.sort((a,b) => a - b);
        console.log(a[a.length - 1] - a[0]);
    }
}

solve();

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

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

let count = -1
let inputArr = []

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

function solve([n], arr) {
    const sarr = arr.sort((a, b) => a - b)
    const max = sarr[0], min = sarr[sarr.length - 1]
    console.log(Math.abs(min - max))
}

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

const readline = require('readline')

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

function solve(n, arr) {
    arr.sort((a, b) => a - b)
    return arr[n - 1] - arr[0]
}

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

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

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

		const ans = Math.max(...a) - Math.min(...a);

		console.log(ans);
	}
}

test = readline();
while (test--) {
    readline();
    set = new Set()
    readline().split(' ').map(x => set.add(parseInt(x)));
    max = Math.max(...set);
    set = Array.from(set).sort((a, b) => b - a)
    steps = 0;
    set.forEach(num => {
        if (num < max) {
            num += steps
            steps += (max - num)
        }
    })
    print(steps)
}

j = +readline();
while (j--) {
  x = +readline();
  t = readline().split(" ").map(Number);
  if (t.length > 1) {
    q = Math.max(...t);
    w = Math.min(...t);
    c = q - w;
    print(c);
  } else {
    print(0);
  }
}

var tests=+readline()
for(var i=0;i<tests;i++){
var length=+readline()
var sequence=readline().split(" ").map(node=>+node)
sequence.sort((a,b)=>{
    return a-b
})
print((sequence[length-1]-sequence[0]))
}

var tests=+readline()
for(var i=0;i<tests;i++){
var length=+readline()
var sequence=readline().split(" ").map(node=>+node)
var min=sequence.reduce((a,b)=>Math.min(a,b))
var max=sequence.reduce((a,b)=>Math.max(a,b))

print((max-min))
}

'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 TC = getInt();
    for (let i = 0; i < TC; ++i) {
        const n = getInt();
        const arr = getInts();

        arr.sort((a, b) => a - b);
        print(arr[n - 1] - arr[0])
    }

}

var count = parseInt(readline());

while (count--){
   var n = readline();
   var n1 = readline()
   var arr = n1.split(' ').map(Number)
   print(Math.max(...arr) - Math.min(...arr))
}

var t = parseInt(readline());

  function solve() {
    var n = parseInt(readline());
    var a = readline().split(" ").map((data) => +data)
    var max = -Infinity
    var min = Infinity
    for (var i = 0; i < n; i++) {
      max = Math.max(max, a[i])
      min = Math.min(min, a[i])
    }
    return max - min;
  }

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

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], e= 0
    for(j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j]
        }else{
            var k = lines[j].split(' ').sort(function(a, b){return a-b}).map(Number)
            console.log(k[k.length] - k[0])
        }
    }
});

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 * 2; j++){
        if(j % 2 == 1){
            var a = Number(lines[j])
            if(a % 2 === 0){
                console.log(a / 2)
            }else{
                console.log(a += 1)
            }
        }
    }
});

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++){
        if(j % 2 == 1){
            var a = Number(lines[j])
            if(a % 2 === 0){
                console.log(a / 2)
            }else{
                console.log(a += 1)
            }
        }
    }
});

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++){
        if(j % 2 == 1){
            var a = lines[j]
            if(a % 2 === 0){
                console.log(a / 2)
            }else{
                console.log(a += 1)
            }
        }
    }
});

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++){
        if(j % 2 == 1){
            var a = lines[j]
            if(a % 2 === 0){
                console.log(a / 2)
            }else{
                console.log(a + 1)
            }
        }
    }
});

let line = '';
let rows = [];
process.stdin.on('data', c => line += c);
process.stdin.on('end', () => {
    const lines = line.split('\n');
    let input1 = +lines[0];

    for (let i = 1; i <= input1; i++) {
        let row = lines[i].split(' ');
        row.sort((a, b) => a - b);
        console.log(row[row.length - 1] - row[0]);
    }

});

j = +readline();
while (j--) {
  x = +readline();
  t = readline().split(" ").map(Number);
  if (t.length > 1) {
    q = Math.max(...t);
    w = Math.min(...t);
    c = q - w;
    print(c);
  } else {
    print(1);
  }
}

j = +readline();
while (j--) {
  x = +readline();
  t = readline().split(" ").map(Number);
  if (x > 1) {
    q = Math.max(...t);
    w = Math.min(...t);
    c = q - w;
    print(c);
  } else {
    print(1);
  }
}


function bfs(s, adj, visited) {
    var q = [];
    var pos = 0;
    q.push(s);
    visited[s] = true;
    while (pos < q.length) {
        var u = q[pos++];
        adj[u].forEach(function (v) {
            if (!visited[v]) {
                q.push(v);
                visited[v] = true;
            }
        });
    }
    return q.length;
}

var a = readline().split(" ").map(function (x) { return parseInt(x); });
var n = a[0], m = a[1];
var adj = [];
for (i = 0; i <= n; ++i) {
    adj.push([]);
}
for (i = 0; i < m; ++i) {
    a = readline().split(" ").map(function (x) { return parseInt(x); });
    adj[a[0]].push(a[1]);
    adj[a[1]].push(a[0]);
}
var visited = new Array(n + 1);
for (i = 0; i <= n; ++i) {
    visited[i] = false;
}
r = 1;
for (i = 1; i <= n; ++i) {
    if (!visited[i]) {
        var p = bfs(i, adj, visited);
        for (j = 1; j < p; ++j) {
            r = r * 2;
        }
    }
}
print(r);

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], m = data[1],
		edges = {}, vertices = [];
	edges.add = function (u, v) {
		if (edges[u] === undefined) {
			edges[u] = [v];
			vertices.push(u);
		} else {
			edges[u].push(v);
		}
	};
	for (var i = 0; i < m; ++i) {
		var pair = tokenizeIntegers(readline()),
			u = pair[0], v = pair[1];
		edges.add(u, v);
		edges.add(v, u);
	}
	var seen = {}, danger = 1;
	function dfs(u, double) {
		if (seen[u]) {
			return;
		}
		seen[u] = true;
		if (double) {
			danger *= 2;
		}
		var vs = edges[u];
		for (var i = 0; i < vs.length; ++i) {
			dfs(vs[i], true);
		}
	}
	for (var i = 0; i < vertices.length; ++i) {
		var u = vertices[i];
		dfs(u, false);
	}
	print(danger);
}

main();