let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStd) => {
  inputString += inputStd;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    let input = readLine();
    let countOne = 0;
    let countZero = 0;
    for (let i = 0; i < input.length; i++) {
      if (input[i] === "0") countOne++;
      else countZero++;
    }
    if (Math.abs(countOne - countZero) === input.length) console.log("NET");
    else {
      let num = Math.min(countZero, countOne);
      if (num % 2 === 1) console.log("DA");
      else console.log("NET");
    }
  }
}

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; t++) {
      var s = read();
      var c = {
         '0': 0,
         '1': 0
      };
      for (var i = 0; i < s.length; i++) {
         c[s[i]]++;
      }
      if (Math.min(c[0], c[1]) & 1) {
         write('da');
      } else {
         write('net');
      }
   }
}

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

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

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

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

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

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

//↓見なくていいよ！ここから--------------------------------------------------
var 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");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
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 s = nextCharArray();
		var zero = 0;
		var one = 0;
		for(var j = 0; j < s.length; j++){
			if(s[j] == "0"){
				zero++;
			}else{
				one++;
			}
		}
		myerr({zero,one});
		count = Math.min(zero, one);
		if(count % 2 == 0){
			output[i] = "NET";
		}else{
			output[i] = "DA";
		}
	}
	myout(myconv(output,9));
}

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

let stdinInput = '';

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

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

function main(data) {
  data = data.split('\n');
  const testCases = data[0] * 1;
  let i = 1;
  while (i <= testCases) {
    let s = data[i].trim().split('');
    let count = 1;
    for (let j = 0; j < s.length; j += 1) {
      if ((s[j] === '0' && s[j + 1] === '1') || (s[j] === '1' && s[j + 1] === '0')) {
        s.splice(j, 2);
        count += 1;
        j = -1;
      }
    }
    count % 2 === 0 ? console.log('DA') : console.log('NET');
    i += 1;
  }
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let numDeleted = 0;
    let i = 1;
    while (i <= testCases) {
        var j = 0;
        numDeleted = 0
        let curString = data[i]
        while (j < curString.length - 1) {
            if ((curString.charAt(j) === "0" && curString.charAt(j + 1) === "1") ||
            (curString.charAt(j) === "1" && curString.charAt(j + 1) === "0")) {
                let tempString = ""
                if (j === 0) {
                    tempString = curString.substring(2)
                } else {
                    tempString = curString.substring(0, j)
                    if (j + 2 < curString.length) {
                        tempString += curString.substring(j + 2, curString.length)
                    }
                }
                curString = tempString
                j = Math.max(j - 1, 0)
                numDeleted++
            } else {
                j++
            }
        }
        i++
        console.log((numDeleted !== 0 && numDeleted % 2 !== 0) ? "DA" : "NET")
    }
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let numDeleted = 0;
    let i = 1;
    while (i <= testCases) {
        let stack = []
        let numDeleted = 0
        let j = 0;
        let curString = data[i].split('')
        for(j = 0; j < curString.length; j++) {
            if ((curString[j] === '0' && stack[stack.length-1] === '1') ||
            (curString[j] === '1' && stack[stack.length-1]) === '0') {
                numDeleted++
                stack.pop()
            } else {
                stack.push(curString[j])
            }
        }
        i++
        console.log((numDeleted !== 0 && numDeleted % 2 !== 0) ? "DA" : "NET")
    }
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let i;
    for(i = 1; i <= testCases; i++) {
        solve(data[i])
    }
}

function solve(line) {
    var i;
    let num0 = 0
    let num1 = 0
    let lineSplit = line.split('')
    for(i = 0; i < line.length; i++) {
        if (lineSplit[i] == '0') {
            num0++
        } else {
            num1++
        }
    }

    console.log((Math.min(num0, num1) % 2 !== 0) ? "DA" : "NET")
}

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

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

  let count = 0;
  const arr = [...str];

  for (let i = 1; i < arr.length; i++) {
    if (arr[i] !== arr[i - 1]) {
      arr.splice(i-1, 2);
      i = 0;
      count++;
    }
  }

  if (count % 2) {
    console.log('DA');
  }
  else {
    console.log('NET');
  }

  c++;
});

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

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

  let zeros = 0;
  let ones = 0;

  for (let i = 0; i < str.length; i++) {
    if (str[i] === '1') {
      ones++;
    }
    else {
      zeros++;
    }
  }

  let count = Math.min(zeros, ones);
  if (count % 2) {
    console.log('DA');
  }
  else {
    console.log('NET');
  }

  // let count = 0;
  // const arr = [...str];

  // for (let i = 1; i < arr.length; i++) {
  //   if (arr[i] !== arr[i - 1]) {
  //     arr.splice(i-1, 2);
  //     i = 0;
  //     count++;
  //   }
  // }

  // if (count % 2) {
  //   console.log('DA');
  // }
  // else {
  //   console.log('NET');
  // }

  c++;
});

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

function main() {
  let T = s2i(readLine());
  let s, c0, c1, totalMoves;
  let out = '';
  while (T--) {
    s = readLine()
    c0 = 0
    c1 = 0
    for (let i = 0, l = s.length, c; i < l; i++) {
      c = s.charAt(i);
      if (c === '0') c0++;
      else c1++;
    }

    totalMoves = Math.min(c0, c1);

    // console.log(totalMoves % 2 === 0 ? 'NET' : 'DA');
    out += totalMoves % 2 === 0 ? 'NET\n' : 'DA\n'
  }
  console.log(out)
}

const readline = require('readline');

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

var lineCount = 0
var testCount = 0
var outputStr = ''

rl.on('line', (input) => {
    if (lineCount == 0) {
        // first line
        testCount = parseInt(input)
    }
    else if (lineCount >= testCount) {
        outputStr += getWinner(input) + '\n'
        console.log(outputStr)
        rl.close()
    }
    else {
        // data
        outputStr += getWinner(input) + '\n'
    }
    lineCount++
});

function getWinner(str) {
    var count0 = 0
    var count1 = 0
    for(var i=0;i<str.length;i++){
        if(parseInt(str[i])==0){
            count0++
        }
        else{
            count1++
        }
    }
    return Math.min(count0,count1)%2?'DA':'NET'

}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let i;
    for(i = 1; i <= testCases; i++) {
        solve(data[i])
    }
}

