nk = readline().split(" ").map(Number)
n = nk[0]
k = nk[1]
a=readline().split(" ").map(Number)

st=1
end=1000000000
while (st<=end) {
    mid=(st+end)>>1
    ct=0;i=1;pos=n
    if (k%2!==0) pos-=1
    while (i<pos) {
        if (a[i]<=mid) {
            ct+=1
            i+=1
        }
        i+=1
    }
    if (ct>=k>>1) {
        end=mid-1
        continue;
    }
    ct=0;i=0;pos=n
    if (k%2===0) pos-=1
    while (i<pos) {
        if(a[i]<=mid) {
            ct+=1
            i+=1
        }
        i+=1
    }
    if (ct>=(k+1)>>1) {
        end=mid-1
        continue;
    }
    st=mid+1
}
print (end+1)

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var input = '';
process.stdin.on('data', function (line) {
    input += line;
});
process.stdin.on('end', function () {
    var lines = input.split('\n');
    var _a = lineToNumArray(lines.shift()), n = _a[0], k = _a[1];
    var arr = lineToNumArray(lines.shift());
    console.log(Math.min(binarySearch(n, k, arr, 0), binarySearch(n, k, arr, 1)));
});
function binarySearch(n, k, arr, parity) {
    var lo = 1, hi = Math.max.apply(Math, arr);
    var ans;
    while (lo <= hi) {
        var mid = Math.floor((lo + hi) / 2);
        var count = 0;
        for (var i = 0; i < n && count < k; i++) {
            if (count % 2 === parity) {
                count += Number(arr[i] <= mid);
            }
            else {
                count++;
            }
        }
        if (count === k) {
            ans = mid;
            hi = mid - 1;
        }
        else {
            lo = mid + 1;
        }
    }
    return ans;
}
// input helper
function lineToNumArray(line) {
    return line.split(' ').map(function (element) { return parseInt(element, 10); });
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let input = '';
process.stdin.on('data', (line) => {
    input += line;
});
process.stdin.on('end', () => {
    const lines = input.split('\n');
    const [n, k] = lineToNumArray(lines.shift());
    const arr = lineToNumArray(lines.shift());
    console.log(Math.min(binarySearch(n, k, arr, 0), binarySearch(n, k, arr, 1)));
});
function binarySearch(n, k, arr, parity) {
    let lo = 1, hi = Math.max(...arr);
    let ans;
    while (lo <= hi) {
        const mid = Math.floor((lo + hi) / 2);
        let count = 0;
        for (let i = 0; i < n && count < k; i++) {
            if (count % 2 === parity) {
                count += Number(arr[i] <= mid);
            }
            else {
                count++;
            }
        }
        if (count === k) {
            ans = mid;
            hi = mid - 1;
        }
        else {
            lo = mid + 1;
        }
    }
    return ans;
}
// input helper
function lineToNumArray(line) {
    return line.split(' ').map(element => parseInt(element, 10));
}

nk = readline().split(" ").map(Number);
n = nk[0];
k = nk[1];
a=readline().split(" ").map(Number);

st=1
end=100000000
while (st<=end) {
    mid=(st+end)>>1
    ct=0;i=1;pos=n
    if (k%2!==0) pos-=1
    while (i<pos) {
        if (a[i]<=mid) {
            ct+=1
            i+=1
        }
        i+=1
    }
    if (ct>=k/2) {
        end=mid-1
        continue;
    }
    ct=0;i=0;pos=n
    if (k%2===0) pos-=1
    while (i<pos) {
        if(a[i]<=mid) {
            ct+=1
            i+=1
        }
        i+=1
    }
    if (ct>=(k+1)/2) {
        end=mid-1
        continue;
    }
    st=mid+1
}
print (end+1)

nk = readline().split(" ").map(Number)
n = nk[0]
k = nk[1]
a=readline().split(" ").map(Number)

st=1
end=1000000000
while (st<=end) {
    mid=(st+end)>>1
    ct=0;i=1;pos=n
    if (k%2!==0) pos-=1
    while (i<pos) {
        if (a[i]<=mid) {
            ct+=1
            i+=1
        }
        i+=1
    }
    if (ct>=k/2) {
        end=mid-1
        continue;
    }
    ct=0;i=0;pos=n
    if (k%2===0) pos-=1
    while (i<pos) {
        if(a[i]<=mid) {
            ct+=1
            i+=1
        }
        i+=1
    }
    if (ct>=(k+1)>>1) {
        end=mid-1
        continue;
    }
    st=mid+1
}
print (end+1)


var n=parseInt(readline())
var a=readline().split(" ").map(x=>parseInt(x))
var s=new Set()
s.add(0)
var chk=0
var cnt=1;
for(x of a){
    if(s.has(x) || s.has(x-1)){
        cnt+=1;
        s.add(x);
    }
    else{
        chk=1;
        break;
    }
}
if (a[0]!=0) print(1)
else if (chk==0) print(-1)
else print(cnt)

const readline = require('readline');

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

const appnedMex = (length, result) => {
  let max = 0;
  for (let i = 0; i < length; i++) {
    if (result[i] > max) {
      return i + 1;
    }
    if ( max == result[i] )
      max += 1;
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.split(' ');
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

var m = readline(),
    arr = readline().split(' '),
    flag = 1,
    max = -1;
for(var i = 0; i < m; i++) {
    var newMax = Math.max(max, arr[i]);
    if(newMax - max > 1) {
        write(i + 1);
        flag = 0;
        break;
    }
    max = newMax;
}
if(flag) {
    write(-1);
}

const readline = require('readline');

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

const appnedMex = (length, result) => {
  for (let i = 0; i < length; i++) {
    if (result[i] >= i+1 ) {
      console.log(result[i]);
      return i + 1;
    }
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.split(' ');
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

const readline = require('readline');

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

const appnedMex = (length, result) => {
  for (let i = 0; i < length; i++) {
    if (result[i] > i || result[i] > result[i-1] + 1) {
      return i + 1;
    }
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.split(' ');
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

const readline = require('readline');

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

const appnedMex = (length, result) => {
  for (let i = 0; i < length; i++) {
    if (result[i] > i+1 ) {
      return i + 1;
    }
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.split(' ');
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

const readline = require('readline');

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

const appnedMex = (length, result) => {
  for (let i = 0; i < length; i++) {
    if (result[i] >= i+1 ) {
      if ( i > 4000) {
        console.log(result[i]);
      }
      return i + 1;
    }
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.split(' ');
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

const readline = require('readline');

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

const appnedMex = (length, result) => {
  for (let i = 0; i < length; i++) {
    if (result[i] >= i+2 ) {
      return i + 1;
    }
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.split(' ');
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

const readline = require('readline');

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

const appnedMex = (length, result) => {
  let naj = 0;
  for (let i = 0; i < length; i++) {
    if (result[i] > naj ) {
      return i + 1;
    }
    naj = Math.max(naj, result[i] + 1);
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.trim();
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

const readline = require('readline');

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

const appnedMex = (length, result) => {
  for (let i = 0; i < length; i++) {
    if ( i == 42230 || i == 42231 ) {
      console.log(result[i]);
    }
    if (result[i] >= i+1 ) {
      return i + 1;
    }
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.split(' ');
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

const readline = require('readline');

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

const appnedMex = (length, result) => {
  let max = 0;
  for (let i = 0; i < length; i++) {
    if (result[i] > max) {
      return i + 1;
    }
    max = Math.max(max, result[i] + 1);
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.split(' ');
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

const readline = require('readline');

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

const appnedMex = (length, result) => {
  for (let i = 0; i < length; i++) {
    if (result[i] > i && result[i] > result[i-1] + 1) {
      return i + 1;
    }
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.split(' ');
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

const readline = require('readline');

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

const appnedMex = (length, result) => {
  for (let i = 0; i < length; i++) {
    if (result[i] >= i+1 ) {
      return i + 1;
    }
  }
  return -1;
}

let length, result;

rl.on('line', (line) => {
  if (!length) {
    length = line;
  } else {
    result = line.split(' ');
    console.log(appnedMex(length, result));
    rl.close();
    process.exit();
  }
});

var n=parseInt(readline())
var a=readline().split(" ").map(x=>parseInt(x))
var s=new Set()
s.add(0)
var chk=0
var cnt=1;
for(x of a){
    if(s.has(x) || s.has(x-1)){
        cnt+=1;
    }
    else{
        chk=1;
        break;
    }
}
if (a[0]!=0) print(1)
else if (chk==0) print(-1)
else print(cnt+1)

var m = readline(),
    arr = readline().split(' '),
    flag = 1;
for(var i = 0; i < m; i++) {
    if(arr[i] > i) {
        write(i + 1);
        flag = 0;
        break;
    }
}
if(flag) {
    write(-1);
}


'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const s = read();
  const n = s.length;
  const map = new Map();
  for (let i = 0; i < n; i++) {
    var _map$get;
    if (!map.has(s[i])) map.set(s[i], []);
    (_map$get = map.get(s[i])) === null || _map$get === void 0 ? void 0 : _map$get.push(i);
  }
  let flag = 1;
  if (s[0] > s[n - 1]) {
    flag = -1;
  }
  let res = [],
      d = 0,
      p = s.charCodeAt(0);
  for (let i = p; flag > 0 ? i <= s.charCodeAt(n - 1) : i >= s.charCodeAt(n - 1); i += flag) {
    const ch = String.fromCharCode(i);
    if (map.has(ch)) {
      d += Math.abs(i - p);
      p = i;
      for (let j of map.get(ch)) {
        res.push(j);
      }
    }
  }
  return `${d} ${res.length}\n${res.map(num => num + 1).join(' ')}`;
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split(/\r\n?/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

const readline = require('readline')

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

function solve(str) {
    let a = str[0]
    let b = str[str.length - 1]
    let f = 0
    if (a > b) {
        [a, b] = [b, a]
        f = 1
    }
    const r = []
    for (let i = 1; i < str.length - 1; i++) {
        if (str[i] >= a && str[i] <= b) {
            r.push(i + 1)
        }
    }
    r.sort((p, q) => str.charCodeAt(p - 1) - str.charCodeAt(q - 1))
    if (f) r.reverse()
    r.unshift(1)
    r.push(str.length)
    const cost = b.charCodeAt(0) - a.charCodeAt(0)
    return cost + ' ' + r.length + '\n' + r.join(' ')
}

var t = +readline()

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

    var line = readline()

    var nums = []
    var pos = {}
    for (var j=1; j<line.length-1; j++) {

        var n = line.charCodeAt(j) - 96
        nums.push(n)
        if (pos[n] === undefined)
            pos[n] = [j+1]
        else
            pos[n].push(j+1)
    }

    var head = line.charCodeAt(0)-96
    var tail = line.charCodeAt(line.length-1)-96

    var min_cost = Math.abs(head-tail)

    nums = nums.sort((a, b) => { return a-b })

    var mode = 1
    if (head>tail) mode = 2

    var max_step = 0
    var ret = []
    //for (var k=0; k<nums.length; k++) {
    for (var k=1; k<=26; k++) {
        if (!pos[k]) continue
        if (k >= Math.min(head, tail) && k <= Math.max(head, tail)) {

            max_step = max_step + pos[k].length

            //var kk = pos[nums[k]].shift()
            //if (kk > 1 && kk < nums.length) ret.push(kk)
            ret = ret.concat(pos[k])
        }
    }

    if (mode == 2) {
        ret = ret.reverse()
    }
    max_step = max_step + 2
    print(min_cost + " " +max_step)
    ret.unshift(1)
    //ret.push(nums.length)
    ret.push(nums.length+2)
    print(ret.join(" "))

}

'use strict';

var fs = require('fs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);

function solve(read) {
  const s = read();
  const n = s.length;
  const map = new Map();
  for (let i = 0; i < n; i++) {
    var _map$get;
    if (!map.has(s[i])) map.set(s[i], []);
    (_map$get = map.get(s[i])) === null || _map$get === void 0 ? void 0 : _map$get.push(i);
  }
  let flag = 1;
  if (s[0] > s[n - 1]) {
    flag = -1;
  }
  let res = [],
      d = 0,
      p = s.charCodeAt(0);
  for (let i = p; flag > 0 ? i <= s.charCodeAt(n - 1) : i >= s.charCodeAt(n - 1); i += flag) {
    const ch = String.fromCharCode(i);
    if (map.has(ch)) {
      d += Math.abs(i - p);
      p = i;
      for (let j of map.get(ch)) {
        res.push(j);
      }
    }
  }
  return `${d} ${res.length}\n${res.map(num => num + 1).join(' ')}`;
}

function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < 100) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= 100) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

const inputs = fs__default["default"].readFileSync(0, 'utf-8').split('\n');
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

const readline = require('readline')

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

function solve(str) {
    let a = str[0]
    let b = str[str.length - 1]
    if (a > b) {
        [a, b] = [b, a]
    }
    const r = []
    for (let i = 1; i < str.length - 1; i++) {
        if (str[i] >= a && str[i] <= b) {
            r.push(i + 1)
        }
    }
    r.sort((p, q) => str.charCodeAt(p - 1) - str.charCodeAt(q - 1))
    r.unshift(1)
    r.push(str.length)
    const cost = b.charCodeAt(0) - a.charCodeAt(0)
    return cost + ' ' + r.length + '\n' + r.join(' ')
}

var t = +readline()

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

    var line = readline()

    var nums = []
    var pos = {}
    for (var j=1; j<line.length-1; j++) {

        var n = line.charCodeAt(j) - 96
        nums.push(n)
        if (pos[n] === undefined)
            pos[n] = [j+1]
        else
            pos[n].push(j+1)
    }

    var head = line.charCodeAt(0)-96
    var tail = line.charCodeAt(line.length-1)-96

    var min_cost = Math.abs(head-tail)

    nums = nums.sort((a, b) => { return a-b })

    var mode = 1
    if (head>tail) mode = 2

    var max_step = 0
    var ret = []
    //for (var k=0; k<nums.length; k++) {
    for (var k=1; k<=26; k++) {
        if (!pos[k]) continue
        if (k >= Math.min(head, tail) && k <= Math.max(head, tail)) {

            max_step++

            //var kk = pos[nums[k]].shift()
            //if (kk > 1 && kk < nums.length) ret.push(kk)
            ret = ret.concat(pos[k])
        }
    }

    if (mode == 2) {
        ret = ret.reverse()
    }
    max_step = max_step + 2
    print(min_cost + " " +max_step)
    ret.unshift(1)
    //ret.push(nums.length)
    ret.push(nums.length+2)
    print(ret.join(" "))

}

var t = +readline()

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

    var line = readline()

    var nums = []
    var pos = {}
    for (var j=1; j<line.length-1; j++) {

        var n = line.charCodeAt(j) - 96
        nums.push(n)
        if (pos[n] === undefined)
            pos[n] = [j+1]
        else
            pos[n].push(j+1)
    }

    var head = line.charCodeAt(0)-96
    var tail = line.charCodeAt(line.length-1)-96

    var min_cost = Math.abs(head-tail)

    nums = nums.sort((a, b) => { return a-b })

    var mode = 1
    if (head>tail) mode = 2

    var max_step = 0
    var ret = []
    for (var k=0; k<nums.length; k++) {
        if (nums[k] >= Math.min(head, tail) && nums[k] <= Math.max(head, tail)) {

            max_step++

            //var kk = pos[nums[k]].shift()
            //if (kk > 1 && kk < nums.length) ret.push(kk)
            ret = ret.concat(pos[nums[k]])
        }
    }

    if (mode == 2) {
        ret = ret.reverse()
    }
    max_step = max_step + 2
    print(min_cost + " " +max_step)
    ret.unshift(1)
    //ret.push(nums.length)
    ret.push(nums.length+2)
    print(ret.join(" "))

}

var t = +readline()

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

    var line = readline()

    var nums = []
    var pos = {}
    for (var j=0; j<line.length; j++) {
        var n = line.charCodeAt(j) - 96
        nums.push(n)
        if (pos[n] === undefined)
            pos[n] = [j+1]
        else
            pos[n].push(j+1)
    }

    //for (var p in pos) {
        //print("p="+p)
        //print("pos[p]=" + pos[p])
    //}

    var head = nums[0]
    var tail = nums[nums.length - 1]
    var min_cost = Math.abs(head-tail)

    nums = nums.sort((a, b) => { return a-b })
    //print(head)
    //print(tail)

    var mode = 1
    if (head>tail) mode = 2

    var max_step = 0
    var ret = []
    for (var k=0; k<nums.length; k++) {
        //print(nums[k])
        if (nums[k] >= Math.min(head, tail) && nums[k] <= Math.max(head, tail)) {

            max_step++
            //print("max_step="+max_step )

            //print("seq = " + pos[nums[k]].shift())
            ret.push(pos[nums[k]].shift())
        }
    }

    //reverse ret
    if (mode == 2) {
        ret = ret.reverse()
    }

    //print ("min=" + min_cost)
    //print ("max=" + max_step)
    //print ("ret = "+ ret)

    print(min_cost + " " + max_step)
    print(ret.join(" "))
}

var t = +readline()

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

    var line = readline()

    var nums = []
    for (var j=0; j<line.length; j++) {
        var n = line.charCodeAt(j) - 97
        nums.push(n)
    }

    nums = nums.sort((a, b) => { return b-a })
    print (nums)
    //print("answer")
}


'use strict';

function solve(n, m, k) {
  const dp = Array.from({
    length: n
  }, () => new Array(m).fill(Infinity));
  dp[0][0] = 0;
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < m; j++) {
      if (i === 0 && j === 0) continue;
      if (i > 0) dp[i][j] = Math.min(dp[i][j], dp[i - 1][j] + j + 1);
      if (j > 0) dp[i][j] = Math.min(dp[i][j], dp[i][j - 1] + i + 1);
    }
  }
  return dp[n - 1][m - 1] === k ? 'YES' : 'NO';
}

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

    var t = readline();
    for(var i = 0 ; i < t ; i++){
        var inputs = readline().split(' '),
            n = inputs[0],
            m = inputs[1],
            k = inputs[2] ;
            if((n*m) - 1 == k){
                print("YES");
            }
            else{
                print("NO");
            }

    }

(function () {
    const count = readline();
    const n = Number(count);

    var i;
    for (i = 0; i < n; i++) {
        var line = readline();
        var items = line.split(' ');
        var x = Number(items[0]) - 1;
        var y = Number(items[1]) - 1;
        var j;
        var k;
        var c = 0;
        var result = 'No';
        for (j = 1; j <= x; j++) {
            c += 1;
        }
        for (k = 1; k <= y; k++) {
            c += Number(items[0]);
        }
        if (c === Number(items[2])) {
            result = 'Yes';
        }

        print(result);
    }
})();

/* 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() {
    const length = Number(readline());
    for (let i = 0; i < length; i++) {
        const [x, y, budget] = readline().split(' ').map(e => Number(e));
        if(x * y - 1 === budget) {
            console.log('YES')
        }
        else {
            console.log('NO')
        }
    }
    return;
}

'use strict';

function solve(n, m, k) {
  let res = 0;
  for (let i = 1; i < n; i++) res += 1;
  for (let i = 1; i < m; i++) res += n;
  return res === k ? 'YES' : 'NO';
}

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

/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
var __webpack_exports__ = {};

;// CONCATENATED MODULE: ./src/io.js
var interact = function interact(main) {
  process.stdin.resume();
  process.stdin.setEncoding('utf-8');
  var inputString = '';
  var currentLine = 0;

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

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

    process.stdout.write(any.join(' '));
  };

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

    any.length > 0 && print(any);
    print('\n');
  };

  var obj = {
    print: print,
    println: println,
    readline: readline
  };
  process.stdin.on('data', function (inputStdin) {
    inputString += inputStdin;
  });
  process.stdin.on('end', function () {
    inputString = inputString.trim().split('\n').map(function (string) {
      return string.trim();
    });
    main(obj);
  });
};

/* harmony default export */ const io = (interact);
;// CONCATENATED MODULE: ./src/index.js
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; 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"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var main = function main(io) {
  var tc = parseInt(io.readline());

  var _loop = function _loop() {
    var _io$readline$split$ma = io.readline().split(' ').map(function (x) {
      return parseInt(x);
    }),
        _io$readline$split$ma2 = _slicedToArray(_io$readline$split$ma, 3),
        n = _io$readline$split$ma2[0],
        m = _io$readline$split$ma2[1],
        k = _io$readline$split$ma2[2];

    var dp = Array.from(Array(1 + n), function () {
      return Array.from(Array(1 + m), function () {
        return Infinity;
      });
    }); // from (1,1) it is possible to use exactly
    // 0 burles to reach (1,1)

    dp[1][1] = 0;

    for (var i = 1; i <= n; i++) {
      for (var j = 1; j <= m; j++) {
        dp[i][j] = Math.min(dp[i][j], j + dp[i - 1][j], i + dp[i][j - 1]);
      }
    }

    io.println(dp[n][m] === k ? 'YES' : 'NO');
  };

  while (tc--) {
    _loop();
  }
};

io(main);
/******/ })()
;

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

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

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

let nl = nextLine();

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

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

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

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

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

const sol = () => {
	//your code this
	let t = nl.num();
	let ans = [];
	for(let i = 0; i < t; i++){
		let [n, m, k] = nl.nums();
		ans.push((n * m - 1) === k);
	}
	console.log(ans.map(e => e?"YES":"NO").join('\n'));
};

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

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

//Don't have to see. end------------------------------------------

function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var H = nextInt();
		var W = nextInt();
		var K = nextInt();
		if(H * W - 1 == K){
			myout("YES");
		}else{
			myout("NO");
		}
	}
}

'use-strict'

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

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(readLine());

    while(testCases--)
    {
        let [n,m,k] = get_ints();
        let [x,y] = [1,1];
        let burles = 0;
        while(x < n)
        {
            burles += y;
            x++;
        }
        while(y < m)
        {
            burles += x;
            y++;
        }
        burles === k ? print('YES') : print('NO');
    }
});

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

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

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

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

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

let count = -1
let inputArr = []

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

function solve([n, m, k]) {
    let a = n - 1 + (n * (m - 1));
    (a === k) ? console.log('YES') : console.log('NO')
}

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

/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ({

/***/ 747:
/***/ ((module) => {

module.exports = require("fs");;

/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/
/************************************************************************/
/******/ 	/* webpack/runtime/compat get default export */
/******/ 	(() => {
/******/ 		// getDefaultExport function for compatibility with non-harmony modules
/******/ 		__webpack_require__.n = (module) => {
/******/ 			var getter = module && module.__esModule ?
/******/ 				() => (module['default']) :
/******/ 				() => (module);
/******/ 			__webpack_require__.d(getter, { a: getter });
/******/ 			return getter;
/******/ 		};
/******/ 	})();
/******/
/******/ 	/* webpack/runtime/define property getters */
/******/ 	(() => {
/******/ 		// define getter functions for harmony exports
/******/ 		__webpack_require__.d = (exports, definition) => {
/******/ 			for(var key in definition) {
/******/ 				if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ 					Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ 				}
/******/ 			}
/******/ 		};
/******/ 	})();
/******/
/******/ 	/* webpack/runtime/hasOwnProperty shorthand */
/******/ 	(() => {
/******/ 		__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ 	})();
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {

// EXTERNAL MODULE: external "fs"
var external_fs_ = __webpack_require__(747);
var external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_);
;// CONCATENATED MODULE: external "readline"
const external_readline_namespaceObject = require("readline");;
;// CONCATENATED MODULE: ./src/lib/io.ts

class InteractiveIO {
  constructor() {
    this.rl = void 0;
    this.lines = [];
    this.rl = readline.createInterface({
      input: process.stdin,
      output: process.stdout
    });
    this.rl.on('line', line => {
      this.lines.push(line);
    });
  }

  nextLine() {
    return new Promise((resolve, reject) => {
      if (this.lines.length) {
        resolve(this.lines.shift());
        return;
      }

      let waitId = null;
      let timeoutId = null;
      waitId = setInterval(() => {
        if (this.lines.length) {
          resolve(this.lines.shift());
          clearTimeout(timeoutId);
          clearInterval(waitId);
          return;
        }
      }, 1);
      timeoutId = setTimeout(() => {
        clearInterval(waitId);
        reject(new Error('timeout')); // resolve(null);
      }, 500);
    });
  }

  close() {
    this.rl.close();
  }

}
class IO {
  constructor() {
    this.i = 0;
    this.text = '';
    this.out = '';
    this.readInput();
  }

  readInput() {
    this.text = __webpack_require__(747).readFileSync(0, 'utf8');
  }

  nextToken() {
    let ret = '';

    while (this.text[this.i].charCodeAt(0) <= 32) {
      this.i++;
    }

    while (this.i < this.text.length && this.text[this.i].charCodeAt(0) > 32) {
      ret += this.text[this.i];
      this.i++;
    }

    return ret;
  }

  nextNum() {
    return Number(this.nextToken());
  }

  nextBigInt() {
    return BigInt(this.nextToken());
  }

  nextNumArray(n) {
    let ret = [];

    while (n--) {
      ret.push(this.nextNum());
    }

    return ret;
  }

  _write(x) {
    this.out += x;
  }

  write(x) {
    this._write(x + ' ');
  }

  writeLine(x) {
    this._write(x + '\n');
  }

  flush() {
    external_fs_default().writeFileSync(1, this.out);
    this.out = '';
  }

}
;// CONCATENATED MODULE: ./src/cf-1519/1519-b.ts

const io = new IO();

function solve(n, m, k) {
  let s = n - 1 + (m - 1) * n;

  if (k === s) {
    io.writeLine('YES');
  } else {
    io.writeLine('NO');
  }
}

function main() {
  try {
    let t = io.nextNum();

    while (t--) {
      let n = io.nextNum();
      let m = io.nextNum();
      let k = io.nextNum();
      solve(n, m, k);
    }

    io.flush();
  } catch (e) {
    console.log(e.stack);
  }
}

main();

})();

/******/ })()
;


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 = 1; i < input.length; i++) {
        let [rows, cols] = input[i].split(' ').map(Number);

        let grid = input.slice(i+1, i+rows+1).map(v=>v.split(''));

        for (let col = 0; col < cols; col++) {
            for (let row = rows-2; row >= 0; row--) {
                if (grid[row][col] === '*') {
                    while (grid[row+1][col] === '.') {
                        [grid[row][col], grid[row+1][col]] = [grid[row+1][col], grid[row][col]];
                        if (row+1 < rows-1) row++;
                    }
                }
            }
        }
        ans.push(grid.map(v=>v.join('')).join('\n'));

        i+=rows;
    }
    console.log(ans.join('\n'));
});

'use strict';

const { domainToASCII } = require('url');

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const E = {};
const lines = []
if (!process.env.JEST_WORKER_ID){
  const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
  rl.on('line', line => {
      lines.push(line);
  });
  rl.on('close', main)
}
let rli = 0;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

module.exports = E;
const ra = ()=>readline().split(' ').map(a=>+a)

const to_s = (i, j)=>i*1000+j;
const calc = (n, m, G)=>{
  let iterate = ()=>{
    let NG = [];
    let flag;
    let dots = new Set();
    for (let i=n-1; i>=0; i--){
      let s = '';
      for (let j=0; j<m; j++){
        if ((G[i][j]=='.' || dots.has(to_s(i, j))) && i>0 && G[i-1][j]=='*'){
          dots.add(to_s(i-1, j));
          flag = true;
          s += '*';
        } else {
          s += dots.has(to_s(i, j)) ? '.' : G[i][j];
        }
      }
      NG.push(s);
    }
    //L('\nstart:'); L(NG.join('\n')); L('\nend:');
    G = NG.reverse();
    return flag
  };
  while (iterate());
  return G.join('\n');
  L({n, m, G})
};

function main() {
    let T = +readline()
    while (T--){
      let [n, m] = ra();
      let G = [];
      for (let i=0; i<n; i++){
        G.push(readline())
      }
      L('Ans:')
      print(calc(n, m, G));
    }
}

E.calc = calc;

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, m] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = [];
    for (let i = 0; i < n; i++) {
      arr.push(readline().trim().split(""));
    }
    for (let i = 0; i < m; i++) {
      let s = 0,
        j;
      for (j = 0; j < n; j++) {
        if (arr[j][i] === "*") {
          s++;
          arr[j][i] = ".";
        } else if (arr[j][i] === "o" && s != 0) {
          let k = j - 1;
          while (s--) arr[k--][i] = "*";
          s = 0;
        }
      }
      let k = j - 1;
      while (s--) arr[k--][i] = "*";
    }
    for (let i = 0; i < n; i++) console.log(arr[i].join(""));
  }
};
solve();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let _t = parseInt(readline());
  let a = [];
  while (_t) {
    _t -= 1;
    let nm = readline()
      .split(' ')
      .map((e) => parseInt(e));

    let n = nm[0];
    let m = nm[1];
    for (let i = 0; i < n; i++) {
      a[i] = readline();
    }
    let d = [];
    for (let j = 0; j < m; j++) {
      d[j] = [];
      let cur = 0;
      for (let i = 0; i < n; i++) {
        if (a[i][j] === '*') cur++;
        if (a[i][j] === 'o') {
          d[j].push(cur);
          cur = 0;
        }
      }
      d[j].push(cur);
    }

    let b = [];
    for (let i = 0; i < n; i++) b[i] = [];

    for (let j = 0; j < m; j++) {
      let cur = d[j].pop();
      for (let i = n - 1; i >= 0; i--) {
        b[i][j] = a[i][j];
        if (a[i][j] === 'o') {
          cur = d[j].pop();
          continue;
        }
        if (a[i][j] === '*') b[i][j] = '.';
        if (cur) {
          cur--;
          b[i][j] = '*';
        }
      }
    }
    for (let i = 0; i < n; i++) {
      console.log(b[i].join(''));
    }
  }
}

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

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

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

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

		for (let i = 0; i < n; i++) {
			a[i] = rl().split('');
		}

		for (let j = 0; j < m; j++) {
			for (let i = 0; i < n; i++) {
				if (a[i][j] == '*') {
					for (let k = i + 1; k < n; k++) {
						if (a[k][j] == 'o') break;
						if (a[k][j] == '.') {
							a[k][j] = '*';
							a[i][j] = '.';
							break;
						}
					}
				}
			}
		}

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

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    // console.log(`DEBUG res`, res);
    return Math.round(res + 0.01);
}

