process.stdin.resume();
process.stdin.setEncoding('utf-8')
let inputString = '';
let currentLine = 0;
process.stdin.on('data', input => { inputString += input; })
process.stdin.on('end', _ => { inputString = inputString.split('\n'); main(); })
const readline = () => { return inputString[currentLine++] }

function main() {
    [n, k] = readline().split(' ').map(x => parseInt(x));
    p = readline().split(' ').map(x => parseInt(x));
    let mnMax = n - k + 1;
    let pos = -1;
    let sum = 0;
    let parts = 1;
    p.forEach((val, index) => {
        if(val >= mnMax){
            sum += val;
            if(pos != -1)
                parts = (parts * (index - pos)) % 998244353;
            pos = index;
        }
    })
    console.log(sum, parts);
}

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

let input = ''
let ptr = 0
process.stdin.on('data', (i) => {
  input += i
})

process.stdin.on('end', () => {
  input = input.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
  main()
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt() {
  return parseInt(input[ptr++])
}

function readString() {
  return input[ptr++]
}

function readStrings() {
  return input[ptr++].split(' ')
}

function readInts() {
  return input[ptr++].split(' ').map(a => parseInt(a))
}

function main() {
  const [n, k] = readInts()
  const p = readInts()
  const mod = 998244353
  const x = p.map((a, i) => [a, i])
  x.sort((a, b) => b[0] - a[0])
  let ans1 = 0
  let ans2 = 1
  const mark = new Array(n).fill(0)
  for(let i = 0; i < k; i++) {
    ans1 += x[i][0]
    mark[x[i][1]] = 1
  }
  let ptr = mark[0] ? 0 : -1
  for(let i = 1; i < n; i++) {
    if(mark[i] && ptr === -1) {
      ptr = i
    }
    else if(mark[i] && ptr !== -1) {
      ans2 = ans2 *(i - ptr) % mod
      ptr = i
    }
  }

  wr(ans1, ans2)
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
var inputString = '';
var currentLine = 0;
process.stdin.on('data', function (input) { inputString += input; });
process.stdin.on('end', function (_) { inputString = inputString.split('\n'); main(); });
var readline = function () { return inputString[currentLine++]; };
function main() {
    var _a = readline().split(' ').map(function (x) { return parseInt(x); }), n = _a[0], k = _a[1];
    var p = readline().split(' ').map(function (x) { return parseInt(x); });
    var mnMax = n - k + 1;
    var pos = -1;
    var sum = 0;
    var parts = 1;
    p.forEach(function (val, index) {
        if (val >= mnMax) {
            sum += val;
            if (pos != -1)
                parts = (parts * (index - pos)) % 998244353;
            pos = index;
        }
    });
    console.log(sum, parts);
}

const mod =  998244353

const processData = (lines) => {
  const [num, k] = lines[0].split(' ').map(x => +x)

  const nums = lines[1].split(' ').map(x => +x)
  const sliced = nums.map((x, pos) => ({num: x, pos})).sort((a, b) => b.num-a.num).slice(0, k)
  const max = sliced.reduce((r, x) => r+x.num, 0)

  sliced.sort((a, b) => a.pos - b.pos)

  let multipliers = []
  let prevPos = sliced[0].pos
  for (let i=1; i<sliced.length; i++) {
    const pos = sliced[i].pos
    if (pos - prevPos > 1) {
      multipliers.push(pos - prevPos)
    }
    prevPos = pos
  }

  let sum = 1
  for (const m of multipliers) {
    sum = (sum * m) % mod
  }

  console.log(`${max} ${sum}`)
}

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

const mod =  998244353

const processData = (lines) => {
  const [num, k] = lines[0].split(' ').map(x => +x)

  const nums = lines[1].split(' ').map(x => +x)
  const sliced = nums.map((x, pos) => ({num: x, pos})).sort((a, b) => b.num-a.num).slice(0, k)
  const max = sliced.reduce((r, x) => r+x.num, 0)

  sliced.sort((a, b) => a.pos - b.pos)

  let multipliers = []
  let prevPos = 0
  for (let i=0; i<sliced.length; i++) {
    const pos = sliced[i].pos
    if (pos - prevPos > 1) {
      multipliers.push(pos - prevPos)
    }
    prevPos = pos
  }

  let sum = 1
  for (const m of multipliers) {
    sum = (sum * m) % mod
  }

  console.log(`${max} ${sum}`)
}

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

const mod =  998244353

const processData = (lines) => {
  const [num, k] = lines[0].split(' ').map(x => +x)

  const nums = lines[1].split(' ').map(x => +x)
  const sliced = nums.map((x, pos) => ({num: x, pos})).sort((a, b) => b.num-a.num).slice(0, k)
  const max = sliced.reduce((r, x) => r+x.num, 0)

  sliced.sort((a, b) => a.pos - b.pos)

  let multipliers = []
  let prevPos = 0
  for (let i=0; i<sliced.length; i++) {
    const pos = sliced[i].pos
    if (pos - prevPos > 1) {
      multipliers.push(pos - prevPos)
    }
    prevPos = pos
  }
  if (prevPos < num - 1) {
    multipliers.push(num - 1 - prevPos)
  }

  let sum = 1
  for (const m of multipliers) {
    sum = (sum * m) % mod
  }

  console.log(`${max} ${sum}`)
}

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


const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i <= Number(q[0]); i++) {
        console.log(solve(q[i]))
    }
}
function solve(n) {
    const ang1 = Math.PI / n;
    const R = 0.5 / Math.sin(ang1 / 2);
    function ee(shift) {
        let xl = Number.MAX_VALUE;
        let yb = Number.MAX_VALUE;
        let xr = Number.MIN_VALUE;
        let yt = Number.MIN_VALUE;
        for (let i = 0; i < 2 * n; i++) {
            const x = Math.cos(Math.PI / n * i + shift);
            const y = Math.sin(Math.PI / n * i + shift);
            xl = Math.min(xl, x);
            xr = Math.max(xr, x);
            yb = Math.min(yb, y);
            yt = Math.max(yt, y);
        }
        return Math.max(xr - xl, yt - yb) * R;
    }

    return ee(Math.PI / 4 / n).toPrecision(10);
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i <= Number(q[0]); i++) {
        console.log(solve(q[i]))
    }
}
function solve(n) {
    const ang1 = Math.PI / n;
    const R = 0.5 / Math.sin(ang1 / 2);
    function ee(shift) {
        let xl = Number.MAX_VALUE;
        let yb = Number.MAX_VALUE;
        let xr = Number.MIN_VALUE;
        let yt = Number.MIN_VALUE;
        for (let i = 0; i < 2 * n; i++) {
            const x = R * Math.cos(Math.PI / n * i + shift);
            const y = R * Math.sin(Math.PI / n * i + shift);
            xl = Math.min(xl, x);
            xr = Math.max(xr, x);
            yb = Math.min(yb, y);
            yt = Math.max(yt, y);
        }
        return Math.max(xr - xl, yt - yb);
    }
    let l = 0;
    let r = (2 * Math.PI) / (2 * n);
    for (let i = 0; i < 100; i++) {
        const l1 = (2 * l + r) / 3;
        const r1 = (2 * r + l) / 3;
        const calc1 = ee(l1);
        const calc2 = ee(r1);
        if (calc1 < calc2) {
            r = r1;
        } else {
            l = l1;
        }
    }
    return ee((l + r) / 2).toPrecision(10);
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})

function Main() {
  var A = Number(readline());
  for(var i=0;i<A;i++){
    var n = Number(readline());
    print(Math.sin((Math.PI*(n-1/2))/(2*n))/(Math.sin(Math.PI/(2*n))));
  }
}
Main();