function solve(line) {
    var i;
    let num0 = 0
    let num1 = 1
    let lineSplit = line.split('')
    for(i = 0; i < line.length; i++) {
        if (lineSplit[i] == '0') {
            num0++
        } else {
            num1++
        }
    }

    console.log((Math.min(num0, num1) % 2 !== 0) ? "DA" : "NET")
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split(/\r?\n/);
    const testCases = data[0] * 1;
    let numDeleted = 0;
    let i = 1;
    while (i <= testCases) {
        var j = 0;
        numDeleted = 0
        let curString = data[i]
        while (j < curString.length - 1) {
            if ((curString.charAt(j) === "0" && curString.charAt(j + 1) === "1") ||
            (curString.charAt(j) === "1" && curString.charAt(j + 1) === "0")) {
                if (j === 0) {
                    curString = curString.substring(2)
                } else {
                    curString = curString.substring(0, j) + curString.substring(Math.min(j + 1, curString.length - 1), curString.length - 1)
                }
                j = Math.max(j - 1, 0)
                numDeleted++
            } else {
                j++
            }
        }
        i++
        console.log((numDeleted !== 0 && numDeleted % 2 !== 0) ? "DA" : "NET")
    }
}


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

    probC();
});

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

function pi(a) {
    return parseInt(a);
}

function probA(){
    let t = parseInt(readline());
    while(t > 0){
        t--;
        let [n,k] = readline().split(' ');
        n = pi(n);
        k = pi(k);

        if(n < k)
            console.log(k-n);
        else{
            if((n+k) % 2 === 0){
                console.log(0);
            }else{
                console.log(n-k);
            }
        }
    }
}

function probB(){
    let t = pi(readline());

    while(t > 0){
        t--;
        let a = readline().split(' ');
        let b = readline().split(' ');

        a[0] = pi(a[0]);
        a[1] = pi(a[1]);
        a[2] = pi(a[2]);

        b[0] = pi(b[0]);
        b[1] = pi(b[1]);
        b[2] = pi(b[2]);

        let maxSum = 0;
        if(b[2] - (a[0] + a[2]) > 0){
            b[2] = b[2] - (a[0]+a[2]);
            a[0] = 0;
            a[2] = 0;
        }else if(b[2] - a[0] > 0){
            a[2] = a[2] - (b[2] - a[0]);
            b[2] = 0;
            a[0] = 0;
        }else{
            a[0] -= b[2];
            b[2] = 0;
        }

        if(a[2] > b[1])
            console.log((b[1] - b[2]) * 2)
        else
            console.log((a[2]-b[2]) * 2);

    }
}

function probC(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = readline().split(' ');
        let x = JSON.parse(JSON.stringify(a));

        x.sort((a,b) => pi(a) - pi(b));
        let res = true;
        for(let i = 0; i < n; i++){
            if(x[i] !== a[i]){
                if(pi(a[i]) % pi(x[0]) !== 0){
                    res = false;
                    break;
                }
            }
        }

        if(res)
            console.log('yes');
        else
            console.log('no');
    }
}

let inputString = "";
let currentLine = 0;
process.stdin.on("data", (data) => {
  inputString += data;
});
process.stdin.on("end", function () {
  inputString = inputString
    .trim()
    .split("\n")
    .map((str) => str.trim());
  main();
});
function readLine() {
  return inputString[currentLine++];
}
function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine()
      .split(" ")
      .map((n) => parseInt(n));

    const sorted = [...arr].sort((a, b) => a - b);
    const min = sorted[0];
    let possible = true;

    for (let i = 0; i < len; i++) {
      if (sorted[i] !== arr[i]) {
        if (arr[i] % min !== 0) {
          possible = false;
        }
      }
    }

    possible ? console.log("YES") : console.log("NO");
  }
}

function For(a, b, fn) {
  if (!fn) return For(0, a - 1, b);
  let res;
  for (let i = a; i <= b; i++) {
    if ((res = fn(i)) != null) return res;
  }
}
function ForR(a, b, fn) {
  if (!fn) return ForR(a - 1, 0, b);
  let res;
  for (let i = a; i >= b; i--) {
    if ((res = fn(i)) != null) return res;
  }
}

function Arr(a, b, fn) {
  if (typeof (b) == 'function') return Arr(0, a - 1, b);
  if (b < a) return [];
  let arr = Array(b - a + 1)
  for (let i = a; i <= b; i++) arr[i] = fn(i, arr);
  return arr;
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}
Array.prototype.min = function (fn) {
  let min = 1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x < min) { min = x; index = i }
  }
  return [this[index], index, min];
}
Array.prototype.max = function (fn) {
  let max = -1e20, index = -1, x;
  for (let i = 0; i < this.length; i++) {
    x = fn ? fn(this[i], i, this) : this[i];
    if (x > max) { max = x; index = i }
  }
  return [this[index], index, max];
}
Array.prototype.rev = function (first, last) {
  for (let i = first; i < (first + last) / 2; i++) {
    [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
  }
}
Array.prototype.set = function (pos, arr) {
  for (let i = pos; i < pos + arr.length; i++) {
    this[i] = arr[i - pos];
  }
}
Array.prototype.for = function (a, b, fn) {
  let res
  for (let i = a; i <= b; i++) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.forR = function (a, b, fn) {
  let res
  for (let i = a; i >= b; i--) {
    if ((res = fn(this[i], i, this)) != null) return res;
  }
}
Array.prototype.bin = function (comp, a, b) {
  let mid;
  while (a < b) {
    mid = (a + b) / 2 | 0;
    if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
    else b = mid;
  }
  return a;
}
Array.prototype.cut = function (fn, a, b) {
  let arr = [];
  a = a || 0;
  b = b || (this.length - 1);
  let prev = a;
  for (let i = a; i <= b; i++) {
    if (i == b || fn(this[i], this[i + 1])) {
      arr.push(this.slice(prev, i + 1));
      prev = i + 1;
    }
  }
  return arr;
}

function gcd(a, b) {
  while (b) [a, b] = [b, a % b];
  return a;
}
function mul(a, b, m) {
  return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m
}
function pow(a, n, m) {
  let r = 1;
  while (n) n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1]
  return r;
}
function inv(b, m) {
  for (var a = m, u = 0, v = 1, t; b; v = t)
    (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
  return (u + m) % m;
}

// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);

// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];

// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }

// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
  let t = $()
  while (t--) {
    let n = $(), a = $(n), m = a.min()[0], b = a.filter(v => v % m == 0).sort(asc);
    let j = 0;
    For(n, i => {
      if (a[i] % m == 0) a[i] = b[j++];
    })
    log(For(n - 1, i => a[i] > a[i + 1] ? 1 : null) ? 'NO' : 'YES')
  }
}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    str = readline();
    var a = str.split(" ");
    var b = str.split(" ");
    a = a.map(a => Number(a));
    b = b.map(a => Number(a));
    b.sort((a, b) => a - b);

    var min = b[0];
    var out = true;
    for (var j = 0; j < a.length; j++){
        if ((a[j] != b[j]) && (a[j] % min > 0)){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO");
    }
}

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.split(/\n/);
    main();
});

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