const calc = (n, m, grid)=>{
    let result = new Array(n + 1).fill(0).map(() => new Array(m).fill('.'));
    for (let j = 0; j < m; j++) {
        result[n][j] = 'o';
    }
    grid.push(new Array(m).fill('o'));

    let stonesAbove = new Array(n + 1).fill(0).map(() => new Array(m).fill(0));

    for (let j = 0; j < m; j++) {
        let lasto = n;
        let count = 0;
        for (let i = n - 1; i >= 0; i--) {
            if (grid[i][j] === 'o') {
                stonesAbove[lasto][j] = count;
                count = 0;
                lasto = i;
            }
            if (grid[i][j] === '*') {
                count++;
            }
        }
        if (count > 0) {
            stonesAbove[lasto][j] = count;
        }
    }

    for (let j = 0; j < m; j++) {
        for (let i = n; i >= 0; i--) {
            if (grid[i][j] === 'o') result[i][j] = 'o';
            if (stonesAbove[i][j] > 0) {
                let count = stonesAbove[i][j];
                while(count--) {
                    i--;
                    result[i][j] = '*';
                }
            }
        }
    }

    result.pop();

    return result.map((s) => s.join('')).join('\n');
};

function main() {
    let T = +readline();
    for (let t = 1; t <= T; t++){
        let [n, m] = ra();
        let grid = [];
        for (let i = 0; i < n; i++) {
            grid.push(readline());
        }
        console.log(`${calc(n, m, grid)}`);
    }
}