const readline = require('readline');
const input = [];
function A(q) {
    for (let i = 1; i <= Number(q[0]); i++) {
        console.log(solve(q[i]))
    }
}
function solve(n) {
    const ang1 = Math.PI / n;
    const R = 0.5 / Math.sin(ang1 / 2);
    function ee(shift) {
        let xl = Number.MAX_VALUE;
        let yb = Number.MAX_VALUE;
        let xr = Number.MIN_VALUE;
        let yt = Number.MIN_VALUE;
        for (let i = 0; i < n; i++) {
            const x = R * Math.cos(Math.PI / n * i + shift);
            const y = R * Math.sin(Math.PI / n * i + shift);
            xl = Math.min(xl, x);
            xr = Math.max(xr, x);
            yb = Math.min(yb, y);
            yt = Math.max(yt, y);
        }
        return Math.max(xr - xl, yt - yb);
    }
    let l = 0;
    let r = (2 * Math.PI) / (2 * n);
    for (let i = 0; i < 100; i++) {
        const l1 = (2 * l + r) / 3;
        const r1 = (2 * r + l) / 3;
        if (ee(l1) < ee(r1)) {
            r = r1;
        } else {
            l = l1;
        }
    }
    return ee((l + r) / 2).toPrecision(10);
}
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', q => {
    input.push(q.trim())
});
rl.on('close', () => {
    A(input);
})


///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 05/20/21 afternoon

const solve = (n, s) => {
    let cnt = 0;
    for (const c of s) cnt += (c == '0');
    if (cnt == 0) return pr('DRAW');
    if (!isPalindrome(s)) {
        if (n & 1 && s[n >>> 1] == '0' && cnt == 2) {
            return pr('DRAW');
        }
        return pr('ALICE');
    }
    if (n & 1 && s[n >>> 1] == '0') {
        if (cnt == 1) {
            return pr('BOB');
        } else if (cnt == 2) {
            return pr('DRAW');
        } else {
            return pr("ALICE");
        }
    }
    pr('BOB');
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i], input[i + 1]);
            i += 2;
        }
    });
};

main()

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

function solve(str) {
    const mid = Math.ceil(str.length / 2)

    let zero = 0
    let diff = 0
    for (let i = mid - 1; i >= 0; i--) {
        const j = str.length - 1 - i
        if (str[i] !== str[j]) diff++
        else if (str[i] === '0') zero++
    }

    let cost
    if ((str.length & 1) && str[mid - 1] === '0') {
        // alice change the middle 0 first
        // then convert to 0x0
        if (zero === 1) {
            cost = [1, 0]
            // if diff > 1, alice will reverse, and make bob pay the total
            if (diff > 1) {
                cost = [0, 1 + diff]
            } else if (diff === 1) {
            // if diff == 1, bob can force alice to fill the uniqe 0
                cost = [1, 1]
            }
        } else {
            // alices starts the process
            // if bob skips to reduce the diff, just reverse
            cost = [1, 2 + diff]
        }
    } else {
        // 00x00 -> 10x00 -> 10x01, same with 0x0
        cost = [2, 0]
        if (diff) {
            // alice reverses first, no matter bob chooses to reduce the diff,
            // or start 00 process, bob pays the total
            cost = [0, 2 + diff]
        }
    }

    if (cost[0] !== cost[1]) {
        return cost[0] < cost[1] ? 'ALICE' : 'BOB'
    } else {
        return 'DRAW'
    }
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

function solve(str) {
    const mid = Math.ceil(str.length / 2)

    let zero = 0
    let diff = 0
    for (let i = mid - 1; i >= 0; i--) {
        const j = str.length - 1 - i
        if (str[i] !== str[j]) diff++
        else if (str[i] === '0') zero++
    }

    let cost
    if ((str.length & 1) && str[mid - 1] === '0') {
        // alice change the middle 0 first
        // then convert to 0x0
        if (zero === 1) {
            cost = [1, 0]
            // if diff > 1, alice will reverse, and make bob pay the total
            if (diff > 1) {
                cost = [0, 1 + diff]
            } else {
            // if diff == 1, bob can force alice to fill the uniqe 0
                cost = [1, 1]
            }
        } else {
            // alices starts the process
            // if bob skips to reduce the diff, just reverse
            cost = [1, 2 + diff]
        }
    } else {
        // 00x00 -> 10x00 -> 10x01, same with 0x0
        cost = [2, 0]
        if (diff) {
            // alice reverses first, no matter bob chooses to reduce the diff,
            // or start 00 process, bob pays the total
            cost = [0, 2 + diff]
        }
    }

    if (cost[0] !== cost[1]) {
        return cost[0] < cost[1] ? 'ALICE' : 'BOB'
    } else {
        return 'DRAW'
    }
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

function solve(str) {
    const mid = Math.ceil(str.length / 2)

    let zero = 0
    let diff = 0
    for (let i = mid - 1; i >= 0; i--) {
        const j = str.length - 1 - i
        if (str[i] !== str[j]) diff++
        else if (str[i] === '0') zero++
    }

    let cost
    if ((str.length & 1) && str[mid - 1] === '0') {
        // alice change the middle 0 first
        // then convert to 0x0
        if (zero === 1) {
            cost = [1, 0]
        } else {
            cost = [1, 2]
        }
    } else {
        // 00x00 -> 10x00 -> 10x01, same with 0x0
        cost = [2, 0]
    }

    const [a, b] = cost
    if (diff) {
        // not reverse, [a + diff, b]
        // reverse, [b, a + diff]
        cost = [Math.min(a + diff, b), Math.max(a + diff, b)]
    }

    if (cost[0] !== cost[1]) {
        return cost[0] < cost[1] ? 'ALICE' : 'BOB'
    } else {
        return 'DRAW'
    }
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

function solve(str) {
    const mid = Math.ceil(str.length / 2)

    let zero = 0
    let diff = 0
    for (let i = mid - 1; i >= 0; i--) {
        const j = str.length - 1 - i
        if (str[i] !== str[j]) diff++
        else if (str[i] === '0') zero++
    }

    // 00x00 -> 10x00 -> 10x01, same with 0x0
    let cost = [2, 0]
    if ((str.length & 1) && str[mid - 1] === '0') {
        // alice change the middle 0 first
        // then convert to 0x0
        cost = [1, 2]
        return diff === 1 ? 'DRAW' : 'ALICE'
    }
    if (diff) {
        cost = [0, 2 + diff]
    }

    const [a, b] = cost
    if (a !== b) {
        return a < b ? 'ALICE' : 'BOB'
    } else {
        return 'DRAW'
    }
}

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

let cache0, cache1
function solve(str) {
    cache0 = {}
    cache1 = {}

    const mid = Math.ceil(str.length / 2)
    for (let i = mid - 1; i >= 0; i--) {
        const j = str.length - i
        cache0[i] = solvePay(str, i, j)
        cache1[i] = solvePay(str, i, j, 1)
    }
    const [a, b] = cache0[0]
    // console.log(cache0)
    if (a === b) return 'DRAW'
    return a < b ? 'ALICE' : 'BOB'
}

// @returns [a, b, p], `p` means `str` is palindrome
function solvePay(str, i, j, r /* if 1, can't reverse */) {
    str = str.slice(i, j)

    const len = str.length
    if (len === 1) {
        return str === '1' ? [0, 0, 1] : [1, 0, 1]
    } else if (len === 2) {
        if (str === '11') {
            return [0, 0, 1]
        } else if (str === '00') {
            // change -> reverse -> change
            return [2, 0, 1]
        } else {
            // reverse -> change
            return r ? [1, 0, 0] : [0, 1, 0]
        }
    } else {
        const r1 = cache0[i + 1]
        const r2 = cache1[i + 1]
        const [a, b, p] = r1
        const [a2, b2, p2] = r2

        str = str[0] + str[str.length - 1]
        if (str === '11') {
            if (r) {
                // still can't reverse, do nothing
                return r2
            } else if (p) {
                return r1
            } else {
                return [b, a, p]
            }
        } else if (str === '00') {
            if (p || r) {
                // can't reverse
                return [b + 2, a, p]
            } else {
                return [a, b + 2, p]
            }
        } else {
            if (r) {
                return [a + 1, b, 0]
            } else {
                return [a, b + 1, 0]
            }
        }
    }
}

// console.log(solvePay('11'))
// console.log(solvePay('1111'))

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

let cache0, cache1
function solve(str) {
    cache0 = {}
    cache1 = {}

    const mid = Math.ceil(str.length / 2)
    for (let i = mid - 1; i >= 0; i--) {
        const j = str.length - i
        cache0[i] = solvePay(str, i, j)
        cache1[i] = solvePay(str, i, j, 1)
    }
    const [a, b] = cache0[0]
    // console.log(cache0)
    if (a === b) return 'DRAW'
    return a < b ? 'ALICE' : 'BOB'
}
function solvePay(str, i, j, r /* if 1, can't reverse */) {
    str = str.slice(i, j)

    const len = str.length
    if (len === 1) {
        return str === '1' ? [0, 0, 1] : [1, 0, 1]
    } else if (len === 2) {
        if (str === '11') {
            return [0, 0, 1]
        } else if (str === '00') {
            // change -> reverse -> change
            return [2, 0, 1]
        } else {
            // reverse -> change
            return r ? [1, 0, 0] : [0, 1, 0]
        }
    } else {
        const r1 = cache0[i + 1]
        const r2 = cache1[i + 1]
        const [a, b, p] = r1
        const [a2, b2, p2] = r2

        str = str[0] + str[str.length - 1]
        if (str === '11') {
            if (r) {
                // still can't reverse
                return r2
            } else {
                return r1
            }
        } else if (str === '00') {
            if (p || r) {
                // can't reverse
                return [a + 2, b, p]
            } else {
                return [a, b + 2, p]
            }
        } else {
            if (r) {
                return [a + 1, b, 0]
            } else {
                return [a, b + 1, 0]
            }
        }
    }
}

// console.log(solvePay('11'))
// console.log(solvePay('1111'))

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var lines = [];
rl.on('line', function(input) {
    lines.push(input);
});
rl.on('close', function() {
    var t = parseInt(lines[0]);
    var l = 1;
    for (var i = 0; i < t; i++) {
        var n = +lines[l++]
        console.log(solve(lines[l++]));
    }
});

function solve(str) {
    const [a, b] = solvePay(str)
    if (a === b) return 'DRAW'
    return a < b ? 'ALICE' : 'BOB'
}
function solvePay(str) {
    if (str.length === 1) {
        return str === '1' ? [0, 0, 1] : [1, 0, 1]
    } else if (str.length === 2) {
        if (str === '11') {
            return [0, 0, 1]
        } else if (str === '00') {
            // change -> reverse -> change
            return [2, 0, 1]
        } else {
            // reverse -> change
            return [0, 1, 0]
        }
    } else {
        const [a, b, p] = solvePay(str.slice(1, -1))
        if (str === '11') {
            return [a, b, p]
        } else if (str === '00') {
            if (p) {
                return [a + 2, b, p]
            } else {
                return [a, b + 2, p]
            }
        } else {
            return [a, b + 1, 0]
        }
    }
}

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 05/20/21 afternoon
 * https://codeforces.com/contest/1527/problem/B2
 */

const solve = (n, s) => {
    let se = new Set();
    for (let i = 0; i < n; i++) {
        if (s[i] == '0') se.add(i);
    }
    let a = s.split("");
    let Alice = Bob = 0;
    let isP = isPalindrome(s);
    let round = 1;
    let pre;
    while (se.size) {
        if (isP == false && pre != 'rv') {
            a.reverse();
            pre = 'rv';
        } else {
            let did = false;
            for (const i of se) {
                if (i == n - 1 - i || a[n - 1 - i] == '1') {
                    a[i] = '1';
                    did = true;
                    se.delete(i);
                    break;
                }
            }
            if (!did) {
                let first = se.values().next().value;
                a[first] = '1';
                se.delete(first);
                isP = false;
            }
            round & 1 ? Alice++ : Bob++;
            pre = 'rp';
        }
        round++;
    }
    if (Alice > Bob) {
        pr("BOB");
    } else if (Alice < Bob) {
        pr("ALICE");
    } else {
        pr("DRAW")
    }
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line);
    });
    rl.on('close', () => {
        let t = Number(input[0]);
        let i = 1;
        while (t--) {
            solve(input[i], input[i + 1]);
            i += 2;
        }
    });
};