function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
    const n = Number(readLine())
    const as = readLine().split(/\s/).map(Number).slice(0, n)
    const sorted = [...as].sort((a, b) => a - b)
    const minimum = sorted[0]
    let result = true
    for (let i = 0; i < n; i++) {
      if (as[i] !== sorted[i] && as[i] % minimum !== 0) {
        result = false
        break
      }
    }
    console.log(result ? 'YES' : 'NO')
  }
}

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.split(/\n/);
    main();
});

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

function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
    const n = Number(readLine())
    const as = readLine().split(/\s/).map(Number)
    const sorted = [...as].sort((a, b) => a - b)
    const minimum = sorted[0]
    let result = true
    for (let i = 0; i < n; i++) {
      if (as[i] !== sorted[i] && as[i] % minimum !== 0) {
        result = false
        break
      }
    }
    console.log(result ? 'YES' : 'NO')
  }
}

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.split(/\n/);
    main();
});

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

function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
    const n = Number(readLine())
    const as = readLine().split(/\s/).map(Number)
    const sorted = [...as].sort((a, b) => a - b)
    const minimum = sorted[0]
    let result = true
    console.log(as, minimum, sorted)
    for (let i = 0; i < n; i++) {
      if (as[i] !== sorted[i] && as[i] % minimum !== 0) {
        result = false
        console.log('failed', i)
        break
      }
    }
    console.log(result ? 'YES' : 'NO')
  }
}

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.split(/\n/);
    main();
});

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

function main() {
  const t = Number(readLine())
  for (let _ = 0; _ < t; _++) {
    const n = Number(readLine())
    const as = readLine().split(/\s/).map(Number)
    const sorted = [...as].sort((a, b) => a - b)
    console.log(as.every((a, i) => a === sorted[i] || a % sorted[0] === 0) ? 'YES' : 'NO')
  }
}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    var a = readline().split(" ");
    b = a.concat();
    b.sort((a, b) => {
        if(a > b){
            return 1;
        }
        else{
            return -1;
        }
    })
    var min = b[0];
    var out = true;
    for (var j = 0; j < a.length; j++){
        if ((a[j] != b[j]) && (a[j] % min > 0)){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO");
    }
}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    str = readline();
    var a = str.split(" ");
    var b = str.split(" ");
    a = a.map(a => Number(a));
    b.sort((a, b) => {
        if(a > b){
            return 1;
        }
        else{
            return -1;
        }
    })
    var min = b[0];
    var out = true;
    for (var j = 0; j < a.length; j++){
        if ((a[j] != b[j]) && (a[j] % min > 0)){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO");
    }
}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    var a = readline().split(" ");
    a = a.map(a => Number(a));
    b = a.sort((a, b) => {
        if(a > b){
            return 1;
        }
        else{
            return 0;
        }
    })
    var temp;
    var min = b[0];
    var out;
    for (var j = 0; j < a.length; j++){
        if ((a[j] != b[j]) != (a[j] % min > 0)){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO")
    }
}

function gcd(a, b){
    var temp;
    if (b > a){
        temp = a;
        a = b;
        b = temp;
    }

    var res = b;

    while(res > 1){
        if((a % res == 0) && (b % res == 0)){
            break;
        }
        res--;
    }

    if(res <= b){
        return res;
    }
    else{
        return false;
    }

}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    var a = readline().split(" ");
    a = a.map(a => Number(a));
    var temp;
    var min = a[0];

    for (var j = 0; j < a.length; j++){
        if (a[j] < min){
            min = a[j];
        }
    }

    for (var j = 0; j < a.length; j++){
        for(var d = j+1; d < a.length; d++){
            if((gcd(a[j], a[d]) == min) && (a[j] > a[d])){
                temp = a[j];
                a[j] = a[d];
                a[d] = temp;
            }
        }
    }
    var out = true;
    for (var j = 0; j < a.length - 1; j++){
        if(a[j] > a[j+1]){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO")
    }
}

function gcd(a, b){
    var temp;
    if (b > a){
        temp = a;
        a = b;
        b = temp;
    }

    var res = 2;

    while(res <= b){
        if((a % res == 0) && (b % res == 0)){
            break;
        }
        res++;
    }

    if(res <= b){
        return res;
    }
    else{
        return false;
    }

}

var t = Number(readline());

for (var i = 0; i < t; i++){
    var n = Number(readline());
    var a = readline().split(" ");
    a = a.map(a => Number(a));
    var temp;
    var min = a[0];

    for (var j = 0; j < a.length; j++){
        if (a[j] < min){
            min = a[j];
        }
    }

    for (var j = 0; j < a.length; j++){
        for(var d = j+1; d < a.length; d++){
            if((gcd(a[j], a[d]) == min) && (a[j] > a[d])){
                temp = a[j];
                a[j] = a[d];
                a[d] = temp;
            }
        }
    }
    var out = true;
    for (var j = 0; j < a.length - 1; j++){
        if(a[j] > a[j+1]){
            out = false;
        }
    }

    if(out){
        print("YES");
    }
    else{
        print("NO");
    }
}


var x = parseInt(readline());
var n = readline().split(" ").map(function(x){return parseInt(x);}).filter(function(x){return x==0;});

print((x==1&&n.length==0)||(x>1&&n.length==1)?"YES":"NO");

function InputButtons() {
  readline();
  const buttons = readline().split(' ').map((element) => {
    return parseInt(element);
  });
  return buttons;
}

function IsFastened(button) {
  if (buttons.length == 1) {
    if (buttons[0] == 1) {
      return true;
    }
    else {
      return false;
    }
  }

  var isFastened = false;
  var result = true;
  buttons.forEach(function(button) {
    if (button == 0) {
      if (!isFastened) {
        isFastened = true;
      }
      else {
        result = false;
      }
    }
  });
  if (!result) {
    return false;
  }
  else {
    return isFastened;
  }
}

var buttons = InputButtons();
if (IsFastened(buttons)) {
  print('YES');
}
else {
  print('NO');
}

function InputButtons() {
  readline();
  const buttons = readline().split(' ').map((element) => {
    return parseInt(element);
  });
  return buttons;
}

function IsFastened(button) {
  if (buttons.length == 1) {
    if (buttons[0] == 1) {
      return true;
    }
    else {
      return false;
    }
  }

  var isFastened = false;
  buttons.forEach(function(button) {
    if (button == 0) {
      if (!isFastened) {
        isFastened = true;
      }
      else {
        return false;
      }
    }
  });

  return isFastened;
}

var buttons = InputButtons();
if (IsFastened(buttons)) {
  print('YES');
}
else {
  print('NO');
}


var a = readline();
var b = a.split(" ", 2);
var n = Number(b[0]);
var k = Number(b[1]);
print((n * n + k - n + n  * (k - 1) + 1) / 2 * n);