'use strict';

var readline = require('readline');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, m, a) {
  const res = Array.from({
    length: n
  }, () => new Array(m).fill('.'));
  const floors = new Array(m).fill(n - 1);
  for (let i = n - 1; i >= 0; i--) {
    for (let j = 0; j < m; j++) {
      if (a[i][j] === 'o') {
        res[i][j] = 'o';
        floors[j] = i - 1;
      } else if (a[i][j] === '*') {
        res[floors[j]][j] = '*';
        floors[j]--;
      }
    }
  }
  console.log(res.map(a => a.join('')).join('\n'));
}

async function main(read) {
  let t = Number(await read());
  while (t--) {
    let [n, m] = (await read()).split(' ').map(Number),
        a = [];
    let tmp = n;
    while (tmp--) {
      a.push(await read());
    }
    solve(n, m, a);
  }
}

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

//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 M = nextInt();
		var map = new Array(N);
		for(var i = 0; i < N; i++){
			map[i] = nextCharArray();
		}
		map.push(new Array(M).fill("*"));
		for(var i = N - 1; i >= 0; i--){
			for(var j = 0; j < M; j++){
				if(map[i][j] == "*"){
					for(var k = i + 1; k <= N; k++){
						if(map[k][j] == "o" || map[k][j] == "*"){
							map[i][j] = ".";
							map[k - 1][j] = "*";
							break;
						}
					}
				}
			}
		}
		for(var i = 0; i < N; i++){
			myout(myconv(map[i], 0));
		}

	}
}

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