main()


'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, grid) {
  let res = [-1, -1];
  skip: for (let i = 0; i < n; i++) {
    const dp = [],
          nums = grid[i];
    for (let j = m - 1; j >= 0; j--) {
      var _nums$dp;
      if (nums[j] < ((_nums$dp = nums[dp[j + 1]]) !== null && _nums$dp !== void 0 ? _nums$dp : Infinity)) {
        dp[j] = j;
      } else {
        dp[j] = dp[j + 1];
      }
    }
    for (let j = 0; j < m; j++) {
      if (nums[dp[j]] < nums[j]) {
        res = [j, dp[j]];
        break skip;
      }
    }
  }
  if (res[0] === -1) return `1 1`;
  const [a, b] = res;
  const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];
  for (let i = 0; i < n; i++) {
    if (grid[i][a] < grid[i][b]) return -1;
    swap(i, a, b);
  }
  for (let i = 0; i < n; i++) {
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) return -1;
    }
  }
  return [a + 1, b + 1].join(' ');
}

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

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

const comp = (arr,n)=>{
     let sort = [...arr].sort((a,b)=>a-b);
     let res = [],cnt = 0;
     for(let i=0;i<n;i++){
          if(arr[i]!==sort[i]){
               cnt++;
               res.push(i);
          }
          if(cnt===3) return -1;
     }
     if(cnt===0) return 1;
     else return res;
}
const swap = (arr,n,s)=>{
     for(let i=0;i<n;i++) [arr[i][s[0]],arr[i][s[1]]] = [arr[i][s[1]],arr[i][s[0]]]
}
const check = (arr,n,m)=>{
     for(let i=0;i<n;i++){
          for(let j=1;j<m;j++){
               if(arr[i][j-1]>arr[i][j]) return false;
          }
     }
     return true;
}
const solve = (arr,n,m)=>{
     if(m===1) return `1 1`;
     for(let i=0;i<n;i++){
          let s = comp(arr[i],m);
          if(s===-1) return -1;
          if(s===1) continue;
          swap(arr,n,s);
          if(check(arr,n,m)) return `${s[0]+1} ${s[1]+1}`;
          else return -1;
     }
     return `1 1`;
}

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

'use strict';
// HEADER:
const print = function(arg){
  let str = arg;
  if (arguments.length>1)
    str = Array.prototype.slice.call(arguments).join(' ');
  process.stdout.write(str+'\n');
};
let IS_MULTITEST, testN, tests;
const pcalc = (testN, toPrint)=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    toPrint.push(res.join(' '));
  } else if (Number.isFinite(res) || typeof res=='string'){
    toPrint.push(res+'');
  }
  if (process.env.DEBUG && toPrint.length){
    let ans = toPrint.pop();
    print(ans);
    let expected = tests[testN-1];
    if (expected){
      if (expected==ans)
        console.log('\x1b[32m%s\x1b[0m', 'correct');
      else {
        console.log('\x1b[31m%s\x1b[0m', 'wrong, expected:', expected);
      }
    }
  }
};