var x = 0, y = n * (k - 1);
for (var i = 0; i < n; ++i) {
    var str = "";
    for (var j = 0; j < k - 1; ++j) {
        str += ++x + " ";
    }
    for (var j = k - 1; j < n; ++j) {
        str += ++y + " ";
    }
    print(str);
}

var a = readline();
var b = a.split(" ", 2);
var n = Number(b[0]);
var k = Number(b[1]);

var arr = new Array(n);
for (var i = 0; i < n; ++i) {
    arr[i] = new Array(n);
}

var num = n * n;
for (var i = 0; i < n; ++i) {
    for (var j = n - 1; j >= k - 1; --j) {
        arr[i][j] = num--;
    }
}

if (num) {
    for (var i = 0; i < n; ++i) {
        for (var j = k - 2; j >= 0; --j) {
            arr[i][j] = num--;
        }
    }
}

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

print(sum);
for (var i = 0; i < n; ++i) {
    print(arr[i].join(" "));
}


var N = parseInt(readline());
var a = readline().split(" ").map(function(x){return parseInt(x);});

var res = 0;
var swaps = [];
var temp = 0;

function selectionSort(sortMe)
{
    var i, j, tmp, tmp2;
    for (i = 0; i < sortMe.length - 1; i++)
    {
        tmp = i;
        for (j = i + 1; j < sortMe.length; j++){
            if (sortMe[j] < sortMe[tmp]){
                tmp = j;
            }
        }
        if(tmp!=i){
            tmp2 = sortMe[tmp];
            sortMe[tmp] = sortMe[i];
            sortMe[i] = tmp2;
            res++;
            swaps.push({x: i, y: tmp});
        }
	}
}

selectionSort(a);
print(res);
for(var i=0; i < swaps.length; i++){
	print(swaps[i].x + " " + swaps[i].y);
}

var n = parseInt(readline());
var nums = readline().split(' ').map(function(x){return parseInt(x)});
var min, k, tmp;
var step = [];

for(var i=0;i<nums.length;++i) {
  var min = nums[i];
  k = i;
  for(var j=i;j<nums.length;++j) {
    if (nums[j] < min) {
      min = nums[j];
      k = j;
    }
  }
  if (k != i) {
     step.push([i, k]);
  }
  tmp = nums[i];
  nums[i] = nums[k];
  nums[k] = tmp;
}

print(step.length);
if (step.length > 0)
  for(var i=0;i<step.length;++i)
    print(step[i][0] + ' ' + step[i][1]);

var n = parseInt(readline());
var list = readline().split(' ');
var ctr = 0;
var seq = [];
var tmp;
for(var i = 0; i < list.length - 1; i++) {
	var minId = i;
	list[i] = parseInt(list[i]);
	for(var j = i + 1; j < list.length; j++) {
		list[j] = parseInt(list[j]);
		if(list[j] < list[minId]) {
			minId = j;
		}
	}
	if(minId !== i) {
		ctr++;
		seq.push([i, minId]);
		tmp = list[i];
		list[i] = list[minId];
		list[minId] = tmp;
	}
}
print(ctr);
for(i = 0; i < ctr; i++) {
	print(seq[i][0] + ' ' + seq[i][1]);
}

var n = parseInt(readline());
var a = readline().split(' ');
var cnt = 0;
var b = [];
for (var i=0;i<n;i++) a[i] = parseInt(a[i]);
for (var i=0;i<n;i++){
	var k = i;
	for (var j=i+1;j<n;j++){
		if (a[j]<a[k]){
			k = j;
		}
	}
	if (k!=i){
		cnt++;
		b.push([i,k]);
		var tmp = a[i];
		a[i] = a[k];
		a[k] = tmp;
	}
}
print(cnt);
for(var i=0;i<cnt;i++){
	print(b[i][0]+' '+b[i][1]);
}

var N = parseInt(readline());
var a = readline().split(" ").map(function(x){return parseInt(x);});

var res = 0;
var swaps = [];
var temp = 0;

function selectionSort(sortMe)
{
    var i, j, tmp, tmp2;
    for (i = 0; i < sortMe.length - 1; i++)
    {
        tmp = i;
        for (j = i + 1; j < sortMe.length; j++){
            if (sortMe[j] < sortMe[tmp]){
                tmp = j;
            }
        }
        if(tmp!=i){
            tmp2 = sortMe[tmp];
            sortMe[tmp] = sortMe[i];
            sortMe[i] = tmp2;
            res++;
            swaps.push({x: i, y: tmp2});
        }
	}
}

selectionSort(a);
print(res);
for(var i=0; i < swaps.length; i++){
	print(swaps[i].x + " " + swaps[i].y);
}

var n = parseInt(readline());
var list = readline().split(' ');
var ctr;
var seq = [];
for(var i = 0; i < list.length - 1; i++) {
	var minId = i;
	list[i] = parseInt(list[i]);
	for(var j = 1; j < list.length; j++) {
		list[j] = parseInt(list[j]);
		if(list[j] < list[minId]) {
			minId = j;
		}
	}
	if(minId !== i) {
		ctr++;
		seq.push([i, minId]);
	}
}
print(ctr);
for(i = 0; i < ctr - 1; i++) {
	print(seq[i] + ' ' + seq[i + 1]);
}

var n = parseInt(readline());
var a = readline().split(' ');
var cnt = 0;
var b = [];
for (var i=0;i<n;i++) a[i] = parseInt(a[i]);
for (var i=0;i<n;i++){
	var k = i;
	for (var j=i+1;j<n;j++){
		if (a[j]<a[k]){
			k = j;
		}
	}
	if (k!=i){
		cnt++;
		b.push([i,k]);
		var tmp = a[i];
		a[i] = a[j];
		a[j] = tmp;
	}
}
print(cnt);
for(var i=0;i<cnt;i++){
	print(b[i][0]+' '+b[i][1]);
}

var n = parseInt(readline());
var a = new Array();
a = readline().split(' ');
for (var i=0;i<n;i++){
	var k = i;
	for (var j=i+1;j<n;j++){
		if (a[j]<a[k]){
			k = j;
		}
	}
	if (k!=i){
		var tmp = a[i];
		a[i] = a[j];
		a[j] = tmp;
		print(i+" "+k);
	}
}

var n = parseInt(readline());
var a = new Array();
a = readline().split(' ');
for (var i=0;i<n;i++){
	var k = i;
	for (var j=i+1;j<n;j++){
		if (a[j]<a[k]){
			k = j;
		}
	}
	if (k!=i) print(i+" "+k);
}


(function() {
    var s = readline().split(' ');
    var n = parseInt(s[0]);
    var t = parseInt(s[1]);
    var c = parseInt(s[2]);
    s = readline().split(' ');
    var i, a = [-1];
    for(i = 0 ; i < n ; ++i){
        if ( parseInt(s[i]) > t ){
            a.push(i);
        }
    }
    a.push(n);
    var diff, result = 0;
    for(i = 1 ; i < a.length ; ++i){
        diff = a[i] - a[i-1] - 1;
        result += Math.max(diff-c+1,0);
    }
    print(result);
})();

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