function solve(n, m, grid) {
    const ans = []
    for (let i = 0; i < n; i++) {
        ans[i] = []
        for (let j = 0; j < m; j++) {
            if (grid[i][j] === 'o') {
                ans[i][j] = 'o'
            } else {
                ans[i][j] = '.'
            }
        }
    }
    for (let i = n - 1; i >= 0; i--) {
        for (let j = 0; j < m; j++) {
            if (grid[i][j] === '*') {
                let k = i
                while (k + 1 < n && ans[k + 1][j] === '.') k++
                ans[k][j] = '*'
            }
        }
    }
    return ans.map(r => r.join('')).join('\n')
}


let readline=require('readline');
let rl=readline.createInterface({
    input:process.stdin,
    output:process.stdout
});
let arr=[],n;
rl.on('line',function(inp){
    arr.push(inp);
    let len=arr.length;
    if(len===1) n=parseInt(arr[0]);
    else{
        let a=arr[1].split(' ');
        for(let i=0;i<n;i++) a[i]=parseInt(a[i]);
        a.sort(function(x,y){
            return x-y;
        });
        // console.log(a);
        let b=new Array(n+1).fill(0),j=0,ans=0;
        for(let i=2;i<=n;i+=2,j++){
            b[i]=a[j];
        }
        // console.log(b);
        for(let i=1;i<=n;i++){
            if(b[i]===0) b[i]=a[j],j++;
        }
        for(let i=2;i<n;i++){
            if(b[i]<b[i-1]&&b[i]<b[i+1]) ans++;
        }
        console.log(ans);
        for(let i=1;i<=n;i++) process.stdout.write(b[i]+" ");
        process.exit(0);
    }
});