const main = ()=>{
  let toPrint = [];
  L('\nSolving:');
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(testN, toPrint);
  } else {
    pcalc(1, toPrint);
  }
  if (toPrint.length){
    print(toPrint.join('\n'));
  }
};

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;
const readline = ()=>lines[rli++];
const L = process.env.DEBUG ? console.log : ()=>{};
const LT = obj=>L(`\nTest #${testN}`, obj);

const ra = ()=>readline().split(' ').map(a=>+a)
const pa = arr=>print(arr.join(' '));

tests = [
``, // Test #1
``, // Test #2
``, // Test #3
``, // Test #4
``, // Test #5
];

// SOLUTION:
IS_MULTITEST = true;

const calc = (testN)=>{
  // READING:
  let [n, m] = ra();
  let A = [];
  let SA = [];
  for (let i=0; i<n; i++){
    A.push(ra())
    SA.push(A[i].slice().sort((a, b)=>a-b));
  }
  LT({n, m, A});
  //L(SA.join('\n'))
  // PROCESSING:
  let DIFFS = [];
  let ref_diff;
  for (let i=0; i<n; i++){
    let diffs = [];
    for (let j=0; j<m; j++){
      if (A[i][j]!=SA[i][j])
        diffs.push(j);
    }
    if (diffs.length>2)
      return -1;
    if (diffs.length==2)
      ref_diff = diffs;
    DIFFS.push(diffs);
  }
  if (!ref_diff)
    return '1 1';
  for (let i=0; i<n; i++){
    let diff = DIFFS[i];
    if (diff.length==2){
      if (diff[0]!=ref_diff[0] || diff[1]!=ref_diff[1])
        return -1;
    } else {
      if (SA[i][ref_diff[0]]!=SA[i][ref_diff[1]])
        return -1;
    }
  }
  return `${ref_diff[0]+1} ${ref_diff[1]+1}`;
};

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 calc = ()=>{
    /* read */
    let [n, m] = ra();
    let g = [];
    let cols = new Array(m);
    let scols = new Array(m);
    let sg = [];
    for (let i = 0; i < n; i++) {
        let row = ra();
        g.push(row);
        sg.push([...row]);
    }

    for (let i = 0; i < m; i++) {
        cols[i] = i;
        scols[i] = i;
    }

    if (m === 1) return "1 1";

    const isInc = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] > g[i][b]) return false;
        }
        return true;
    }

    const isDec = (a, b) => {
        let eqcnt = 0;
        for (let i = 0; i < n; i++) {
            if (g[i][a] < g[i][b]) return false;
            if (g[i][a] === g[i][b]) eqcnt++;
        }
        return eqcnt !== n;
    }

    const isEq = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] !== g[i][b]) return false;
        }
        return true;
    }

    for (let i = 0; i < n; i++) {
        sg[i].sort((a, b) => a - b);
    }

    // scols.sort((a, b) => {
    //     if (isEq(a, b)) return 0;
    //     if (isInc(a, b)) return -1;
    //     return 1;
    // });

    // console.log('DEBUG g', g);
    // console.log('DEBUG sg', sg);

    let diffs = new Set();

    for (let i = 0; i < n; i++){
        for (let j = 0; j < m; j++) {
            if (g[i][j] !== sg[i][j]) diffs.add(j);
        }
    }

    // console.log('DEBUG diffs', diffs);

    diffs = Array.from(diffs);

    if (diffs.length > 2) return "-1";

    if (diffs.length === 2) {
        for (let i = 0; i < n; i++) {
            let tmp = g[i][diffs[0]];
            g[i][diffs[0]] = g[i][diffs[1]];
            g[i][diffs[1]] = tmp;
        }
    }

    // console.log('DEBUG g', g);

    for (let i = 0; i < n; i++){
        for (let j = 0; j < m - 1; j++) {
            if (g[i][j] > g[i][j + 1]) return "-1";
        }
    }

    return diffs.length === 2 ? `${diffs[0] + 1} ${diffs[1] + 1}` : "1 1";

};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc());
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