print(function(n, t, c) {
  var a = readline().split(' ').map(Number);

  var count = 0;
  var ans = 0;
  for (var i = 0; i < n; i++) {
    if (a[i] <= t) {
      count++;
      if (count >= c) {
        ans++;
      }
    } else {
      count = 0;
    }
  }
  return ans;

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

var ntc = readline().trim().split(' ').map((x)=>parseInt(x))
var n=ntc[0],t=ntc[1],c=ntc[2];
var x = readline().trim().split(' ').map((x)=>parseInt(x))
var ans =0;
var p=[];
for(var i=0;i<n;i++){
    if(x[i]>t)
        p.push(i)
}
if(p.length==0)
    ans = n-c+1;
else{
    for(var i=0;i<p.length;i++){
        ans+=Math.max(p[i]-(i==0?(-1):p[i-1])-c,0);
    }
    ans+=Math.max(n-p.pop()-c,0);
}

print(ans);

;(function () {

	var n = readline().split(' '), t, c, p = readline().split(' ').map(Number), k = 0, l = 0;
	t = +n[1];
	c = +n[2];
	n = +n[0];

	for (var i = 0; i < n; i++) {
		if (p[i] <= t) l++;
		else l = 0;

		if (l >= c) k++;
	}

	print(k);

}).call(this);

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

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

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

function main() {
	var data = tokenizeIntegers(readline()),
		n = data[0], maxCrime = data[1], minSpan = data[2],
		count = 0,
		crimes = tokenizeIntegers(readline()),
		span = 0;
	for (var i = 0; i < n; ++i) {
		if (crimes[i] <= maxCrime) {
			++span;
			if (span >= minSpan) {
				++count;
			}
		} else {
			span = 0;
		}
	}
	print(count);
}

main();

var tmp = readline().split(' ');
var t = parseInt(tmp[1]);
var c = parseInt(tmp[2]);
var items = readline().split(' ');
var answ = 0, size = 0;

for( var i = 0; i < items.length; ++i) {
  if (parseInt(items[i]) <= t ) {
    size++;
  } else {
    if(size >= c){
      answ += 1 + size - c;
    }
    size = 0;
  }
}

if(size >= c) answ += 1 + size - c;

print(answ);

var tok = null;
var index = 0;
function next() {
    while (tok == null || index == tok.length) {
        tok = readline().split(' ');
        index = 0;
    }
    var res = tok[index++];
    return res;
}

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

function main() {
    var n;
    var t;
    var c;
    n = nextInt();
    t = nextInt();
    c = nextInt();
    var pre = 0;
    var result = 0;
    for (var i = 0; i < n; i++) {
        var x = nextInt();
        if (x > t) {
            if (i - pre >= c) {
                result += (i - pre + 1 - c);
            }
            pre = i + 1;
        }
    }
    if(n-pre>=c){
    result += (n - pre + 1 - c);
    }
    print(result);
}

main();

"use strict";

var _slicedToArray = (function() {
  function sliceIterator(arr, i) {
    var _arr = [];
    var _n = true;
    var _d = false;
    var _e = undefined;
    try {
      for (
        var _i = arr[Symbol.iterator](), _s;
        !(_n = (_s = _i.next()).done);
        _n = true
      ) {
        _arr.push(_s.value);
        if (i && _arr.length === i) break;
      }
    } catch (err) {
      _d = true;
      _e = err;
    } finally {
      try {
        if (!_n && _i["return"]) _i["return"]();
      } finally {
        if (_d) throw _e;
      }
    }
    return _arr;
  }
  return function(arr, i) {
    if (Array.isArray(arr)) {
      return arr;
    } else if (Symbol.iterator in Object(arr)) {
      return sliceIterator(arr, i);
    } else {
      throw new TypeError(
        "Invalid attempt to destructure non-iterable instance"
      );
    }
  };
})();

var compose = function compose() {
  for (
    var _len = arguments.length, functions = Array(_len), _key = 0;
    _key < _len;
    _key++
  ) {
    functions[_key] = arguments[_key];
  }

  return function() {
    for (
      var _len2 = arguments.length, args = Array(_len2), _key2 = 0;
      _key2 < _len2;
      _key2++
    ) {
      args[_key2] = arguments[_key2];
    }

    return functions.reduce(function(currArgs, func) {
      return func(currArgs);
    }, args);
  };
};

var lineToNumberArray = function lineToNumberArray(str) {
  return str.split(" ").map(function(num) {
    return parseInt(num, 10);
  });
};

var readNumbersLine = compose(
  readline,
  lineToNumberArray
);

var _readNumbersLine = readNumbersLine(),
  _readNumbersLine2 = _slicedToArray(_readNumbersLine, 3),
  n = _readNumbersLine2[0],
  t = _readNumbersLine2[1],
  c = _readNumbersLine2[2];

var arr = readNumbersLine();
var lastTOver = -1;
var res = 0;

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;

try {
  for (
    var _iterator = arr.entries()[Symbol.iterator](), _step;
    !(_iteratorNormalCompletion = (_step = _iterator.next()).done);
    _iteratorNormalCompletion = true
  ) {
    var _ref = _step.value;

    var _ref2 = _slicedToArray(_ref, 2);

    var key = _ref2[0];
    var value = _ref2[1];

    if (value > t) lastTOver = key;
    if (key - lastTOver >= c) res++;
  }
} catch (err) {
  _didIteratorError = true;
  _iteratorError = err;
} finally {
  try {
    if (!_iteratorNormalCompletion && _iterator.return) {
      _iterator.return();
    }
  } finally {
    if (_didIteratorError) {
      throw _iteratorError;
    }
  }
}

print(res);

var tmp = readline().split(' ');
var t = parseInt(tmp[1]);
var c = parseInt(tmp[2]);
var items = readline().split(' ');
var answ = 0, size = 0;

for( var i = 0; i < items.length; ++i) {
  if (parseInt(items[i]) <= t ) {
    size++;
  } else if(size >= c){
    answ += 1 + size - c;
    size = 0;
  }
}

if(size >= c) answ += 1 + size - c;

print(answ);

var tmp = readline().split(' ');
var t = parseInt(tmp[1]);
var c = parseInt(tmp[2]);
var items = readline().split(' ');
var answ = 0, size = 0;

for( var i = 0; i < items.length; ++i) {
  if (parseInt(items[i]) <= t ) {
    size++;
  } else {
    answ += 1 + size - c;
    size = 0;
  }
}

answ += 1 + size - c;

print(answ);

(function() {
    var s = readline().split(' ');
    var n = parseInt(s[0]);
    var t = parseInt(s[1]);
    var c = parseInt(s[2]);
    s = readline().split(' ');
    var i, a = [-1];
    for(i = 0 ; i < n ; ++i){
        if ( parseInt(s[i]) > t ){
            a.push(i);
        }
    }
    a.push(n);
    var diff, result = 0;
    for(i = 1 ; i < s.length ; ++i){
        diff = a[i] - a[i-1] + 1;
        result += Math.max(diff-parseInt(c)+1,0);
    }
    print(result);
})();


'use strict';

function solve(n, m, a) {
  const max = Math.max(...a.flat());
  let r = 0,
      c = 0;
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < m; j++) {
      if (max === a[i][j]) {
        r = Math.max(i + 1, n - i);
        c = Math.max(j + 1, m - j);
        return r * c;
      }
    }
  }
  return -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, m] = (await read()).split(' ').map(Number);
      const a = [];
      let tmp = n;
      while (tmp--) {
        a.push((await read()).split(' ').map(Number));
      }
      res[i] = solve(n, m, 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);
});

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