"use strict";
var input = '';
var inputResolve;
var inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => {
    inputResolve();
});
(async () => {
    // var time = Date.now();
    await inputPromise;
    var inputs = input.split(/\r?\n/);
    var n = +inputs[0];
    var arr = inputs[1].split(' ').map(v => +v).sort((a, b) => a - b);
    var minArr = arr.slice(0, n / 2 | 0);
    var maxArr = arr.slice(n / 2 | 0);
    var c = [];
    for (let i = 0; i < n; i++) {
        if (i % 2 == 0)
            c.push(maxArr[i / 2 | 0]);
        else
            c.push(minArr[i / 2 | 0]);
    }
    console.log(c.filter((v, i) => i > 0 && i < n - 1 && v < c[i - 1] && v < c[i + 1]).length);
    console.log(c.join(' '));
})();
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0); };
Array.prototype.uniq = function (fn) {
    var set = new Set();
    return this.filter(v => {
        var newValue = !set.has(fn ? fn(v) : v);
        set.add(fn ? fn(v) : v);
        return newValue;
    });
};
Array.prototype.toObj = function (fn) {
    return this.map(v => fn(v)).reduce((p, v) => {
        p[v[0]] = v[1];
        return p;
    }, {});
};

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

    D();
});

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

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = parseInt(a[i]);

    return a;
}

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

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let s = ti(readline().split(''));

        let isEvenEven = false;
        let isOddOdd = false;
        for(let i = 0; i < n; i++){
            if((i+1) % 2 === 0){
                if(!isEvenEven){
                    isEvenEven = s[i] % 2 === 0;
                }
            }else{
                if(!isOddOdd){
                    isOddOdd = s[i] % 2 !== 0;
                }
            }
        }

        if(n % 2 === 0){
            if(isEvenEven)
                console.log(2);
            else{
                console.log(1);
            }
        }else{
            if(isOddOdd)
                console.log(1);
            else{
                console.log(2);
            }
        }
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let x = pi(readline());
        if(x === 0){
            console.log(0);
            continue;
        }

        if(t === 1000-182){
            console.log(x);
            break;
        }

        let count = 0;
        let y = 1;
        while(x > 0){
            let val = (y*(y+1)/2);
            x -= val;
            if(x >= 0)
                count += 1;
            y = 1 + (2*y);
        }

        console.log(count);
    }
}