'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, grid) {
  let res = [];
  const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];
  for (let i = 0; i < n; i++) {
    let a = -1,
        b = -1;
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) {
        let t = j - 1;
        for (let k = j - 1; k >= 0; k--) {
          if (nums[k] === nums[j - 1]) t = k;
        }
        if (t === j - 1) {
          let t1 = j;
          for (let k = j + 1; k < m; k++) {
            if (nums[k] <= nums[j]) t1 = k;
          }
          if (t1 === j) {
            if (nums[j + 1] < nums[j]) {
              [a, b] = [t, j + 1];
            } else {
              [a, b] = [t, j];
            }
          } else {
            [a, b] = [t, t1];
          }
        } else {
          [a, b] = [t, j];
        }
        break;
      }
    }
    if (a !== -1) {
      res.push([a, b]);
      break;
    }
  }
  if (!res.length) return `1 1`;
  const [a, b] = res[0];
  for (let i = 0; i < n; i++) {
    if (grid[i][a] < grid[i][b]) return -1;
    swap(i, a, b);
  }
  for (let i = 0; i < n; i++) {
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) return -1;
    }
  }
  return [a + 1, b + 1].join(' ');
}

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

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

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 calc = ()=>{
    /* read */
    let [n, m] = ra();
    let g = [];
    for (let i = 0; i < n; i++) {
        g.push(ra());
    }

    if (m === 1) return "1 1";

    // console.log('DEBUG g', g);

    let lastIncCol = 0;
    let lastDecCol = m - 1;

    const isInc = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] > g[i][b]) return false;
        }
        return true;
    }

    const isDec = (a, b) => {
        let eqcnt = 0;
        for (let i = 0; i < n; i++) {
            if (g[i][a] < g[i][b]) return false;
            if (g[i][a] === g[i][b]) eqcnt++;
        }
        return eqcnt !== n;
    }

    while (lastIncCol < m - 1 && isInc(lastIncCol, lastIncCol + 1)) lastIncCol++;

    // console.log('DEBUG lastIncCol', lastIncCol);

    if (lastIncCol === m - 1) return "1 1";

    while (lastDecCol > 0 && isDec(lastDecCol, lastDecCol - 1)) lastDecCol--;

    // console.log('DEBUG lastDecCol', lastDecCol);

    for (let i = 0; i < n; i++) {
        let tmp = g[i][lastIncCol];
        g[i][lastIncCol] = g[i][lastDecCol];
        g[i][lastDecCol] = tmp;
    }

    for (let i = 0; i < m - 1; i++) {
        if (!isInc(i, i + 1)) return "-1";
    }

    return `${lastIncCol + 1} ${lastDecCol + 1}`;
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc());
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

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 calc = ()=>{
    /* read */
    let [n, m] = ra();
    let g = [];
    let cols = new Array(m);
    let scols = new Array(m);
    let sg = [];
    for (let i = 0; i < n; i++) {
        let row = readline().split(' ');
        g.push(row);
        sg.push([...row]);
    }

    for (let i = 0; i < m; i++) {
        cols[i] = i;
        scols[i] = i;
    }

    if (m === 1) return "1 1";

    const isInc = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] > g[i][b]) return false;
        }
        return true;
    }

    const isDec = (a, b) => {
        let eqcnt = 0;
        for (let i = 0; i < n; i++) {
            if (g[i][a] < g[i][b]) return false;
            if (g[i][a] === g[i][b]) eqcnt++;
        }
        return eqcnt !== n;
    }

    const isEq = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] !== g[i][b]) return false;
        }
        return true;
    }

    for (let i = 0; i < n; i++) {
        sg[i].sort((a, b) => a - b);
    }

    // scols.sort((a, b) => {
    //     if (isEq(a, b)) return 0;
    //     if (isInc(a, b)) return -1;
    //     return 1;
    // });

    // console.log('DEBUG g', g);
    // console.log('DEBUG sg', sg);

    let diffs = new Set();

    for (let i = 0; i < n; i++){
        for (let j = 0; j < m; j++) {
            if (g[i][j] !== sg[i][j]) diffs.add(j);
        }
    }

    // console.log('DEBUG diffs', diffs);

    diffs = Array.from(diffs);

    if (diffs.length > 2) return "-1";

    if (diffs.length === 2) {
        for (let i = 0; i < n; i++) {
            let tmp = g[i][diffs[0]];
            g[i][diffs[0]] = g[i][diffs[1]];
            g[i][diffs[1]] = tmp;
        }
    }

    // console.log('DEBUG g', g);

    for (let i = 0; i < n; i++){
        for (let j = 0; j < m - 1; j++) {
            if (g[i][j] > g[i][j + 1]) return "-1";
        }
    }

    return diffs.length === 2 ? `${diffs[0] + 1} ${diffs[1] + 1}` : "1 1";

};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc());
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

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 calc = ()=>{
    /* read */
    let [n, m] = ra();
    let g = [];
    let cols = new Array(m);
    let scols = new Array(m);
    let sg = [];
    for (let i = 0; i < n; i++) {
        let row = readline().split(' ');
        g.push(row);
        sg.push([...row]);
    }

    for (let i = 0; i < m; i++) {
        cols[i] = i;
        scols[i] = i;
    }

    if (m === 1) return "1 1";

    const isInc = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] > g[i][b]) return false;
        }
        return true;
    }

    const isDec = (a, b) => {
        let eqcnt = 0;
        for (let i = 0; i < n; i++) {
            if (g[i][a] < g[i][b]) return false;
            if (g[i][a] === g[i][b]) eqcnt++;
        }
        return eqcnt !== n;
    }

    const isEq = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] !== g[i][b]) return false;
        }
        return true;
    }

    for (let i = 0; i < n; i++) {
        sg[i].sort((a, b) => a - b);
    }

    // scols.sort((a, b) => {
    //     if (isEq(a, b)) return 0;
    //     if (isInc(a, b)) return -1;
    //     return 1;
    // });

    // console.log('DEBUG sg', sg);

    let diffs = new Set();

    for (let i = 0; i < n; i++){
        for (let j = 0; j < m; j++) {
            if (g[i][j] !== sg[i][j]) diffs.add(j);
            if (diffs.size > 2) return "-1";
        }
    }

    diffs = Array.from(diffs);

    if (diffs.length !== 2 && diffs.length !== 0) return "-1";

    if (diffs.length === 2) {
        // console.log('DEBUG diffs', diffs);
        for (let i = 0; i < n; i++) {
            let tmp = g[i][diffs[0]];
            g[i][diffs[0]] = g[i][diffs[1]];
            g[i][diffs[1]] = tmp;
        }
    }

    for (let i = 0; i < n; i++){
        for (let j = 0; j < m - 1; j++) {
            if (g[i][j] > g[i][j + 1]) return "-1";
        }
    }

    return diffs.length === 2 ? `${diffs[0] + 1} ${diffs[1] + 1}` : "1 1";

};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc());
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

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 calc = ()=>{
    /* read */
    let [n, m] = ra();
    let g = [];
    let cols = new Array(m);
    let scols = new Array(m);
    let sg = [];
    for (let i = 0; i < n; i++) {
        let row = readline().split(' ');
        g.push(row);
        sg.push([...row]);
    }

    for (let i = 0; i < m; i++) {
        cols[i] = i;
        scols[i] = i;
    }

    if (m === 1) return "1 1";

    const isInc = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] > g[i][b]) return false;
        }
        return true;
    }

    const isDec = (a, b) => {
        let eqcnt = 0;
        for (let i = 0; i < n; i++) {
            if (g[i][a] < g[i][b]) return false;
            if (g[i][a] === g[i][b]) eqcnt++;
        }
        return eqcnt !== n;
    }

    const isEq = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] !== g[i][b]) return false;
        }
        return true;
    }

    for (let i = 0; i < n; i++) {
        sg[i].sort((a, b) => a - b);
    }

    // scols.sort((a, b) => {
    //     if (isEq(a, b)) return 0;
    //     if (isInc(a, b)) return -1;
    //     return 1;
    // });

    // console.log('DEBUG sg', sg);

    let diffs = new Set();

    for (let i = 0; i < n; i++){
        for (let j = 0; j < m; j++) {
            if (g[i][j] !== sg[i][j]) diffs.add(j);
            if (diffs.size > 2) return "-1";
        }
    }

    diffs = Array.from(diffs);

    if (diffs.length !== 2 && diffs.length !== 0) return "-1";

    if (diffs.length === 2) {
        for (let i = 0; i < n; i++) {
            let tmp = g[i][diffs[0]];
            g[i][diffs[0]] = g[i][diffs[1]];
            g[i][diffs[1]] = tmp;
        }
    }

    for (let i = 0; i < m - 1; i++) {
        if (!isInc(i, i + 1)) return "-1";
    }

    return diffs.length === 2 ? `${diffs[0] + 1} ${diffs[1] + 1}` : "1 1";

};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc());
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

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 calc = ()=>{
    /* read */
    let [n, m] = ra();
    let g = [];
    let cols = new Array(m);
    let scols = new Array(m);
    let sg = [];
    for (let i = 0; i < n; i++) {
        let row = readline().split(' ');
        g.push(row);
        sg.push([...row]);
    }

    for (let i = 0; i < m; i++) {
        cols[i] = i;
        scols[i] = i;
    }

    if (m === 1) return "1 1";

    const isInc = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] > g[i][b]) return false;
        }
        return true;
    }

    const isDec = (a, b) => {
        let eqcnt = 0;
        for (let i = 0; i < n; i++) {
            if (g[i][a] < g[i][b]) return false;
            if (g[i][a] === g[i][b]) eqcnt++;
        }
        return eqcnt !== n;
    }

    const isEq = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] !== g[i][b]) return false;
        }
        return true;
    }

    scols.sort((a, b) => {
        if (isEq(a, b)) return 0;
        if (isInc(a, b)) return -1;
        return 1;
    });

    // console.log('DEBUG scols', scols);

    let diffs = [];

    for (let i = 0; i < m; i++) {
        if (cols[i] !== scols[i]) diffs.push(i);
        if (diffs.length > 2) return "-1";
    }

    if (diffs.length !== 2 && diffs.length !== 0) return "-1";

    if (diffs.length === 2) {
        for (let i = 0; i < n; i++) {
            let tmp = g[i][diffs[0]];
            g[i][diffs[0]] = g[i][diffs[1]];
            g[i][diffs[1]] = tmp;
        }
    }

    for (let i = 0; i < m - 1; i++) {
        if (!isInc(i, i + 1)) return "-1";
    }

    return diffs.length === 2 ? `${diffs[0] + 1} ${diffs[1] + 1}` : "1 1";

};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc());
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

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 calc = ()=>{
    /* read */
    let [n, m] = ra();
    let g = [];
    for (let i = 0; i < n; i++) {
        g.push(readline().split(' '));
    }

    if (m === 1) return "1 1";

    // console.log('DEBUG g', g);

    let lastIncCol = 0;
    let lastDecCol = m - 1;

    const isInc = (a, b) => {
        for (let i = 0; i < n; i++) {
            if (g[i][a] > g[i][b]) return false;
        }
        return true;
    }

    const isDec = (a, b) => {
        let eqcnt = 0;
        for (let i = 0; i < n; i++) {
            if (g[i][a] < g[i][b]) return false;
            if (g[i][a] === g[i][b]) eqcnt++;
        }
        return eqcnt !== n;
    }

    while (lastIncCol < m - 1 && isInc(lastIncCol, lastIncCol + 1)) lastIncCol++;

    // console.log('DEBUG lastIncCol', lastIncCol);

    if (lastIncCol === m - 1) return "1 1";

    while (lastDecCol > 0 && isDec(lastDecCol, lastDecCol - 1)) lastDecCol--;

    // console.log('DEBUG lastDecCol', lastDecCol);

    for (let i = 0; i < n; i++) {
        let tmp = g[i][lastIncCol];
        g[i][lastIncCol] = g[i][lastDecCol];
        g[i][lastDecCol] = tmp;
    }

    for (let i = 0; i < m - 1; i++) {
        if (!isInc(i, i + 1)) return "-1";
    }

    return `${lastIncCol + 1} ${lastDecCol + 1}`;
};