/***
Codeforces Round #801 (Div. 2) and EPIC Institute of Technology Round
2022-06-18

A. Subrectangle Guess
***/

function main() {
  var t = readline();
  t = parseInt(t);
  for (let i = 0; i < t; i++) {
    let dim_in = readline();
    dim_in = dim_in.split(" ");
    dim_in = dim_in.map((k) => parseInt(k));
    const n = parseInt(dim_in[0]);
    const m = parseInt(dim_in[1]);

    let cur_max = -1e10;
    let max_row, max_col;

    // Strategy: find the max value and return the largest area of
    // the rectangle between that location and a corner
    for (let row = 0; row < n; row++) {
      let cur_row = readline();
      cur_row = cur_row.split(" ");
      cur_row = cur_row.map((k) => parseInt(k));
      for (let col = 0; col < m; col++) {
        if (cur_row[col] > cur_max) {
          cur_max = cur_row[col];
          max_row = row;
          max_col = col;
        }
      }
    }

    console.log(
      Math.max(
        (max_row + 1) * (max_col + 1),
        (max_row + 1) * (m - max_col),
        (n - max_row) * (max_col + 1),
        (n - max_row) * (m - max_col)
      )
    );
  }
}

'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) {
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

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

    for (let i = 0; i < N; i++) {
        let [n, m] = readline().split(' ').map(Number);

        let max = -Infinity;
        let maxN = -1;
        let maxM = -1;
        for (let j = 0; j < n; j++) {
            let row = readline().split(' ').map(Number);
            for (let k = 0; k < m; k++) {
                if (row[k] > max) {
                    max = row[k];
                    maxN = j + 1;
                    maxM = k + 1;
                }
            }
        }

        let offsetN = Math.max(Math.abs(n - maxN + 1), maxN);
        let offsetM = Math.max(Math.abs(m - maxM + 1), maxM);

        output(offsetN * offsetM);
    }
}

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

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

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

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

function main() {
    var t = parseInt(readline());

    for (let i = 0; i < t; i++) {
        var x = readline().split(' ');
        var n = parseInt(x[0]);
        var m = parseInt(x[1]);

        var a = [];
        var I = 0, J = 0, maxf = Number.NEGATIVE_INFINITY;
        for (let j = 0; j < n; j++) {
            a[j] = readline().split(' ');
            var max = Number.NEGATIVE_INFINITY;
            var J_ = 0;
            for (let k = 0; k < m; k++) {
                a[j][k] = parseInt(a[j][k]);
                if (max < a[j][k]) {
                    max = a[j][k];
                    J_ = k;
                }
            }

            if (max > maxf) {
                maxf = max;
                I = j;
                J = J_;
            }
        }

        var h = Math.max(I+1, n-I);
        var w = Math.max(J+1, m-J);

        console.log(h*w);
    }
}

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

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

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

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

function main() {
    var t = parseInt(readline());

    for (let i = 0; i < t; i++) {
        var x = readline().split(' ');
        var n = parseInt(x[0]);
        var m = parseInt(x[1]);

        var a = [];
        var I = 0, J = 0, maxf = 0;
        for (let j = 0; j < n; j++) {
            a[j] = readline().split(' ');
            var max = 0;
            var J_ = 0;
            for (let k = 0; k < m; k++) {
                a[j][k] = parseInt(a[j][k]);
                if (max < a[j][k]) {
                    max = a[j][k];
                    J_ = k;
                }
            }

            if (max > maxf) {
                maxf = max;
                I = j;
                J = J_;
            }
        }

        var h = Math.max(I+1, n-I);
        var w = Math.max(J+1, m-J);

        console.log(h*w);
    }
}


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

		let sm = 0;
		for (const x of b) {
			sm += x;
		}

		const d = n*(n+1)/2
		if (sm%d) {
			console.log('NO');
			continue;
		}

		sm /= d;

		let ans = [];
		for (let i = 0; i < n; i++) {
			ans[i] = (b[(i+n-1)%n]-(b[i]-sm))/n;
			if (ans[i] <= 0 || ans[i]%1) {
				ans = false;
				break;
			}
		}

		console.log(ans ? 'YES\n' + ans.join(' ') : 'NO');
	}
}

var t = parseInt(readline());

  function solve() {
    var n = parseInt(readline());
    var a = readline()
      .split(" ")
      .map((data) => +data);
    var ans = [];
    var total = 0;
    for (var i = 0; i < n; i++) {
      total += a[i];
    }
    var sum = (n * (n + 1)) / 2;
    if (total % sum) {
      print("NO");
      return;
    }
    total /= sum;
    for (var i = 0; i < n; i++) {
      var diff = a[i] - a[(n - 1 + i) % n];
      diff = total - diff;
      if (diff <= 0 || diff % n) {
        print("NO");
        return;
      }
      diff /= n;
      ans[i] = diff;
    }
    print("YES");
    var an = "";
    for (var i of ans) {
      an += i + " ";
    }
    print(an);
  }

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

'use strict';

function solve(n, a) {
  const res = [];
  let sum = a.reduce((a, b) => a + b, 0);
  if (sum % (n * (n + 1) / 2) !== 0) return 'NO';
  sum /= n * (n + 1) / 2;
  for (let i = 0; i < n; i++) {
    res[i] = sum - (a[i] - a[(i - 1 + n) % n]);
    if (res[i] % n !== 0) return 'NO';
    if (res[i] <= 0) return 'NO';
    res[i] /= n;
  }
  return `YES\n${res.join(' ')}`;
}

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());
      const a = (await read()).split(' ').map(Number);
      res[i] = solve(n, 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);
});

"use strict";