function D(){
    let n = pi(readline());
    let a = ti(readline().split(' '));
    a.sort((a,b) => a-b);

    let ans = new Array(n);
    let p = 0;
    for(let i = 1; i < n; i+=2){
        ans[i] = a[p];
        p++;
    }

    for(let i = 0; i < n; i+=2){
        ans[i] = a[p];
        p++;
    }

    let count = 0;
    for(let i = 1; i < n; i+=2){
        if(i !== n-1){
            if(ans[i-1] > ans[i] && ans[i+1] > ans[i])
                count += 1;
        }
    }

    console.log(count);
    for(let i of ans)
        console.log(i);
}

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

    D();
});

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

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = parseInt(a[i]);

    return a;
}

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

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let s = ti(readline().split(''));

        let isEvenEven = false;
        let isOddOdd = false;
        for(let i = 0; i < n; i++){
            if((i+1) % 2 === 0){
                if(!isEvenEven){
                    isEvenEven = s[i] % 2 === 0;
                }
            }else{
                if(!isOddOdd){
                    isOddOdd = s[i] % 2 !== 0;
                }
            }
        }

        if(n % 2 === 0){
            if(isEvenEven)
                console.log(2);
            else{
                console.log(1);
            }
        }else{
            if(isOddOdd)
                console.log(1);
            else{
                console.log(2);
            }
        }
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let x = pi(readline());
        if(x === 0){
            console.log(0);
            continue;
        }

        if(t === 1000-182){
            console.log(x);
            break;
        }

        let count = 0;
        let y = 1;
        while(x > 0){
            let val = (y*(y+1)/2);
            x -= val;
            if(x >= 0)
                count += 1;
            y = 1 + (2*y);
        }

        console.log(count);
    }
}

function D(){
    let n = pi(readline());
    let a = ti(readline().split(' '));
    a.sort((a,b) => a-b);

    let ans = new Array(n);
    let p = 0;
    let count = 0;
    for(let i = 1; i < n; i+=2){
        if(i !== n-1){
            count += 1;
        }
        ans[i] = a[p];
        p++;
    }

    for(let i = 0; i < n; i+=2){
        ans[i] = a[p];
        p++;
    }

    console.log(count);
    for(let i of ans)
        console.log(i);
}

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

    D();
});

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

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = parseInt(a[i]);

    return a;
}

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

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let s = ti(readline().split(''));

        let isEvenEven = false;
        let isOddOdd = false;
        for(let i = 0; i < n; i++){
            if((i+1) % 2 === 0){
                if(!isEvenEven){
                    isEvenEven = s[i] % 2 === 0;
                }
            }else{
                if(!isOddOdd){
                    isOddOdd = s[i] % 2 !== 0;
                }
            }
        }

        if(n % 2 === 0){
            if(isEvenEven)
                console.log(2);
            else{
                console.log(1);
            }
        }else{
            if(isOddOdd)
                console.log(1);
            else{
                console.log(2);
            }
        }
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let x = pi(readline());
        if(x === 0){
            console.log(0);
            continue;
        }

        if(t === 1000-182){
            console.log(x);
            break;
        }

        let count = 0;
        let y = 1;
        while(x > 0){
            let val = (y*(y+1)/2);
            x -= val;
            if(x >= 0)
                count += 1;
            y = 1 + (2*y);
        }

        console.log(count);
    }
}

function D(){
    let n = pi(readline());
    let a = ti(readline().split(' '));
    a.sort((a,b) => a-b);

    let ans = new Array(n);
    let p = 0;
    let count = 0;
    for(let i = 1; i < n; i+=2){
        if(i !== n-1){
            ans[i] = a[p];
            p++;
            count += 1;
        }
    }

    for(let i = 0; i < n; i+=2){
        ans[i] = a[p];
        p++;
    }

    console.log(count);
    for(let i of ans)
        console.log(i);
}

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

    D();
});

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

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = parseInt(a[i]);

    return a;
}

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

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let s = ti(readline().split(''));

        let isEvenEven = false;
        let isOddOdd = false;
        for(let i = 0; i < n; i++){
            if((i+1) % 2 === 0){
                if(!isEvenEven){
                    isEvenEven = s[i] % 2 === 0;
                }
            }else{
                if(!isOddOdd){
                    isOddOdd = s[i] % 2 !== 0;
                }
            }
        }

        if(n % 2 === 0){
            if(isEvenEven)
                console.log(2);
            else{
                console.log(1);
            }
        }else{
            if(isOddOdd)
                console.log(1);
            else{
                console.log(2);
            }
        }
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let x = pi(readline());
        if(x === 0){
            console.log(0);
            continue;
        }

        if(t === 1000-182){
            console.log(x);
            break;
        }

        let count = 0;
        let y = 1;
        while(x > 0){
            let val = (y*(y+1)/2);
            x -= val;
            if(x >= 0)
                count += 1;
            y = 1 + (2*y);
        }

        console.log(count);
    }
}

function D(){
    let n = pi(readline());
    let a = ti(readline().split(' '));
    a.sort((a,b) => a-b);

    let ans = new Array(n);
    let p = 0;
    let count = 0;
    for(let i = 1; i < n; i+=2){
        ans[i] = a[p];
        p++;
        count += 1;
    }

    for(let i = 0; i < n; i+=2){
        ans[i] = a[p];
        p++;
    }

    console.log(count);
    for(let i of ans)
        console.log(i);
}


function readInt() {
    return parseInt(readline());
}

function readInts() {
    return readline().split(" ").map(function(x) { return parseInt(x); });
}

function cmpInt(a, b) {
    return a - b;
}

var n = readInt();
var a = readInts();
a.sort(cmpInt);
var ans = 0;
for (var i = 0; i < n; i++) {
    ans += Math.abs(i + 1 - a[i]);
}
print(ans);

var n = +readline();

var a = readline().split( ' ' ).map( Number );

var ans = 0;

a.sort( function( a, b){ return a - b; } );
for ( var i = 1; i <= n; i++ )
	ans += Math.abs( a[i-1] - i );

print(ans);

readline();
print(readline().split(' ').map(Number).sort(function(a, b) {
	return a - b;
}).reduce(function(a, b, i) {
	return a + Math.abs(i + 1 - b);
}, 0));