function main() {
    let T = +readline();
    let out = [];
    for (let t = 1; t <= T; t++){
        out.push(calc());
        // process.stdout.write(`${calc(n, a)}\n`);
    }
    process.stdout.write(out.join('\n')+'\n');
}

'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, grid) {
  let res = [];
  const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];
  for (let i = 0; i < n; i++) {
    let a = -1,
        b = -1;
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) {
        let t = j - 1;
        for (let k = j - 1; k >= 0; k--) {
          if (nums[k] === nums[j - 1]) t = k;
        }
        if (t === j - 1) {
          let t1 = j;
          for (let k = j + 1; k < m; k++) {
            if (nums[k] === nums[j]) t1 = k;
          }
          if (t1 === j) {
            if (nums[j + 1] < nums[j]) {
              [a, b] = [t, j + 1];
            } else {
              [a, b] = [t, j];
            }
          } else {
            [a, b] = [t, t1];
          }
        } else {
          [a, b] = [t, j];
        }
        break;
      }
    }
    if (a !== -1) {
      res.push([a, b]);
      break;
    }
  }
  if (!res.length) return `1 1`;
  const [a, b] = res[0];
  for (let i = 0; i < n; i++) {
    if (grid[i][a] < grid[i][b]) return -1;
    swap(i, a, b);
  }
  for (let i = 0; i < n; i++) {
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) return -1;
    }
  }
  return [a + 1, b + 1].join(' ');
}

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

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

'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, grid) {
  let res = [];
  const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];
  for (let i = 0; i < n; i++) {
    let a = -1,
        b = -1;
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) {
        let t = j - 1;
        while (nums[t - 1] === nums[j - 1]) {
          t--;
        }
        if (t === j - 1) {
          let t1 = j;
          for (let k = j + 1; k < m; k++) {
            if (nums[k] === nums[j]) t1 = k;
          }
          if (t1 === j) {
            if (nums[j + 1] < nums[j]) {
              [a, b] = [t, j + 1];
            } else {
              [a, b] = [t, j];
            }
          } else {
            [a, b] = [t, t1];
          }
        } else {
          [a, b] = [t, j];
        }
        break;
      }
    }
    if (a !== -1) {
      res.push([a, b]);
      break;
    }
  }
  if (!res.length) return `1 1`;
  const [a, b] = res[0];
  for (let i = 0; i < n; i++) {
    if (grid[i][a] < grid[i][b]) return -1;
    swap(i, a, b);
  }
  for (let i = 0; i < n; i++) {
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) return -1;
    }
  }
  return [a + 1, b + 1].join(' ');
}

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

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

'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, grid) {
  let res = [];
  const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];
  for (let i = 0; i < n; i++) {
    let index = [-1, -1];
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) {
        let t = j - 1;
        while (nums[t - 1] === nums[t]) {
          t--;
        }
        if (t === j - 1) {
          let t1 = j;
          while (nums[t1 + 1] === nums[j]) {
            t1++;
          }
          if (t1 === j) {
            if (nums[j + 1] < nums[j]) {
              index = [t, j + 1];
            } else {
              index = [t, j];
            }
          } else {
            index = [j - 1, t1];
          }
        } else {
          index = [t, j];
        }
        break;
      }
    }
    if (index[0] !== -1) {
      res.push(index);
      break;
    }
  }
  if (!res.length) return `1 1`;
  const [a, b] = res[0];
  for (let i = 0; i < n; i++) {
    if (grid[i][a] < grid[i][b]) return -1;
    swap(i, a, b);
  }
  for (let i = 0; i < n; i++) {
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) return -1;
    }
  }
  return [a + 1, b + 1].join(' ');
}

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

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

'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, grid) {
  let res = [];
  const swap = (i, j, k) => [grid[i][j], grid[i][k]] = [grid[i][k], grid[i][j]];
  for (let i = 0; i < n; i++) {
    let index = [-1, -1];
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) {
        if (j > 2 && nums[j] < nums[j - 3]) return -1;
        if (j < m - 2 && nums[j - 1] > nums[j + 2]) return -1;
        if (j > 1 && nums[j - 1] === nums[j - 2]) {
          if (nums[j - 1] > nums[j + 1]) return -1;
          index = [j - 2, j];
        } else if (nums[j] >= nums[j + 1]) {
          if (j > 1 && nums[j + 1] < nums[j - 2]) return -1;
          index = [j - 1, j + 1];
        } else {
          if (nums[j - 1] > nums[j + 1]) return -1;
          index = [j - 1, j];
        }
        break;
      }
    }
    if (index[0] !== -1) {
      res.push(index);
      break;
    }
  }
  if (!res.length) return `1 1`;
  const [a, b] = res[0];
  for (let i = 0; i < n; i++) {
    if (grid[i][a] < grid[i][b]) return -1;
    swap(i, a, b);
  }
  for (let i = 0; i < n; i++) {
    for (let j = 1; j < m; j++) {
      const nums = grid[i];
      if (nums[j] < nums[j - 1]) return -1;
    }
  }
  return [a + 1, b + 1].join(' ');
}

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

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

const swap = (arr,c1,c2,n,m)=>{
     for(let i=0;i<n;i++){
          [arr[i][c1],arr[i][c2]] = [arr[i][c2],arr[i][c1]];
     }
}
const check = (arr,n,m)=>{
     for(let i=0;i<n;i++){
          for(let j=0;j<m-1;j++){
               if(arr[i][j]>arr[i][j+1]) return false;
          }
     }
     return true;
}
const solve = (arr,n,m)=>{
     if(m===1) return `1 1`;
     let c1 = 0,c2 = 0;
     for(let i=0;i<n;i++){
          let cnt = 0;
          for(let j=1;j<m;j++){
               if(arr[i][j-1]>arr[i][j]){
                    cnt++;
                    c1 = cnt===1 ? j-1 : c1;
                    c2 = j;
               }
          }
          if(cnt===3) return -1;
          if((c1!==0)||(c2!==0)){
               swap(arr,c1,c2,n,m);
               if(check(arr,n,m)) return `${c1+1} ${c2+1}`;
               else return -1;
          }
     }
     return `1 1`;
}

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