function matprint(mat) {
  let shape = [mat.length, mat[0].length];
  function col(mat, i) {
    return mat.map((row) => row[i]);
  }
  let colMaxes = [];
  for (let i = 0; i < shape[1]; i++) {
    colMaxes.push(
      Math.max.apply(
        null,
        col(mat, i).map((n) => n.toString().length)
      )
    );
  }

  mat.forEach((row) => {
    console.log.apply(
      null,
      row.map((val, j) => {
        return new Array(colMaxes[j] - val.toString().length + 1).join(" ") + val.toString() + "  ";
      })
    );
  });
}

const nQueues = this.readline().split(" ");

// For this problem we will apply Gauss elimination algorithm

for (let i = 0; i < nQueues; i++) {
  const n = Number(this.readline());
  const minutes = this.readline()
    .split(" ")
    .map((e) => Number(e));
  const sum = minutes.reduce((prev, curr) => prev + curr, 0);
  const totalRep = (n * (n + 1)) / 2;

  if (sum % totalRep) {
    this.print("NO");
    continue;
  }

  const ans = new Array(n);

  let fail = false;
  for (let x = 0; x < n; x++) {
    ans[x] = (minutes[(n - 1 + x) % n] - minutes[x] + sum / totalRep) / n;

    if (ans[x] <= 0 || Math.abs(ans[x] - Math.round(ans[x])) > 0.0000001) {
      this.print("NO");
      fail = true;
      break;
    }
  }

  if (!fail) {
    this.print("YES");
    this.print(ans.join(" "));
  }
}

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

		let sm = 0;
		for (const x of b) {
			sm += x;
		}

		const d = n*(n+1)/2
		if (sm%d) {
			console.log('NO');
			continue;
		}

		sm /= d;

		let ans = [];
		for (let i = 0; i < n; i++) {
			ans[i] = (b[(i+n-1)%n]-(b[i]-sm))/n;
			if (ans[i] <= 0) {
				ans = false;
				break;
			}
		}

		console.log(ans ? 'YES\n' + ans.join(' ') : 'NO');
	}
}

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

		let sm = 0;
		for (const x of b) {
			sm += x;
		}

		const d = n*(n+1)/2
		if (sm%d) {
			console.log('NO');
			return;
		}

		sm /= d;

		let ans = [];
		for (let i = 0; i < n; i++) {
			ans[i] = (b[(i+n-1)%n]-(b[i]-sm))/n;
			if (ans[i] <= 0 || ans[i] > n) {
				ans = false;
				break;
			}
		}

		console.log(ans ? 'YES\n' + ans.join(' ') : 'NO');
	}
}

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

		let sm = 0;
		for (const x of b) {
			sm += x;
		}

		sm = 2*sm/(n*(n+1));

		let ans = [];
		for (let i = 0; i < n; i++) {
			ans[i] = (b[(i+n-1)%n]-(b[i]-sm))/n;
			if (ans[i] <= 0 || ans[i] > n) {
				ans = false;
				break;
			}
		}

		console.log(ans ? 'YES\n' + ans.join(' ') : 'NO');
	}
}

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

		let sm = 0;
		for (const x of b) {
			sm += x;
		}

		sm = 2*sm/(n*(n+1));

		let ans = [];
		for (let i = 0; i < n; i++) {
			ans[i] = (b[(i+n-1)%n]-(b[i]-sm))/n;
			if (ans[i] == 0) {
				ans = false;
				break;
			}
		}

		console.log(ans ? 'YES\n' + ans.join(' ') : 'NO');
	}
}

"use strict";

function matprint(mat) {
  let shape = [mat.length, mat[0].length];
  function col(mat, i) {
    return mat.map((row) => row[i]);
  }
  let colMaxes = [];
  for (let i = 0; i < shape[1]; i++) {
    colMaxes.push(
      Math.max.apply(
        null,
        col(mat, i).map((n) => n.toString().length)
      )
    );
  }

  mat.forEach((row) => {
    console.log.apply(
      null,
      row.map((val, j) => {
        return new Array(colMaxes[j] - val.toString().length + 1).join(" ") + val.toString() + "  ";
      })
    );
  });
}

const nQueues = this.readline().split(" ");

// For this problem we will apply Gauss elimination algorithm

for (let i = 0; i < nQueues; i++) {
  const n = Number(this.readline());
  const minutes = this.readline()
    .split(" ")
    .map((e) => Number(e));

  const matrix = [];
  /* generate matrix with the coefficient of the repertoire for each singer
   * For 6 cities, it'll look like this:
      1   6   5   4   3   2   81
      2   1   6   5   4   3   75
      3   2   1   6   5   4   75
      4   3   2   1   6   5   93
      5   4   3   2   1   6   93
      6   5   4   3   2   1   87
   */
  for (let city = 0; city < n; city++) {
    matrix[city] = [];
    for (let singer = 0; singer < n; singer++) {
      matrix[city][singer] = 1 + ((city + (n - singer)) % n);
    }
    matrix[city].push(minutes[city]);
  }

  /* Now, we will get the matrix to echelon form, that is, something like this
    1   6                     5                    4                     3                      2                   81
    0   1   0.36363636363636365   0.2727272727272727   0.18181818181818182    0.09090909090909091    7.909090909090909
    0   0                     1                  0.2    0.1333333333333333    0.06666666666666671   5.0666666666666655
    0   0                     0                    1    0.1111111111111111   0.055555555555555476   1.7222222222222239
    0   0                     0                    0                     1    0.05000000000000005    4.249999999999998
    0   0                     0                    0                     0                      1   5.0000000000000036

    which will help us isolate each variable
  */
  for (let a = 0; a < n; a++) {
    const factor1 = matrix[a][a];
    for (let col = a; col <= n; col++) {
      matrix[a][col] = matrix[a][col] / factor1;
    }
    for (let lin = a + 1; lin < n; lin++) {
      const factor2 = matrix[lin][a];
      for (let col = a; col <= n; col++) {
        matrix[lin][col] = matrix[lin][col] / factor2 - matrix[a][col];
      }
    }
  }

  /* Now we start from the bottom and subtract for each equation the free variables, which will give us something like this
    (rounding is actually done later, but I've done here just for clarity)
      1   0   0   0   0   0   5
      0   1   0   0   0   0   5
      0   0   1   0   0   0   4
      0   0   0   1   0   0   1
      0   0   0   0   1   0   4
      0   0   0   0   0   1   5

      Which makes it trivial to find the values of each variable
  */
  for (let a = n - 1; a >= 0; a--) {
    for (let lin = a - 1; lin >= 0; lin--) {
      const factor = matrix[lin][a];
      for (let col = n; col >= a; col--) {
        matrix[lin][col] = matrix[lin][col] - factor * matrix[a][col];
      }
    }
  }

  const vars = [];
  for (let a = 0; a < n; a++) {
    if (matrix[a][n] <= 0) {
      // repertoires must have positive duration
      this.print("NO");
      break;
    }
    if (matrix[a][n] - Math.round(matrix[a][n]) > 0.000001) {
      // not an integer
      this.print("NO");
      break;
    }
    vars.push(Math.round(matrix[a][n]));
  }
  if (vars.length === n) {
    this.print("YES");
    this.print(vars.join(" "));
  }
}