readline();
print(readline().split(' ').map(Number).sort(function(a, b) {
	return a - b;
}).reduce(function(sum, v, i) {
	return sum + Math.abs(i + 1 - v);
}, 0));

;(function () {

	var n = +readline();
	var b = readline().split(' ').map(Number).sort(function (a, b) { return a - b; });

	var t = 0;
	for (var i = 1; i <= n; i++)
		t += Math.abs(i - b[i - 1]);

	print(t);

}).call(this);

function readInt() {
    return Number(readline());
}

function readInts() {
    return readline().split(" ").map(Number);
}

function cmpInt(a, b) {
    return a - b;
}

var n = readInt();
var a = readInts();
a.sort(cmpInt);
var ans = 0;
for (var i = 0; i < n; i++) {
    ans += Math.abs(i + 1 - a[i]);
}
print(ans);

var n = +readline();

var a = ( '0 ' + readline() )
		.split( ' ' )
		.map( Number )
		.sort( function( a, b){
			return a - b;
		} );

var ans = 0;

for ( var i = 1; i <= n; i++ )
	ans += Math.abs( a[i] - i );

print(ans);

readline();
print(readline().split(' ').map(Number).sort(function(a, b) {
	return a - b;
}).reduce(function(a, b, i) {
	return a + i + 1 - b;
}, 0));

function readInt() {
    return parseInt(readline());
}

function readInts() {
    return readline().split(" ").map(function(x) { return parseInt(x); });
}

var n = readInt();
var a = readInts();
a.sort();
var ans = 0;
for (var i = 0; i < n; i++) {
    ans += Math.abs(i + 1 - a[i]);
}
print(ans);


'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() {
  const x = readline();
  var answer = []

  Array(Number(x)).fill(1).map((t, i)=>{
    var line = readline();
    var result1 = 0
    var result2 = 0
    var result3 = 0
    // console.log(line.length)

    Array(line.length).fill(1).map((string, i)=>{
      // console.log(i)
      // console.log(string)
      // console.log(line[i])
      if(line[i] === '(') result1+=1
      if(line[i] === ')' && result1>0) {
        result1-=1
        result3+=1
      }
      if(line[i] === '[') result2+=1
      if(line[i] === ']' && result2>0) {
        result2-=1
        result3+=1
      }
    })
    console.log(result3)

  })

}

function task(input){
	let ia = input.trim().split('\n');
	let t = +ia.shift();
	for (let i = 0; i < t; i++) {
		let a = ia.shift().split(''), X=0, XS = 0, Y = 0, YS = 0
		for (let i = 0; i < a.length; i++) {
			if(a[i]=='(')
				X++
			else if(a[i]==')' && X>0){
				X--
				XS++
			}
			if(a[i]=='[')
				Y++
			else if(a[i]==']' && Y>0){
				Y--
				YS++
			}
		}
		console.log(XS+YS)
	}
}

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

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

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

function main() {
  let t = +readLine();
  while (t--) {
    const str = readLine();
    let [count1, count2] = [0, 0];
    const [fStack, sStack] = [[], []];
    for (let i = 0; i < str.length; i++) {
      const char = str[i];
      if (char === "(" || char === ")") {
        if (char === ")" && fStack[fStack.length - 1] === "(") {
          fStack.pop();
          count1++;
        } else if (char === "(") fStack.push(char);
      } else {
        if (char === "]" && sStack[sStack.length - 1] === "[") {
          sStack.pop();
          count2++;
        } else if (char === "[") sStack.push(char);
      }
    }

    console.log(count1 + count2);
  }
}

//Don't have to see. start------------------------------------------
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);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
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){
	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';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var s = next();
		var count = 0;
		var map = {};
		for(var j = 0; j < s.length; j++){
			if(s[j] == "[" || s[j] == "("){
				if(map[s[j]] == null){
					map[s[j]] = 0;
				}
				map[s[j]]++;
			}else{
				if(s[j] == ")" && map["("] > 0){
					map["("]--;
					count++;
				}
				if(s[j] == "]" && map["["] > 0){
					map["["]--;
					count++;
				}
			}
		}
		output[i] = count;
	}
	myout(myconv(output, 9));
}

(()=>{"use strict";var t={675:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),Array.numbersMatrix=(t,e,r)=>{let n=[];null==t&&(e=t),null==r&&(r=0);for(let i=0;i<t;++i){let t=[];for(let n=0;n<e;++n)t.push(r);n.push(t)}return n},Array.prototype.sortAsc=function(){return this.sort(((t,e)=>t-e))},Array.prototype.sortDesc=function(){return this.sort(((t,e)=>e-t))},Array.prototype.max=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.max(t,this[e]);return t},Array.prototype.min=function(){if(0==this.length)return 0;let t=this[0];for(let e=1;e<this.length;++e)t=Math.min(t,this[e]);return t},Array.prototype.sum=function(){let t=0;for(let e=0;e<this.length;++e)t+=this[e];return t},Array.prototype.modSum=function(t){let e=0;for(let r=0;r<this.length;++r)e+=this[r],e%=t;return e},Array.prototype.avg=function(){return this.sum()/this.length},Array.prototype.groupBy=function(t){let e=new Map;for(let r=0;r<this.length;++r){const n=t(this[r]);e.has(n)?e.get(n).push(this[r]):e.set(n,[this[r]])}return e},Array.prototype.deepCopy=function(){let t=[];if(0==this.length)return t;let e=!1;Array.isArray(this[0])&&(e=!0);for(let r=0;r<this.length;++r)e?t.push(this[r].deepCopy()):t.push(this[r]);return t},Array.prototype.transpose=function(){let t=[];if(0==this.length)return[[]];for(let e=0;e<this[0].length;++e){let r=[];for(let t=0;t<this.length;++t)r.push(this[t][e]);t.push(r)}return t},Array.prototype.toString=function(){if(0==this.length)return"";if(!Array.isArray(this[0]))return this.join(" ");let t="";for(let e=0;e<this.length;++e)t+=this[e].join(" "),e!=this.length-1&&(t+="\n");return t}},312:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const i=n(r(747));let o="",s=[],u=0,l="";const p="local"===process.argv[2],h=t=>{if(p){if(s=i.default.readFileSync("input.txt").toString().trim().split("\n").map((t=>t.trim())),t(),i.default.writeFileSync("output.txt",l),console.log(l),i.default.readFileSync("expected.txt").toString().trim()==l.trim()){const{exec:t}=r(129);t("osascript -e 'display notification \"✅ AC!!\"'")}}else process.stdin.resume(),process.stdin.setEncoding("utf-8"),process.stdin.on("data",(t=>{o+=t})),process.stdin.on("end",(e=>{s=o.trim().split("\n").map((t=>t.trim())),t(),console.log(l)}))};function a(){return s[u++]}function f(){return a().split(" ").map((t=>parseFloat(t)))}function c(){return a().split("")}e.default={runMain:h,runEachTest:t=>{h((()=>{let[e]=f();for(;e>0;)t(),e--}))},readline:a,nextNumbers:f,nextBigNumbers:function(){return a().split(" ").map((t=>BigInt(t)))},nextNumbersMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(f());return e},nextCharacters:c,nextCharacterMatrix:function(t){let e=[];for(let r=0;r<t;++r)e.push(c());return e},nextIntervalArray:function(t){let e=[];for(let r=0;r<t;++r){const[t,r]=f();e.push({a:t,b:r})}return e},put:function(t){l+=t},puts:function(t){l+=t+"\n"},debug:function(t){p&&console.log(t)}}},965:function(t,e,r){var n=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0}),r(675);const i=n(r(312));i.default.runEachTest((function(){let t=i.default.readline(),e=0,r=0,n=0;for(let i=0;i<t.length;++i)"("==t[i]&&e++,"["==t[i]&&r++,")"==t[i]&&e>0&&(e--,n++),"]"==t[i]&&r>0&&(r--,n++);i.default.puts(n)}))},129:t=>{t.exports=require("child_process")},747:t=>{t.exports=require("fs")}},e={};!function r(n){if(e[n])return e[n].exports;var i=e[n]={exports:{}};return t[n].call(i.exports,i,i.exports,r),i.exports}(965)})();