n = +readline();
l = readline().split(" ").map(Number);
ans = 0;
cmp = n;
for (i = n - 1; i >= 0; i--) {
  if (i < cmp)
    ans++;
  cmp = Math.min(cmp, i - l[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 n = readline();
  const l = readline().split(' ').map(Number);
  helper(n, l);
}

function helper(n, l) {
    let killNum = n
    let alive = 0
    for (let i = n - 1; i >= 0; i--) {
        if (i < killNum) alive++
        killNum = Math.min(killNum, i - l[i])
    }

    console.log(alive + '')
}

const count = readline();
const claws = readline().split(' ').map(v=> parseInt(v));

var alive = 0;
var lastAlive = claws.length - 1;

for (var killer = claws.length - 1; killer >= 0; killer--) {
    if (killer === lastAlive) {
        alive++;
    }
    lastAlive = Math.min(lastAlive, killer - claws[killer] - 1);
}

print(alive);

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n')
  const n = parseInt(arr.shift())
  const claw = arr.shift().split(' ')

  var count = 1
  var last = n - 1
  for(let i = n - 1; i >= 0; i --) {
    // console.log(i, claw[i], last, count)
    if(i < last) count ++
    if(i - claw[i] <= last && claw[i] != 0) last = i - claw[i]
  }
  console.log(count)
})

var n = parseInt(readline());
var vivos=0;
var array2 = readline().split(' ');
for(var i = 0; i < n ; i++){
	array2[i]= parseInt(array2[i]);
}
var ultimo=n-1;
for(var i = n-1; i >=0  ;i--){
	 if (i === ultimo) {
        vivos++;
    }
    ultimo = Math.min(ultimo, i - array2[i] - 1);
}
print(vivos);

n = +readline();
l = readline().split().map(Number);
ans = 0
cmp = n
for (i = n - 1; i >= 0; i--) {
  if (i < cmp)
    ans++;
  cmp = Math.min(cmp, i - l[i]);
}
print(ans)

const count = readline();
const claws = readline().split(' ').map(v=> parseInt(v));

var alive = 0;
var lastAlive = claws.length - 1;

for (var killer = claws.length - 1; killer >= 0; killer--) {
    print(lastAlive);

    if (killer === lastAlive) {
        alive++;
    }

    lastAlive = Math.min(lastAlive, killer - claws[killer] - 1);
}

print(alive);

'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 n = readline();
  const l = readline().split(' ').map(Number);
  helper(n, l);
}

function helper(n, l) {
    let killed = new Set()
    for (let i = n - 1; i >= 0; i--) {
        for (let j = 1; j <= l[i]; j++) {
            killed.add(i - j)
        }
        if (killed.size === n - 1) {
            console.log('1')
            return
        }
    }

    console.log((n - killed.size) + '')
}

'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 n = readline();
  const l = readline().split(' ').map(Number);
  helper(n, l);
}

function helper(n, l) {
    let killed = new Set()
    for (let i = n - 1; i >= 0; i--) {
        if (l[i] >= i) {
            if (i === n - 1) {
                console.log('1')
                return;
            }
            break;
        }
        for (let j = 1; j <= l[i] && j <= i; j++) {
            killed.add(i - j)
        }
        if (killed.size >= n - 1) {
            console.log('1')
            return
        }
    }

    console.log((n - killed.size) + '')
}

'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 n = readline();
  const l = readline().split(' ').map(Number);
  helper(n, l);
}

function helper(n, l) {
    let killed = new Set()
    for (let i = n - 1; i >= 0; i--) {
        if (l[i] >= i) {
            if (i === n - 1) {
                console.log('1')
            } else {
                console.log((n - killed.size - i + 1) + '')
            }
            return

        }
        for (let j = 1; j <= l[i] && j <= i; j++) {
            killed.add(i - j)
        }
    }

    console.log((n - killed.size) + '')
}

'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 n = readline();
  const l = readline().split(' ').map(Number);
  helper(n, l);
}

function helper(n, l) {
    let killed = new Set()
    for (let i = n - 1; i >= 0; i--) {
        if (l[i] >= i) {
            if (i === n - 1) {
                console.log('1')
            } else {
                console.log((n - killed.size - i) + '')
            }
            return

        }
        for (let j = 1; j <= l[i] && j <= i; j++) {
            killed.add(i - j)
        }
    }

    console.log((n - killed.size) + '')
}

'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 n = readline();
  const l = readline().split(' ').map(Number);
  helper(n, l);
}

function helper(n, l) {
    let killed = new Set()
    for (let i = n - 1; i >= 0; i--) {
        if (l[i] >= i) {
            if (i === n - 1) {
                console.log('1')
                return
            } else {
                console.log((n - killed.size - i) + '')
            }

        }
        for (let j = 1; j <= l[i] && j <= i; j++) {
            killed.add(i - j)
        }
    }

    console.log((n - killed.size) + '')
}


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 len = +readLine();
    const arr = readLine().split(" ").map(Number);
    let result = arr.reverse();
    result = result.map((n, index) => {
      if (index % 2 === 0) {
        return -1 * n;
      } else return n;
    });

    console.log(result.join(" "));
  }
}

#!/usr/bin/env node
'use strict';

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

const buf = [];
const prom = [];
let maxBuf = 0;
let maxProm = 0;
rl.on('line', (line) => {
  if (prom.length > 0) {
    maxProm = Math.max(maxProm, prom.length);
    const [resolve, reject] = prom.shift();
    resolve(line);
  } else {
    rl.pause();
    buf.push(line);
    maxBuf = Math.max(maxBuf, buf.length);
  }
});

rl.on('close', () => {
  // console.error({maxProm, maxBuf});
});

async function getLine() {
  return new Promise((resolve, reject) => {
    if (buf.length > 0) {
      const line = buf.shift();
      resolve(line);
    } else {
      prom.push([resolve, reject]);
      rl.resume();
    }
  });
}

/**
 *
 * @param {Number []} a
 * @returns {Number []}
 */
function solve(a) {
  const n = a.length;
  const res = [];
  for (let i = 1; i < n; i += 2) {
    res.push(a[i], -a[i-1]);
  }
  return res;
}

async function main() {
  const t = Number(await getLine());
  for (let i = 0; i < t; i++) {
    const n = Number(await getLine());
    const a = (await getLine()).split(' ').map(Number);
    const res = solve(a);
    console.log(res.join(' '));
  }
}

if (require.main === module) {
  main();
}

const readline = require('readline');

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

function spltoarr(arr){
    for (let i=0; i<arr.length; i++){
        arr[i]=parseInt(arr[i])
    }
};

function sealBreakJutsu(sealValues){
    for(let c=doorSealCount, f=0;c>0;c-=2,f+=2){
        chakraValues += `${sealValues[f+1]*-1} `;
        chakraValues += `${sealValues[f]} `;
        doorSealCount -=2;
    }
    console.log(chakraValues)

}

var doorCount, doorSealCount, sealValues, chakraValues;
chakraValues='';
rl.on('line', (input) => {

if(doorCount>0){

    if(doorSealCount>0 ){
        sealValues=input.split(" ")
        spltoarr(sealValues)
        sealBreakJutsu(sealValues)
        doorCount -=1
        chakraValues = ''
    } else doorSealCount=parseInt(input)

}else doorCount=parseInt(input)

})

const readline = require('readline');

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

let arr = []
let count = 0
let T = 0
let str = '';

rl.on('line', (input) => {
  if (count === 0) {
    T = input
  } else if (count % 2 === 0) {
    arr.push(input.split(' '))
  }
  count++
  if (T * 2 + 1 === count) {
    for (let i = 0; i < arr.length; i++) {
      str = '';
      for (let k = 1; k < arr[i].length; k = k + 2) {
        str = str + ' ' + -arr[i][k] + ' ' + arr[i][k-1];
      }
      console.log(str);
    }
  }
});

'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 A(arr) {
  if (!Array.isArray(arr)) return [];

  if (arr.length === 0 || arr.length % 2 !== 0) return [];

  const result = [];

  for (let i = 0; i < arr.length / 2; i++) {
    result.push(-arr[2 * i + 1], arr[2 * i]);
  }

  return result;
}