"use strict";

function matprint(mat) {
  let shape = [mat.length, mat[0].length];
  function col(mat, i) {
    return mat.map((row) => row[i]);
  }
  let colMaxes = [];
  for (let i = 0; i < shape[1]; i++) {
    colMaxes.push(
      Math.max.apply(
        null,
        col(mat, i).map((n) => n.toString().length)
      )
    );
  }

  mat.forEach((row) => {
    console.log.apply(
      null,
      row.map((val, j) => {
        return new Array(colMaxes[j] - val.toString().length + 1).join(" ") + val.toString() + "  ";
      })
    );
  });
}

const nQueues = this.readline().split(" ");

// For this problem we will apply Gauss elimination algorithm

for (let i = 0; i < nQueues; i++) {
  const n = Number(this.readline());
  const minutes = this.readline()
    .split(" ")
    .map((e) => Number(e));

  const matrix = [];
  /* generate matrix with the coefficient of the repertoire for each singer
   * For 6 cities, it'll look like this:
      1   6   5   4   3   2   81
      2   1   6   5   4   3   75
      3   2   1   6   5   4   75
      4   3   2   1   6   5   93
      5   4   3   2   1   6   93
      6   5   4   3   2   1   87
   */
  for (let city = 0; city < n; city++) {
    matrix[city] = [];
    for (let singer = 0; singer < n; singer++) {
      matrix[city][singer] = 1 + ((city + (n - singer)) % n);
    }
    matrix[city].push(minutes[city]);
  }

  /* Now, we will get the matrix to echelon form, that is, something like this
    1   6                     5                    4                     3                      2                   81
    0   1   0.36363636363636365   0.2727272727272727   0.18181818181818182    0.09090909090909091    7.909090909090909
    0   0                     1                  0.2    0.1333333333333333    0.06666666666666671   5.0666666666666655
    0   0                     0                    1    0.1111111111111111   0.055555555555555476   1.7222222222222239
    0   0                     0                    0                     1    0.05000000000000005    4.249999999999998
    0   0                     0                    0                     0                      1   5.0000000000000036

    which will help us isolate each variable
  */
  for (let a = 0; a < n; a++) {
    const factor1 = matrix[a][a];
    for (let col = a; col <= n; col++) {
      matrix[a][col] = matrix[a][col] / factor1;
    }
    for (let lin = a + 1; lin < n; lin++) {
      const factor2 = matrix[lin][a];
      for (let col = a; col <= n; col++) {
        matrix[lin][col] = matrix[lin][col] / factor2 - matrix[a][col];
      }
    }
  }

  /* Now we start from the bottom and subtract for each equation the free variables, which will give us something like this
    (rounding is actually done later, but I've done here just for clarity)
      1   0   0   0   0   0   5
      0   1   0   0   0   0   5
      0   0   1   0   0   0   4
      0   0   0   1   0   0   1
      0   0   0   0   1   0   4
      0   0   0   0   0   1   5

      Which makes it trivial to find the values of each variable
  */
  for (let a = n - 1; a >= 0; a--) {
    for (let lin = a - 1; lin >= 0; lin--) {
      const factor = matrix[lin][a];
      for (let col = n; col >= a; col--) {
        matrix[lin][col] = matrix[lin][col] - factor * matrix[a][col];
      }
    }
  }

  const vars = [];
  for (let a = 0; a < n; a++) {
    if (matrix[a][n] <= 0) {
      // repertoires must have positive duration
      this.print("NO");
      break;
    }
    if (matrix[a][n] - Math.round(matrix[a][n]) > 0.1) {
      // not an integer
      this.print("NO");
      break;
    }
    vars.push(Math.round(matrix[a][n]));
  }
  if (vars.length === n) {
    this.print("YES");
    this.print(vars.join(" "));
  }
}

"use strict";

function matprint(mat) {
  let shape = [mat.length, mat[0].length];
  function col(mat, i) {
    return mat.map((row) => row[i]);
  }
  let colMaxes = [];
  for (let i = 0; i < shape[1]; i++) {
    colMaxes.push(
      Math.max.apply(
        null,
        col(mat, i).map((n) => n.toString().length)
      )
    );
  }

  mat.forEach((row) => {
    console.log.apply(
      null,
      row.map((val, j) => {
        return new Array(colMaxes[j] - val.toString().length + 1).join(" ") + val.toString() + "  ";
      })
    );
  });
}

const nQueues = this.readline().split(" ");

for (let i = 0; i < nQueues; i++) {
  const n = Number(this.readline());
  const minutes = this.readline()
    .split(" ")
    .map((e) => Number(e));

  const matrix = [];
  for (let city = 0; city < n; city++) {
    matrix[city] = [];
    for (let singer = 0; singer < n; singer++) {
      matrix[city][singer] = 1 + ((city + (n - singer)) % n);
    }
    matrix[city].push(minutes[city]);
  }

  for (let a = 0; a < n; a++) {
    const f1 = matrix[a][a];
    for (let col = a; col <= n; col++) {
      matrix[a][col] = matrix[a][col] / f1;
    }
    for (let lin = a + 1; lin < n; lin++) {
      const f2 = matrix[lin][a];
      for (let col = a; col <= n; col++) {
        matrix[lin][col] = matrix[lin][col] - f2 * matrix[a][col];
      }
    }
  }

  for (let a = n - 1; a >= 0; a--) {
    for (let lin = a - 1; lin >= 0; lin--) {
      const fator = matrix[lin][a];
      for (let col = n; col >= a; col--) {
        matrix[lin][col] = matrix[lin][col] - fator * matrix[a][col];
      }
    }
  }

  const vars = [];
  for (let a = 0; a < n; a++) {
    if (matrix[a][n] <= 0) {
      this.print("NO");
      break;
    }
    vars.push(Math.round(matrix[a][n]));
  }
  if (vars.length === n) {
    this.print("YES");
    this.print(vars.join(" "));
  }
}


;(function () {

	print((+readline().slice(-2)) % 4 ? 0 : 4);

}).call(this);

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

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

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

function main() {
	var s = trim(readline()),
		n = parseInt(s.substring(s.length-2)),
		two = [1, 2, 4, 3][n%4],
		three = [1, 3, 4, 2][n%4],
		four = [1, 4][n%2];
	print((1 + two + three + four) % 5);
}

main();