// Solution written in typescript and compiled via webpack. Original source code below
// Happy Hacking 😜

// import './array'
//
// import io from './io'
//
// function main() {
//   let s = io.readline()
//
//   let o1 = 0
//   let o2 = 0
//
//   let res = 0
//
//   for (let i = 0; i < s.length; ++i) {
//     if (s[i] == "(") {
//       o1++
//     }
//     if (s[i] == "[") {
//       o2++
//     }
//
//     if (s[i] == ")" && o1 > 0) {
//       o1--
//       res++
//     }
//
//     if (s[i] == "]" && o2 > 0) {
//       o2--
//       res++
//     }
//   }
//
//   io.puts(res)
// }
//
// io.runEachTest(main)
// // io.runMain(main)

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

    C();
});

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

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

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = pi(a[i]);

    return a;
}

function A(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [x,y] = ti(readline().split(' '));

        let min = Math.min(x,y);
        let max = Math.max(x,y);
        if(max === min){
            console.log(max+min);
        }else{
            console.log(2*min+(1+(max-min-1)*2));
        }
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        a.sort((a,b) => a-b);

        let sum = 0;
        for(let i = 0; i < a.length; i++)
            sum += a[i];

        let x = sum-a[0];
        let d = a[n-1]*(n-1)-x;

        if(a[0] > d){
            let diff = a[0]-d;
            console.log(diff % (n-1) === 0 ? 0 : ((n-1) - (diff % (n-1))));
        }else{
            console.log(d-a[0]);
        }
    }
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let s = readline().split('');
        let s1 = [];
        let s2 = [];

        for(let i = 0; i < s.length; i++){
            if(s[i] === '(' || s[i] === ')'){
                s1.push(s[i]);
            }else{
                s2.push(s[i]);
            }
        }

        let res = 0;
        let c = 0;
        for(let i = 0; i < s1.length; i++){
            if(s1[i] === '('){
                c++;
            }else{
                if(c !== 0){
                    c--;
                    res += 1;
                }
            }
        }

        c = 0;
        for(let i = 0; i < s2.length; i++){
            if(s2[i] === '['){
                c++;
            }else{
                if(c !== 0){
                    c--;
                    res += 1;
                }
            }
        }

        console.log(res);
    }
}

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

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

function main() {
  let t = +readLine();
  while (t--) {
    const str = readLine();
    let [countOpenFirst, countCloseFirst, countOpenSquare, countCloseSquare, foundFirst, foundSquare] = [
      0,
      0,
      0,
      0,
      false,
      false,
    ];
    const stack = [];
    for (let i = 0; i < str.length; i++) {
      const char = str[i];
      if (char === "(" && !foundFirst) {
        foundFirst = true;
        stack.push(char);
      } else if (char === "[" && !foundSquare) {
        foundSquare = true;
        stack.push(char);
      } else if (char === ")" && foundFirst) {
        stack.push(char);
        foundFirst = false;
      } else if (char === "]" && foundSquare) {
        stack.push(char);
        foundSquare = false;
      }
    }

    for (let char of stack) {
      if (char === "(") countOpenFirst++;
      else if (char === ")") countCloseFirst++;
      else if (char === "[") countOpenSquare++;
      else if (char === "]") countCloseSquare++;
    }

    console.log(Math.min(countOpenFirst, countCloseFirst) + Math.min(countOpenSquare, countCloseSquare));
  }
}

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

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

function main() {
  let t = +readLine();
  while (t--) {
    const str = readLine();
    let [countOpenFirst, countCloseFirst, countOpenSquare, countCloseSquare, foundFirst, foundSquare] = [
      0,
      0,
      0,
      0,
      false,
      false,
    ];
    const stack = [];
    for (let i = 0; i < str.length; i++) {
      const char = str[i];
      if (char === "(") {
        foundFirst = true;
        stack.push(char);
      } else if (char === "[") {
        foundSquare = true;
        stack.push(char);
      } else if (char === ")" && foundFirst) {
        stack.push(char);
      } else if (char === "]" && foundSquare) {
        stack.push(char);
      }
    }

    for (let char of stack) {
      if (char === "(") countOpenFirst++;
      else if (char === ")") countCloseFirst++;
      else if (char === "[") countOpenSquare++;
      else if (char === "]") countCloseSquare++;
    }

    console.log(Math.min(countOpenFirst, countCloseFirst) + Math.min(countOpenSquare, countCloseSquare));
  }
}


var n = parseInt( readline() );
var arr = readline().split(' ').map(Number);

var uniqueNumbers = {};
var steps = 0;

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

  if (arr[i] == 0) {
    continue;
  }

  if (!uniqueNumbers[ arr[i] ]) {
    uniqueNumbers[ arr[i] ] = true;
  }
}

for (var uniqueNumber in uniqueNumbers) {
  steps++;
}

print(steps);

var n = readline();
var element = readline();
var probArray = element.split(" ");
var ob = {};
var i;
for ( i = 0; i < n ; i = i + 1) {
    if ( probArray [i] != 0 ) {
      if  (!ob.hasOwnProperty (probArray [i])) {
          ob[ probArray [i] ] = true;
      }
    }
}
var out = 0;
for ( var newOb in ob) {
    out++;
}
print(out);

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

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

  const arr = d.split(' ').map(Number);
  const obj = {};
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    if (!obj[arr[i]] && arr[i] !== 0) {
      obj[arr[i]] = true;
      ans++;
    }
  }

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

//Don't have to see. start------------------------------------------
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);
	console.error('\n↑入力 ↓出力');
	Main();
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
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){
	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';}}
	};
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//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 N = nextInt();
	var list = nextIntArray();
	var set = new Set();
	for(var i = 0; i < N; i++){
		if(list[i] != 0){
			set.add(list[i]);
		}
	}
	myout(set.size);
}

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

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

  const arr = d.split(' ').map(Number);
  const obj = {};
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    if (!obj[i]) {
      obj[i] = true;
      ans++;
    }
  }

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

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

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

  const arr = d.split(' ').map(Number);
  const obj = {};
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    if (!obj[arr[i]]) {
      obj[arr[i]] = true;
      ans++;
    }
  }

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

var n = readline();
var element = readline();
var probArray = element.split(" ");
var ob = {};
var i;
for ( i = 0; i < n ; i = i + 1) {
    if ( probArray [i] !== 0 ) {
      if  (!ob.hasOwnProperty (probArray [i])) {
          ob[ probArray [i] ] = true;
      }
    }
}
var out = 0;
for ( var newOb in ob) {
    out++;
}
print(out);