function main() {
    const T = readline();
    for (let i = 0; i < T; i++) {
  const n = readline();
  const arrStr = readline();
  const arr = arrStr.split(' ');
  process.stdout.write(A(arr).join(' '));
        process.stdout.write('\n');
    }
}

//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 N = nextInt();
		var list = nextIntArray();
		var b = new Array(N);
		for(var j = 0; j < N; j += 2){
			var L = lcm(list[j], list[j + 1]);
			b[j] = L / list[j];
			b[j + 1] = -L / list[j + 1];
		}

		output[i] = myconv(b, 8);
	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

//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 N = nextInt();
		var list = nextIntArray();
		var L = list[0];
		for(var j = 1; j < N; j++){
			L = lcm(L, list[j]);
		}
		myerr(L);
		var b = new Array(N);
		if(N % 2 == 1){
			for(var j = 0; j < N - 1; j++){
				if(j < Math.floor(N / 2)){
					b[j] = L / list[j];
				}else{
					b[j] = -(L / list[j]);
				}
			}
			b[N - 1] = -L * 2;
		}else{
			for(var j = 0; j < N; j++){
				b[j] = L / list[j];
				if(j >= N / 2){
					b[j] *= -1;
				}
			}
		}
		output[i] = myconv(b, 8);
	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

//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 N = nextInt();
		var list = nextIntArray();
		var L = list[0];
		for(var j = 1; j < N; j++){
			L = lcm(L, list[j]);
		}
		var b = new Array(N);
		for(var j = 0; j < N; j++){
			b[j] = L / list[j];
			if(j >= N / 2){
				b[j] *= -1;
			}
		}
		var sum = 0;
		for(var j = 0; j < N; j++){
			sum += list[j] * b[j];
		}
		myerr(sum);
		output[i] = myconv(b, 8);
	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

//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 N = nextInt();
		var list = nextIntArray();
		var b = new Array(N);
		for(var j = 0; j < N; j += 2){
			var L = lcm(list[j], list[j + 1]);
			b[j] = L / list[j];
			b[j + 1] = L / list[j + 1];
		}

		output[i] = myconv(b, 8);
	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

//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 N = nextInt();
		var list = nextIntArray();
		var L = list[0];
		for(var j = 1; j < N; j++){
			L = lcm(L, list[j]);
		}
		var b = new Array(N);
		if(N % 2 == 1){
			for(var j = 0; j < N - 1; j++){
				if(j <= Math.floor(N / 2)){
					b[j] = L / list[j];
				}else{
					b[j] = -(L / list[j]);
				}
			}
			b[N - 1] = -L * 2 / list[j];
		}else{
			for(var j = 0; j < N; j++){
				b[j] = L / list[j];
				if(j >= N / 2){
					b[j] *= -1;
				}
			}
		}

		output[i] = myconv(b, 8);
	}
	myout(myconv(output, 9));
}
function lcm(m, n) {return (m / gcd(m, n)) * n;}	function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

const readline = require('readline');

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

let arr = []
let count = 0
let T = 0
let str = '';

rl.on('line', (input) => {
  if (count === 0) {
    T = input
  } else if (count % 2 === 0) {
    arr.push(input.split(' '))
  }
  count++
  if (T * 2 + 1 === count) {
    for (let i = 0; i < arr.length; i++) {
      str = '';
      for (let k = 1; k < arr[i].length; k = k + 2) {
        let num = k - 1;
        str = str + ' ' + -k + ' ' + num;
      }
      console.log(str);
    }
  }
});


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

    A();
});

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 [n,k] = ti(readline().split(' '));
        let s = readline().split('');
        let v = new Array(n);
        v.fill('?');
        let flag = true;
        for(let i = 0; i < k; i++){
            for(let j = i; j < n; j+=k){
                if(s[j] === '?')
                    continue;
                if(v[i] === '?' || v[i] === s[j])
                    v[i] = s[j];
                else{
                    flag = false;
                    break;
                }
            }
        }

        if(flag){
            let c1 = 0;
            let c0 = 0;
            for(let i = 0; i < k; i++){
                if(v[i] === '1') c1++;
                if(v[i] === '0') c0++;
            }

            if(c1 > k/2 || c0 > k/2)
                console.log('NO');
            else
                console.log('YES');
        }else{
            console.log('NO');
        }
    }
}

let input = '';
let inputResolve;
let inputPromise = new Promise(resolve => inputResolve = resolve);
process.stdin.on('data', c => input += c);
process.stdin.on('end', () => inputResolve());

(async () => {
  await inputPromise;
  let inp = input.split(/\r?\n/); r = 0;
  let t = +inp[r++];
  for (let i = 0; i < t; i++) {
    (() => {
      let [n, k] = inp[r++].split(' ').map(v => +v);
      let s = inp[r++].split('');
      // console.log(s.join(''));
      for (let i = 0; i < k; i++) {
        let c = s[i];
        for (let j = i + k; j < n; j += k) {
          if (c != '?' && s[j] != '?' && c != s[j]) {
            // console.log(c, j, s[j]);
            console.log('NO');
            return;
          }
          if (s[j] != '?') c = s[j];
        }
        s[i] = c;
      }
      let c = {};
      for (let i = 0; i < k; i++) c[s[i]] = (c[s[i]] || 0) + 1;
      // console.log(c);
      console.log((c[0] || 0) <= k / 2 && (c[1] || 0) <= k / 2 ? 'YES' : '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++];
}

// utils
const MOD = 1e9 + 7;
const mod = (n) => ((n % MOD) + MOD) % MOD;
const add = (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 main() {
  let t = +readLine();
  while (t--) {
    const [len, limit] = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    const arr = readLine().split("");
    let possible = true;
    let [count0, count1] = [0, 0];

    for (let i = 0; i < len; i++) {
      const index = i % limit;
      if (arr[i] === "?" && arr[index] !== "?") {
        arr[i] = arr[index];
      } else if (arr[index] === "?" && arr[i] !== "?") {
        arr[index] = arr[i];
      }

      if (arr[i] !== arr[index]) {
        possible = false;
        break;
      }
    }

    if (possible) {
      for (let i = 0; i < limit; i++) {
        if (arr[i] === "1") count1++;
        if (arr[i] === "0") count0++;
      }

      if (count1 <= limit / 2 && count0 <= limit / 2) possible = true;
      else possible = false;
    }

    if (possible) console.log("YES");
    else console.log("NO");
  }
}


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

function solve(a, b, x) {
    while (a) {
        const r = b % a
        // b, b - a, b - 2 * a, ..., r
        if (x === a) return 'YES'
        if (x >= r && x <= b && !((b - x) % a)) return 'YES'
        b = a
        a = r
    }
    return 'NO'
}

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));
const rbna = () => ra().map(x => BigInt(x));

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

function main () {
	let T = rn();
	while (T--) {
		let [a, b, x] = rbna();

		function get (a, b, x) {
			// normalize a and b
			if (a > b) [a, b] = [b, a];
			if (b - a < a) a = b - a;

			if (x == b) return true;
			if (x > b || a == 0) return false;
			if ((b - x) % a == 0) return true;
			return get(a, a + b % a, x);
		}

		console.log(get(a, b, x) ? 'YES' : 'NO');
	}
}

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));
const rbna = () => ra().map(x => BigInt(x));

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

function main () {
	let T = rn();
	while (T--) {
		let [a, b, x] = rbna();

		function get (a, b, x) {
			if (a > b) [a, b] = [b, a];
			if (b - a < a) a = b - a;
			if (x == b) return true;
			if (x > b || a == 0 || b == 0) return false;
			if ((b - x) % a == 0) return true;
			return get(a, a + b % a, x);
		}

		console.log(get(a, b, x) ? 'YES' : 'NO');
	}
}