/*
** <problem_number> - <problem_title>
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

function main() {
    let testcases = parseInt(readline())

    while (testcases--) {
        let str = readline().split('')
        let left = 0
        let right = str.length - 1

        while(str[left] == str[right]){
            if(left >= right) break
            left++
            right--
        }

        while(str[left] == str[left+1]) {
            if(left >= right) break
            left += 2
        }

        ( left <= right ) ? console.log('Alice') : console.log('Draw')
    }
}

const util = require("util")

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

//

function main() {
    let t = parseInt(readLine())
    while (t--) {
        let str = readLine()
        const n = str.length
        str = "a"+str+"a"
        let f = []
        for (let i = 0; i <= n+1; i ++) {
            f[i] = []
            for (let j = 0; j <= n+1; j++) {
                f[i][j] = i > j
            }
        }
        // console.log(util.inspect(f, {depth: null, colors: true}))
        for (let len = 2; len <= n; len += 2) {
            for (let i = 1; i + len - 1 <= n; i ++) {
                let j = i + len - 1
                if (str[i] === str[i+1] && str[j-1] === str[j]) {
                    f[i][j] = f[i][j] || (f[i+2][j] && f[i][j-2])
                }
                if (str[i] === str[j]) {
                    f[i][j] = f[i][j] || f[i+1][j-1]
                }
            }
        }
        if (f[1][n]) {
            console.log("Draw")
        } else {
            console.log("Alice")
        }
    }
}

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const s = read(),
        n = s.length;
  if (n % 2 == 0) {
    const cache = Array.from({
      length: n
    }, () => new Map());
    const dfs = (i, j, p) => {
      if (j - i === 1) {
        if (s[i] === s[j]) return 0;
        return 1;
      }
      if (cache[i].has(j)) return cache[i].get(j);
      let res = 1;
      if (j - i & 1) {
        let a = dfs(i + 1, j, s[i]),
            b = dfs(i, j - 1, s[j]);
        if (a === -1 && b === -1) {
          res = -1;
        } else if (a === 0 && b === 0) {
          res = 0;
        }
        cache[i].set(j, res);
      } else {
        let a = dfs(i + 1, j, s[i]),
            b = dfs(i, j - 1, s[j]);
        if (a === 0 && s[i] < p || b === 0 && s[j] < p) {
          res = -1;
        } else if (a === 0 && s[i] === p || b === 0 && s[j] === p) {
          res = 0;
        }
      }
      return res;
    };
    let res = dfs(0, n - 1, '');
    if (res === 0) return 'Draw';else if (res === 1) return 'Alice';
    return 'Bob';
  }
  return 'Bob';
}

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

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

const readline = require('readline')

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

function solve(str) {
    const n = str.length
    let prev
    for (let l = 2; l <= n; l += 2) {
        const dp = Array(n)
        for (let i = 0; i + l - 1 < n; i++) {
            if (l === 2) {
                dp[i] = Math.min(
                    cmp(0, str[i], str[i + 1]),
                    cmp(0, str[i + 1], str[i])
                )
                continue
            }
            const a = Math.max(
                cmp(prev[i + 2], str[i], str[i + 1]),
                cmp(prev[i + 1], str[i], str[i + l - 1])
            )
            const b = Math.max(
                cmp(prev[i], str[i + l - 1], str[i + l - 2]),
                cmp(prev[i + 1], str[i + l - 1], str[i])
            )
            dp[i] = Math.min(a, b)
        }
        // console.log(dp)
        prev = dp
    }
    return prev[0] < 0 ? 'Alice' : (prev[0] > 0 ? 'Bob' : 'Draw')

    function cmp(sub, a, b) {
        if (sub === 0) {
            return a < b ? -1 : (a > b ? 1 : 0)
        } else {
            return sub
        }
    }
}

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const s = read(),
        n = s.length;
  if (n % 2 == 0) {
    const cache = Array.from({
      length: n
    }, () => new Map());
    const dfs = (i, j) => {
      if (j - i === 1) {
        return s[i] !== s[j];
      }
      if (cache[i].has(j)) return cache[i].get(j);
      if (j - i & 1) {
        if (s[i] !== s[j]) return true;
      }
      let a = dfs(i + 1, j),
          b = dfs(i, j - 1);
      if (a && b) {
        cache[i].set(j, false);
        return false;
      }
      cache[i].set(j, true);
      return true;
    };
    if (dfs(0, n - 1)) return 'Alice';
    return 'Draw';
  }
  return 'Bob';
}

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

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const s = read(),
        n = s.length;
  if (n % 2 == 0) {
    const cache = Array.from({
      length: n
    }, () => new Map());
    const dfs = (i, j) => {
      if (j - i === 1) {
        return s[i] === s[j];
      }
      if (cache[i].has(j)) return cache[i].get(j);
      if (j - i & 1) {
        let a = dfs(i + 1, j),
            b = dfs(i, j - 1);
        if (a && b) {
          cache[i].set(j, true);
          return true;
        }
        cache[i].set(j, false);
        return false;
      } else {
        if (dfs(i + 1, j) || dfs(i, j - 1)) {
          cache[i].set(j, true);
          return true;
        }
        cache[i].set(j, false);
        return false;
      }
    };
    if (dfs(0, n - 1)) return 'Draw';
    return 'Alice';
  }
  return 'Bob';
}

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

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const s = read(),
        n = s.length;
  if (n % 2 == 0) {
    let flag = true;
    for (let i = 0, j = n - 1; i < j; i++, j--) {
      if (s[i] !== s[j]) {
        flag = false;
        break;
      }
    }
    if (flag) return 'Draw';else return 'Alice';
  }
  return 'Bob';
}

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

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const s = read();
  const strs = [[], []];
  for (let i = 0, j = s.length - 1; i <= j;) {
    let k = i + (s.length - j - 1) & 1;
    if (s[i] <= s[j]) strs[k].push(s[i++]);else strs[k].push(s[j--]);
  }
  const [a, b] = strs;
  a.reverse();
  b.reverse();
  const n = Math.max(strs.length, b.length);
  for (let i = 0; i < n; i++) {
    if (a[i] === b[i]) continue;
    if (a[i] === undefined || a[i] < b[i]) return 'Alice';else return 'Bob';
  }
  return 'Draw';
}

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

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const s = read();
  const a = [],
        b = [];
  for (let i = 0, j = s.length - 1; i < j; i++, j--) {
    let [x, y] = [s[i], s[j]];
    if (x > y) [x, y] = [y, x];
    a.push(x);
    if (i < j - 1) b.push(y);
  }
  a.reverse();
  b.reverse();
  const n = Math.max(a.length, b.length);
  for (let i = 0; i < n; i++) {
    if (a[i] === b[i]) continue;
    if (a[i] === undefined || a[i] < b[i]) return 'Alice';else return 'Bob';
  }
  return 'Draw';
}

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

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const s = read();
  let l = 0,
      r = s.length - 1;
  while (l < r - 1) {
    if (s[l] === s[r]) {
      l++;
      r--;
    } else return 'Alice';
  }
  if (l === r - 1) return 'Draw';
  return 'Bob';
}

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

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

/*
** <problem_number> - <problem_title>
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

function main() {
    let testcases = parseInt( readline() )

    while(testcases--) {
        let str = readline()
        let alice = bob = ''

        let round = 1, moves = str.length
        while( str !== '' ){
            let firstChar = str.charAt(0)
            let lastChar = str.charAt(str.length - 1)
            let pickedChar = ''

            if( firstChar <= lastChar ) {
                pickedChar = firstChar
                str = str.substring(1)
            } else {
                pickedChar = lastChar
                str = str.substring(0, str.length - 1)
            }

            if( round % 2 == 1 ) alice = pickedChar.concat(alice)
            else bob = pickedChar.concat(bob)

            round++
        }

        if( alice == bob ) console.log('Draw')
        else console.log('Alice')
    }
}

/*
** <problem_number> - <problem_title>
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

function main() {
    let testcases = parseInt( readline() )

    while(testcases--) {
        let str = readline()
        let alice = bob = ''

        let re = /[\W_]/g;
        let lowRegStr = str.toLowerCase().replace(re, '');
        let reverseStr = lowRegStr.split('').reverse().join('');
        if( reverseStr === lowRegStr ) console.log('Draw')
        else {

            let round = 1
            while( str !== '' ){
                let first = str.charAt(0)
                let last = str.charAt(str.length - 1)
                let picked = ''

                if( first > last ) {
                    picked = last
                    str = str.substring(0, str.length - 1)
                } else if( first < last ){
                    picked = first
                    str = str.substring(1)
                } else {
                    if( round % 2 == 1 ) {
                        picked = last
                        str = str.substring(0, str.length - 1)
                    } else {
                        picked = first
                        str = str.substring(1)
                    }
                }

                if( round % 2 == 1 ) alice = picked.concat(alice)
                else bob = picked.concat(bob)

                round++
            }

            if( alice < bob ) console.log('Alice')
            if( alice > bob ) console.log('Bob')
            if( alice == bob ) console.log('Draw')

        }

    }
}

/*
** <problem_number> - <problem_title>
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

function main() {
    let testcases = parseInt( readline() )

    while(testcases--) {
        let str = readline()
        let alice = bob = ''

        let round = 1, moves = str.length
        while( str !== '' ){
            let firstChar = str.charAt(0)
            let lastChar = str.charAt(str.length - 1)
            let pickedChar = ''

            if( firstChar <= lastChar ) {
                pickedChar = firstChar
                str = str.substring(1)
            } else {
                pickedChar = lastChar
                str = str.substring(0, str.length - 1)
            }

            if( round % 2 == 1 ) alice = pickedChar.concat(alice)
            else bob = pickedChar.concat(bob)

            round++
        }

        if( alice < bob ) console.log('Alice')
        if( alice > bob ) console.log('Bob')
        if( alice == bob ) console.log('Draw')
    }
}

/*
** <problem_number> - <problem_title>
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

function main() {
    let testcases = parseInt( readline() )

    while(testcases--) {
        let str = readline()
        let alice = bob = ''

        let round = 1, moves = str.length
        while( str !== '' ){
            let firstChar = str.charAt(0)
            let lastChar = str.charAt(str.length - 1)
            let pickedChar = ''

            if( firstChar < lastChar ) {
                pickedChar = firstChar
                str = str.substring(1)
            } else {
                pickedChar = lastChar
                str = str.substring(0, str.length - 1)
            }

            if( round % 2 == 1 ) alice = pickedChar.concat(alice)
            else bob = pickedChar.concat(bob)

            round++
        }

        if( alice < bob ) console.log('Alice')
        if( alice > bob ) console.log('Bob')
        if( alice == bob ) console.log('Draw')
    }
}

/*
** <problem_number> - <problem_title>
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

function main() {
    let str = readline()
    let alice = bob = ''

    let round = 1, moves = str.length
    while( str !== '' ){
        let firstChar = str.charAt(0)
        let lastChar = str.charAt(str.length - 1)
        let pickedChar = ''

        if( firstChar < lastChar ) {
            pickedChar = firstChar
            str = str.substring(1)
        } else {
            pickedChar = lastChar
            str = str.substring(0, str.length - 1)
        }

        if( round % 2 == 1 ) alice = pickedChar.concat(alice)
        else bob = pickedChar.concat(bob)

        round++
    }

    if( alice < bob ) console.log('Alice')
    if( alice > bob ) console.log('Bob')
    if( alice == bob ) console.log('Draw')
}

const util = require("util")

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

//

function main() {
    let t = parseInt(readLine())
    while (t--) {
        let str = readLine()
        const n = str.length
        str = "x"+str+"x"
        let f = []
        for (let i = 0; i <= n+1; i ++) {
            f[i] = []
            for (let j = 0; j <= n+1; j++) {
                f[i][j] = []
                for (let k = 0; k < 2; k++) {
                    f[i][j][k] = []
                    for (let l = 0; l < 2; l++) {
                        f[i][j][k][l] = i >= j;
                    }
                }
            }
        }
        // console.log(util.inspect(f, {depth: null, colors: true}))
        for (let len = 2; len <= n; len += 2) {
            for (let i = 1; i + len - 1 <= n; i ++) {
                let j = i + len - 1
                let left = str[i] === str[i+1] ? 1 : 0
                let right = str[j-1] === str[j] ? 1 : 0
                if (str[i] === str[i+1]) {
                    let res = f[i+2][j][0][1] || f[i+2][j][1][1]
                    f[i][j][left][right] = f[i][j][left][right] || res
                }
                if (str[j-1] === str[j]) {
                    let res = f[i][j-2][1][0] || f[i][j-2][1][1]
                    f[i][j][left][right] = f[i][j][left][right] || res
                }
                if (str[i] === str[j]) {
                    let res = cum(f[i+1][j-1])
                    f[i][j][left][right] = f[i][j][left][right] || res
                }
                // console.log(`${i}-${j}-${str.slice(i,j+1)}\t${f[i][j][left][right]}`)
            }
        }
        if (cum(f[1][n])) {
            console.log("Draw")
        } else {
            console.log("Alice")
        }
    }
}

function cum(f) {
    let res = false
    for (let k = 0; k < 2; k ++)
        for (let l = 0; l < 2; l ++) {
            res = res || f[k][l]
        }
    return res
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

//

function main() {
    let t = parseInt(readLine())
    while (t--) {
        let oldStr = readLine()
        let newStr = ""
        while (oldStr !== "") {
            let i = 0
            while (i < oldStr.length) {
                if (i < oldStr.length - 1 && oldStr[i] === oldStr[i+1]) {
                    i += 2
                    continue
                }
                newStr += oldStr[i]
                i ++
            }
            // console.log(oldStr, newStr)
            if (oldStr === newStr) break
            oldStr = newStr
            newStr = ""
        }
        if (newStr === "") {
            console.log("Draw")
        } else {
            console.log("Alice")
        }
    }
}


'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        a = rns();
  const l = [a[0]];
  for (let i = 1; i < n; i++) {
    if (i & 1) {
      l[i] = l[i - 1] - a[i];
    } else {
      l[i] = l[i - 1] + a[i];
    }
  }
  const r = [];
  r[n - 1] = a[n - 1];
  const odd = new Map(),
        even = new Map();
  for (let i = n - 1; i >= 0; i--) {
    if (i < n - 1) {
      if (n - i - 1 & 1) {
        r[i] = a[i] - r[i + 1];
      } else {
        r[i] = a[i] - r[i + 1];
      }
    }
    if (i & 1) {
      if (!odd.has(r[i])) odd.set(r[i], []);
      odd.get(r[i]).push(i);
    } else {
      if (!even.has(r[i])) even.set(r[i], []);
      even.get(r[i]).push(i);
    }
  }
  for (let [key, arr] of odd) arr.reverse();
  for (let [key, arr] of even) arr.reverse();
  const find = arr => {
    while (arr.length && arr[arr.length - 1] > right) arr.pop();
    if (arr.length && arr[arr.length - 1] > left) {
      const ans = arr[arr.length - 1];
      pre = r[ans];
      sum = d = 0;
      res.push([pl, left], [ans, right]);
      right = ans - 1;
      pl = left + 1;
      return true;
    }
    return false;
  };
  let sum = 0,
      pre = 0,
      res = [];
  let left = 0,
      right = n - 1,
      d = 0,
      pl = 0;
  for (; left <= right; left++) {
    if (d & 1) {
      sum -= a[left];
    } else {
      sum += a[left];
    }
    if (sum === 0) {
      res.push([pl, left]);
      pl = left + 1;
      sum = d = 0;
      continue;
    }
    d++;
    if (right & 1) {
      let t = -sum - pre;
      if (odd.has(t)) {
        if (find(odd.get(t))) {
          continue;
        }
      }
      t = -sum + pre;
      if (even.has(t)) {
        if (find(even.get(t))) {
          continue;
        }
      }
    } else {
      let t = -sum - pre;
      if (even.has(t)) {
        if (find(even.get(t))) {
          continue;
        }
      }
      t = -sum + pre;
      if (odd.has(t)) {
        if (find(odd.get(t))) {
          continue;
        }
      }
    }
  }
  res.sort((a, b) => a[0] - b[0]);
  const check = arr => {
    var _arr$, _arr;
    if (((_arr$ = arr[0]) === null || _arr$ === void 0 ? void 0 : _arr$[0]) !== 0 || ((_arr = arr[arr.length - 1]) === null || _arr === void 0 ? void 0 : _arr[1]) !== n - 1) return false;
    for (let i = 1; i < arr.length; i++) {
      if (arr[i][0] !== arr[i - 1][1] + 1) return false;
    }
    return true;
  };
  if (!check(res)) return -1;
  return `${res.length}\n${res.map(arr => arr.map(num => num + 1).join(' ')).join('\n')}`;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

const readline = require('readline')

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

function solve(n, arr) {
    const sum = arr.reduce((s, x) => s + x, 0)
    // if (!sum) {
    //     return `1\n1 ${n}`
    // }
    const t = sum > 0 ? 1 : -1
    let k = sum / t
    if (k & 1) return -1
    k /= 2
// console.log('k', k)
    const use = Array(n)
    const ans = []
    for (let i = 1; i < arr.length; i++) {
        if (k > 0 && arr[i] === t && !use[i - 1]) {
            use[i - 1] = 1
            use[i] = 1
            // ans.push([i - 1, i])
            ans.push([i, i + 1])
            k--
        }
    }
    if (k > 0) return -1
    for (let i = 0; i < arr.length; i++) {
        if (!use[i]) {
            ans.push([i + 1, i + 1])
        }
    }
    ans.sort((a, b) => a[0] - b[0])
    return ans.length + '\n' + ans.map(x => x.join(' ')).join('\n')
}


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

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

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

function main() {
  let q = parseInt(readline());
  for (let i = 0; i < q; i++) {
    readline();
    let mat = [];
    let got = false;
    for (let j = 0; j < 8; j++) mat.push(readline());
    for (let j = 0; j < 8; j++) {
      for (let k = 0; k < 8; k++) {
        if (mat[j][k] == "#") {
          let type = "r";
          if (j + 1 < 8 && k - 1 >= 0 && mat[j + 1][k - 1] == "#") type = "l";
          print(Travel(j, k, mat, type).join(" "));
          got = true;
          break;
        }
      }
      if (got) break;
    }
  }
}

function Travel(i, j, mat, type) {
  if (Bisop(i, j, mat)) return [i + 1, j + 1];
  if (type == "r") return Travel(i + 1, j + 1, mat, type);
  else return Travel(i + 1, j - 1, mat, type);
}
function Bisop(i, j, mat) {
  if (i + 1 >= 8 || j + 1 >= 8 || i - 1 < 0 || j - 1 < 0) return false;
  return mat[i + 1][j + 1] == "#" && mat[i - 1][j - 1] == "#" && mat[i + 1][j - 1] == "#" && mat[i - 1][j + 1] == "#";
}

const solve = (arr,n)=>{
     let flag = 0;
     for(let i=0;i<n;i++){
          let cnt = 0,ind;
          for(let j=0;j<n;j++){
               if(arr[i][j]==="#") {
                    cnt++;
                    ind = j;
               }
          }
          if(cnt===2) flag = 1;
          if((flag===1)&&(cnt===1)) return `${i+1} ${ind+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 = 8,arr=[];
       readline();
       for(let i=0;i<n;i++)
          arr.push(readline().trim().split(""));
       console.log(solve(arr,n));
  }
}
main();

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

function main() {
    let n = readline()
    let prev = ''
    let pos = ''

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

        for (let y = 0; y < 8; y++) { // top to bottom loop
            let row = readline()

            if (prev) {
                for (x = 0; x < row.length; x++) { // left to right
                    if (row[x] == '#' && prev[x - 1] == '#' && prev[x + 1] == '#') {

                        let r = x + 1
                        let c = y + 1
                        pos = c + ' ' + r
                    }
                }
            }

            prev = row
        }

        console.log(pos)
        pos = ''
    }
}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine() {
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace("\r", "");
}

function print(x) {
    console.log(x);
}

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine()
        .split(" ")
        .map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function solve() {
    let t = readSingleInt();
    const boundary = `**********`;
    while (t--) {
        let emptyLine = readLine();
        let grid = [];
        grid.push(boundary);
        for (let i = 0; i < 8; i++) {
            grid.push(`${'*'}${readLine()}${'*'}`);
        }
        grid.push(boundary);
        for(let i=2;i<8;i++)
        {
            for(let j=2;j<8;j++){
            let cnt = 0;
            // const {row ,column} = locationsOfBis[i];
            let row = i,column=j;

            //check upper left
            if(grid[row-1][column-1]=='#'){
                cnt++;
            }
            //check upper right
            if(grid[row-1][column+1]=='#'){
                cnt++;
            }
            //check lower left
            if(grid[row+1][column-1]=='#'){
                cnt++;
            }
            //check lower right
            if(grid[row+1][column+1]=='#'){
                cnt++;
            }

            if(cnt==4){
                console.log(`${row} ${column}`);
                break;
            }
        }

        }

    }
}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine() {
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace("\r", "");
}

function print(x) {
    console.log(x);
}

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine()
        .split(" ")
        .map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function solve() {
    let t = readSingleInt();
    const boundary = `**********`;
    while (t--) {
        let emptyLine = readLine();
        let grid = [];
        grid.push(boundary);
        for (let i = 0; i < 8; i++) {
            grid.push(`${'*'}${readLine()}${'*'}`);
        }
        grid.push(boundary);
        let locationsOfBis = [];
        let location = [];
        grid.forEach((v, idx) => {
            let mp = [];
            Array.from(v).forEach((d, id) => {
                if (d == '#'){
                    mp.push({ row: idx, column: id });

                }
            })
            if(mp.length==1){
               let  r = mp[0].row,c = mp[0].column;
               if(r>1 && r<8 && c>1 && c<8){

                   locationsOfBis.push(mp[0]);
               }
            }
            location.push(...mp);

        })
        for(let i=0;i<locationsOfBis.length;i++)
        {
            let cnt = 0;
            const {row ,column} = locationsOfBis[i];

            //check upper left
            if(grid[row-1][column-1]=='#'){
                cnt++;
            }
            //check upper right
            if(grid[row-1][column+1]=='#'){
                cnt++;
            }
            //check lower left
            if(grid[row+1][column-1]=='#'){
                cnt++;
            }
            //check lower right
            if(grid[row+1][column+1]=='#'){
                cnt++;
            }

            if(cnt==4){
                console.log(`${row} ${column}`);
                break;
            }

        }

    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

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

    function check(r, c, arr) {
        return arr[r-1][c-1] && arr[r-1][c+1] && arr[r+1][c-1] && arr[r+1][c+1];
    }

    for (let test = 0; test < N; test++) {
        readline();
        let rows = new Array(8);
        for (let i = 0; i < 8; i++) {
            rows[i] = readline().split('').map(c => c === '#' ? true : false);
        }

        let resC;
        let resR;
        for (let r = 1; r < 7; r++) {
            for (let c = 1; c < 7; c++) {
                if (check(r, c, rows)) {
                    resC = c + 1;
                    resR = r + 1;
                    break;
                }
            }
        }

        output(resR + ' ' + resC);
    }
}

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

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

    const board = [];
    for (let j = 0; j < 8; j++) {
      board.push(lines[t++].split(''));
    }

    for (let z = 1; z < 7; z++) {
      for (let y = 1; y < 7; y++) {
        if (board[z][y] === '#') {
          const a = [[-1, -1], [1, 1], [-1, 1], [1, -1]];
          let flag = true;
          for (let x = 0; x < a.length; x++) {
            if (board[z + a[x][0]][y + a[x][1]] !== '#') {
              flag = false;
              break;
            }
          }
          if (flag) {
            res.push(`${z + 1} ${y + 1}`);
            break;
          }
        }
      }
    }
  }

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

const readline = require('readline')

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
})
const lines = []
rl.on('line', (input) => {
  lines.push(input);
})
rl.on('close', () => {
  console.log(Solution());
});

/*
** 799A
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let is = "";
let cl = 0;

process.stdin.on("data", (inp) => {
    is += inp;
});

process.stdin.on("end", (_) => {
    is = is.trim().split("\n").map((s) => s.trim());
    main();
});

const readline = () => is[cl++];
// Common Template Ends //

function main() {
    let n = readline();
    while (n--) {
        readline();
        const lines = [...Array(8)].map(_ => readline());
        const yy = lines.map((l, i) => l.indexOf('#.#') !== -1 ? i : -1).filter(n => n != -1);
        const x = lines[yy[0]].indexOf('#') + 2;
        const y = yy.length === 2 ? (yy[0] + yy[1]) / 2 + 1 : (yy[0] < 2 ? yy[0] : yy[0] + 2)

        console.log(`${y} ${x}`);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

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

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

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

function main() {
    const n = parseInt(readline());

    for(var i=0; i<n; i++){
        (readline());
        var d = [];
        for(var j=0; j<8; j++){
            var x = [];
            var m = readline();
            var had1 = 0, index = 0;
            for(var k=0; k<8; k++){
                const cc = m.charAt(k);
                x.push(cc);

                if(cc=="#"){
                    had1++;
                    index = k;
                }
            }
            d.push(x);
            if(had1==1 && j > 0 && j < 7 && d[j-1][index-1]=="#" && d[j-1][index+1]=="#"){
                foo(`${j+1} ${index+1}`);
            }
        }
    }
}
function foo(x) {
    process.stdout.write(x);   // without auto '\n' (newline)
    console.log();  // with auto '\n' (newline)
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		next();
		var list = nextStrArray(8);
		var ok = false;
		var output = "";
		for(var i = 1; i < 8; i++){
			for(var j = 1; j < 8; j++){
				if(list[i][j] == "#" && list[i - 1][j - 1] == "#" && list[i - 1][j + 1] == "#"
					&& list[i + 1][j - 1] == "#" && list[i + 1][j + 1] == "#"){
					output = (i + 1) + " " + (j + 1);
				}
			}
		}
		myout(output);
	}
}

'use strict';

function solve(a) {
  for (let i = 0; i < 8; i++) {
    for (let j = 0; j < 8; j++) {
      if (a[i][j] === '#') {
        var _a, _a2, _a3, _a4;
        if (((_a = a[i - 1]) === null || _a === void 0 ? void 0 : _a[j - 1]) === '#' && ((_a2 = a[i - 1]) === null || _a2 === void 0 ? void 0 : _a2[j + 1]) === '#' && ((_a3 = a[i + 1]) === null || _a3 === void 0 ? void 0 : _a3[j - 1]) === '#' && ((_a4 = a[i + 1]) === null || _a4 === void 0 ? void 0 : _a4[j + 1]) === '#') return `${i + 1} ${j + 1}`;
      }
    }
  }
}

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

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

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

function solve(grid) {
    // console.log(grid)
    for (let i = 1; i < grid.length - 1; i++) {
        for (let j = 1; j < grid[i].length - 1; j++) {
            const a = [
                [i, j],
                [i - 1, j - 1],
                [i - 1, j + 1],
                [i + 1, j - 1],
                [i + 1, j + 1],
            ].every(([x, y]) => grid[x][y] === '#')
            if (a) return [i + 1, j + 1].join(' ')
        }
    }
}

var array = [],x,y,hashtag,found;

var tests = readline();
var found = false;
var pass = false;
while(tests--){
    readline();
    found = false;
    pass = false;
    for(var t = 0;t<8;t++)
    {
         array = readline();
        if(!pass){
        splinter = array.split('#');
        if(splinter.length == 2 && found)
        {
            print(parseInt(t+1) + " " + parseInt(array.indexOf("#") + 1));
            pass = true;
        }
        else if(splinter.length == 3) found = true;
        }
    }
}

var t = +readline();

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

    var t1 = readline();
    var list = [];
    for (var q = 0; q<8;q++){
      var just = readline();
      list.push(just);
    }
      var testone = Task2(list);
    print(testone[0],testone[1])
}

function Task2 (arr){

   function isBishop(i,j){

      var ll = j;
      for(var l = i; l>= 0; l--){
         if (ll < 0) break;
         if (arr[l][ll] != '#') {
            return false;
         }
         ll--;
      }

      var lr = j;
      for(var l1 = i; l1>= 0; l1--){
         if (lr < 0 || lr >= arr.length) break;
         if (arr[l1][lr] != '#') return false;
         lr++;
      }
      var rr = j;
      for(var l2 = i; l2< arr.length; l2++){
         if (rr < 0 || rr >= arr.length) break;
         if (arr[l2][rr] != '#') return false
         ;
         rr++;
      }

      var rl = j;
      for(var l3 = i; l3< arr.length; l3++){
         if (rl < 0 || rl >= arr.length) break;
         if (arr[l3][rl] != '#') return false;
         rl--;
      }

      return true;

   }

   var just = [];

   for(var i = 0; i<arr.length; i++){

      for(var j = 0; j<arr.length; j++){
         if (arr[i][j] == '#') {
            if (isBishop(i,j)) {
                  just.push([i+1,j+1])
            }
         }
      }
   }

   return just.length >= 2 ? just[1] : just[0]

}

const solve = (arr,n)=>{
     let flag = 0;
     for(let i=0;i<n;i++){
          let cnt = 0,ind;
          for(let j=0;j<n;j++){
               if(arr[i][j]==="#") {
                    cnt++;
                    ind = j;
               }
          }
          if(cnt===2) flag = 1;
          if((flag===1)&&(cnt===1)) return `${i+1} ${ind+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 = 8,arr=[];
       for(let i=0;i<n;i++)
          arr.push(readline().trim().split(""));
       console.log(solve(arr,n));
  }
}
main();

/* Common Template Starts */
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/* Common Template Ends */

function main() {
    let n = readline()
    let prev = ''
    let pos = ''

    for (let i = 0; i < n; i++) {
        for (let y = 0; y < 8; y++) { // top to bottom loop
            let row = readline()

            if (prev) {
                for (x = 0; x < row.length; x++) { // left to right
                    if (row[x] == '#' && prev[x - 1] == '#' && prev[x + 1] == '#') {

                        let r = x + 1
                        let c = y + 1
                        pos = c + ' ' + r
                    }
                }
            }

            prev = row
        }

        console.log(pos)
        pos = ''
    }
}


"use strict";
let For = (a, b, fn) => {
    if (!fn)
        return For(0, a - 1, b);
    let res;
    for (let i = a; i <= b; i++) {
        if ((res = fn(i)) != null)
            return res;
    }
};
let ForR = (a, b, fn) => {
    if (!fn)
        return ForR(a - 1, 0, b);
    let res;
    for (let i = a; i >= b; i--) {
        if ((res = fn(i)) != null)
            return res;
    }
};
let Arr = (a, b, fn) => {
    if (typeof (b) == 'function')
        return Arr(0, a - 1, b);
    if (b < a)
        return [];
    let arr = Array(b - a + 1);
    for (let i = a; i <= b; i++)
        arr[i] = fn(i, arr);
    return arr;
};
Object.defineProperty(Object.prototype, '$k', {
    value: function () { return Object.keys(this); }
});
Object.defineProperty(Object.prototype, '$v', {
    value: function () { return Object.values(this); }
});
Object.defineProperty(Object.prototype, '$kv', {
    value: function () { return Object.entries(this); }
});
// Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
// Array.prototype.uniq = function (fn) {
//   var set = new Set();
//   return this.filter(v => {
//     var newValue = !set.has(fn ? fn(v) : v);
//     set.add(fn ? fn(v) : v);
//     return newValue;
//   });
// }
// Array.prototype.toObj = function (fn) {
//   return this.map(v => fn ? fn(v) : v).reduce((p, v) => {
//     p[v[0]] = v[1];
//     return p;
//   }, {})
// }
// Array.prototype.min = function (fn) {
//   let min = 1e20, index = -1, x;
//   for (let i = 0; i < this.length; i++) {
//     x = fn ? fn(this[i], i, this) : this[i];
//     if (x < min) { min = x; index = i }
//   }
//   return [this[index], index, min];
// }
// Array.prototype.max = function (fn) {
//   let max = -1e20, index = -1, x;
//   for (let i = 0; i < this.length; i++) {
//     x = fn ? fn(this[i], i, this) : this[i];
//     if (x > max) { max = x; index = i }
//   }
//   return [this[index], index, max];
// }
// Array.prototype.rev = function (first, last) {
//   for (let i = first; i < (first + last) / 2; i++) {
//     [this[i], this[last - 1 - i + first]] = [this[last - 1 - i + first], this[i]]
//   }
// }
// Array.prototype.set = function (pos, arr) {
//   for (let i = pos; i < pos + arr.length; i++) {
//     this[i] = arr[i - pos];
//   }
// }
// Array.prototype.for = function (a, b, fn) {
//   let res
//   for (let i = a; i <= b; i++) {
//     if ((res = fn(this[i], i, this)) != null) return res;
//   }
// }
// Array.prototype.forR = function (a, b, fn) {
//   let res
//   for (let i = a; i >= b; i--) {
//     if ((res = fn(this[i], i, this)) != null) return res;
//   }
// }
// Array.prototype.bin = function (comp, a, b) {
//   let mid;
//   while (a < b) {
//     mid = (a + b) / 2 | 0;
//     if (typeof comp == 'function' ? comp(this[mid]) : this[mid] < comp) a = mid + 1;
//     else b = mid;
//   }
//   return a;
// }
// Array.prototype.cut = function (fn, a, b) {
//   let arr = [];
//   a = a || 0;
//   b = b || (this.length - 1);
//   let prev = a;
//   for (let i = a; i <= b; i++) {
//     if (i == b || fn(this[i], this[i + 1])) {
//       arr.push(this.slice(prev, i + 1));
//       prev = i + 1;
//     }
//   }
//   return arr;
// }
function gcd(a, b) {
    while (b)
        [a, b] = [b, a % b];
    return a;
}
function mul(a, b, m) {
    return ((a >> 16) * b % m * 65536 + (a & 65535) * b) % m;
}
function pow(a, n, m) {
    let r = 1;
    while (n)
        n & 1 ? (r = mul(r, a, m), n--) : [a, n] = [mul(a, a, m), n >> 1];
    return r;
}
function inv(b, m) {
    for (var a = m, u = 0, v = 1, t; b; v = t)
        (t = a / b | 0, a -= t * b, u -= t * v, t = a, a = b, b = t, t = u, u = v);
    return (u + m) % m;
}
// let MOD = 1e9 + 7
// let gt = Arr(n, (i, a) => i == 0 ? 1 : mul(a[i - 1], i, MOD));
// let rgt = Arr(n, (i, a) => i <= 1 ? 1 : MOD - mul((MOD / i | 0), a[MOD % i], MOD));
// For(2, n - 1, i => { rgt[i] = mul(rgt[i], rgt[i - 1], MOD) });
// let nCk = (n, k) => mul(mul(gt[n], rgt[k], MOD), rgt[n - k], MOD);
// for (i = pos; i <= n; i += i & -i) fen[i]++; // start from index 1
// for (i = pos; i; i -= i & -i) ans += fen[i];
// let p = [2];
// for (let i = 3; i < 1e5; i += 2) {
//   let j, x = Math.sqrt(i);
//   for (j = 0; p[j] <= x; j++) if (i % p[j] == 0) break;
//   if (i % p[j] != 0) p.push(i);
// }
// let root = x => par[x] < 0 ? x : (par[x] = root(par[x]));
// let dsu = (x, y) => {
//   if ((x = root(x)) == (y = root(y))) return;
//   if (par[y] < par[x]) [x, y] = [y, x];
//   par[x] += par[y];
//   par[y] = x;
// }
let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
    let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = (n) => n != null ? inp.slice(_i, _i += n) : inp[_i++], out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
    let [n, m] = $(2), s = 1, z = 1e6;
    let h1 = [], h2 = [];
    For(n, i => {
        let [y, l, r] = $(3);
        if (l == 0 && r == z)
            s++;
        if (l == 0)
            h1.push({ y, r });
        else
            h2.push({ y, l });
    });
    h1.sort((a, b) => a.r - b.r);
    h2.sort((a, b) => a.l - b.l);
    let bit1 = Arr(z + 1, i => 0), bit2 = Arr(z + 1, i => 0);
    let update = (pos, x) => {
        for (let i = pos; i <= z; i += i & -i)
            bit1[i] += x;
        for (let i = z - pos; i <= z; i += i & -i)
            bit2[i] += x;
    };
    let cal1 = pos => {
        let res = 0;
        for (let i = pos; i; i -= i & -i)
            res += bit1[i];
        return res;
    };
    let cal2 = pos => {
        let res = 0;
        for (let i = z - pos; i; i -= i & -i)
            res += bit2[i];
        return res;
    };
    let v = Arr(m, i => ({ x: $(), l: $(), r: $() }));
    v.sort((a, b) => a.x - b.x);
    let i1 = 0, i2 = 0;
    h1.forEach(h => update(h.y, 1));
    v.forEach(v => {
        while (i1 < h1.length && h1[i1].r < v.x) {
            update(h1[i1].y, -1);
            i1++;
        }
        while (i2 < h2.length && h2[i2].l <= v.x) {
            update(h2[i2].y, 1);
            i2++;
        }
        // log(s, cal1(v.l), cal2(v.l));
        if (v.l == 0 && v.r == z)
            s++;
        if (v.l == 0)
            s += cal1(v.r);
        else
            s += cal2(v.l);
    });
    log(s);
}

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

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

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

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

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

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

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

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
  let [n, m] = $(2), s = 1; z = 1e6;
  let h1 = [], h2 = [];
  For(n, i => {
    let [y, l, r] = $(3)
    if (l == 0 && r == z) s++;
    if (l == 0) h1.push({ y, r });
    else h2.push({ y, l })
  })
  h1.sort((a, b) => a.r - b.r);
  h2.sort((a, b) => a.l - b.l);

  let bit1 = Arr(z + 1, i => 0), bit2 = Arr(z + 1, i => 0)

  let update = (pos, x) => {
    for (let i = pos; i <= z; i += i & -i) bit1[i] += x;
    for (let i = z - pos; i <= z; i += i & -i) bit2[i] += x;
  }
  let cal1 = pos => {
    let res = 0;
    for (let i = pos; i; i -= i & -i) res += bit1[i];
    return res;
  }
  let cal2 = pos => {
    let res = 0;
    for (let i = z - pos; i; i -= i & -i) res += bit2[i];
    return res;
  }

  let v = Arr(m, i => ({ x: $(), l: $(), r: $() }))
  v.sort((a, b) => a.x - b.x);

  let i1 = 0, i2 = 0;
  h1.forEach(h => update(h.y, 1));
  v.forEach(v => {
    while (i1 < h1.length && h1[i1].r < v.x) {
      update(h1[i1].y, -1);
      i1++;
    }
    while (i2 < h2.length && h2[i2].l <= v.x) {
      update(h2[i2].y, 1);
      i2++;
    }
    // log(s, cal1(v.l), cal2(v.l));
    if (v.l == 0 && v.r == z) s++;
    if (v.l == 0) s += cal1(v.r);
    else s += cal2(v.l);
  })

  log(s)
}

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

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

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

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

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

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

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

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math, bi = BigInt;
  let [n, m] = $(2), s = 1; z = 1e6;
  let h1 = [], h2 = [];
  For(n, i => {
    let [y, l, r] = $(3)
    if (l == 0 && r == z) s++;
    if (l == 0) h1.push({ y, r });
    else h2.push({ y, l })
  })
  h1.sort((a, b) => a.r - b.r);
  h2.sort((a, b) => a.l - b.r);

  let bit1 = Arr(z + 1, i => 0), bit2 = Arr(z + 1, i => 0)

  let update = (pos, x) => {
    for (let i = pos; i <= z; i += i & -i) bit1[i] += x;
    for (let i = z - pos; i <= z; i += i & -i) bit2[i] += x;
  }
  let cal1 = pos => {
    let res = 0;
    for (let i = pos; i; i -= i & -i) res += bit1[i];
    return res;
  }
  let cal2 = pos => {
    let res = 0;
    for (let i = z - pos; i; i -= i & -i) res += bit2[i];
    return res;
  }

  let v = Arr(m, i => ({ x: $(), l: $(), r: $() }))
  v.sort((a, b) => a.x - b.x);

  let i1 = 0, i2 = 0;
  h1.forEach(h => update(h.y, 1));
  v.forEach(v => {
    while (i1 < h1.length && h1[i1].r < v.x) {
      update(h1[i1].y, -1);
      i1++;
    }
    while (i2 < h2.length && h2[i2].l <= v.x) {
      update(h2[i2].y, 1);
      i2++;
    }
    // log(s, cal1(v.l), cal2(v.l));
    if (v.l == 0 && v.r == z) s++;
    if (v.l == 0) s += cal1(v.r);
    else s += cal2(v.l);
  })

  log(s)
}


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

let lineNum = 0;
let countOfData = null;
let data = null;
readline.on('line', line => {
  lineNum++;
  if(lineNum === 1) {
    countOfData = +line;
    data = Array.from(new Array(countOfData), () => []);
    return;
  }
  data[Math.floor((lineNum - 2) / 2)].push(line.split(' ').map(i => +i));

  if((lineNum - 1) / 2 === countOfData) {
    goToSolution(data);
  }

});

function goToSolution(data) {
  data.forEach(set => {
    const [[length, k],arr] = set;
    if(length < 2) {
      console.log(0);
      return;
    }
    arr.sort((a,b) => a - b);

    for(let i = 0; i < k; i++) {
      arr[length - 1] += arr[length - 2 - i];
    }

    console.log(arr[length - 1]);
  })
}

var tc = parseInt(readline());
for (; tc-- ;){
    var AR = readline().split(' ').map(x => parseInt(x));
    var n = AR[0], m = AR[1];

    var ar = readline().split(' ').map(x => parseInt(x));
    ar.sort((a, b) => b - a);
    var sum = 0;
    for (var i = 0; i <= m; i++) sum += ar[i];
    print(sum);
}

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

let mem = new Map();
function query(arr, k){
    arr.sort((a, b)=>a-b);
    for (let i = arr.length-2; i>=0 && k>0; i--)
    {
        arr[arr.length-1] += arr[i];
        arr[i] = 0;
        k--;
    }
    arr.sort((a, b)=>a-b);
    return arr[arr.length-1]-arr[0];
}

function main() {
    var q = +readline();
    while (q--)
    {
        var [n, k] = readline().split(' ').map(n=>+n);
        let arr = readline().split(' ').map(n=>+n);
        print(query(arr, k));
    }
}

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--) {
    let [len, k] = readLine().split(" ").map(Number);
    const arr = readLine().split(" ").map(Number);
    let [min, max] = [0, 0];

    arr.sort((a, b) => b - a);
    max = arr[0];

    for (let i = 1; i <= k; i++) {
      max += arr[i];
    }

    console.log(max - min);
  }
}

//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 one = nextIntArray();
    var N = one[0];
    var K = one[1];
    var list = nextIntArray();
    list.sort(function(a,b){
    	return b - a;
    });
    for(var j = 1; j < K + 1; j++){
      list[0] += list[j];
    }
    output[i] = list[0];
  }
  myout(myconv(output, 9));
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 2;
    let i = 1;
    while (i <= testCases) {
      let a = data[i].trim().split(' ').map(Number);
      const n = a[0];
      const k = a[1];
      let s = data[i + 1].trim().split(' ').map(Number);
      s.sort((a, b) => b - a);
      if (s[0] === 0) console.log(0);
      else {
        for (let j = 0; j < k; j += 1) {
          s[j + 1] += s[j];
        }
        console.log(s[k]);
      }
      i += 2;
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        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 cases = parseInt(readline());
  for (let i = 0; i < cases; i++) {
    test();
  }
}

function test() {
  const input = readline().split(' ');
  const nb = parseInt(input[0]);
  let k = parseInt(input[1]);
  const barrels = readline().split(' ').map(x => parseInt(x)).sort((a,b) => b-a);
  let max = barrels[0];
  for (let i = 1; i <= k; i++) {
    max += barrels[i];
  }
  console.log(max);
}

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

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

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

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

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

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

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

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

let input = '';
process.stdin.on('data', c => input += c);
process.stdin.on('end', main);
async function main() {
  let inp = input.split(/\s+/).map(v => +v), _i = 0, $ = n => n != null ? inp.slice(_i, _i += n) : inp[_i++],
    out = [], log = console.log, asc = (a, b) => a - b, desc = (a, b) => b - a, { min, max, ceil, floor, sqrt, abs, log2 } = Math,
    bi = BigInt, rand = n => Math.random() * n | 0;

  let t = $()
  while (t--) {
    let [n, k] = $(2)
    let a = $(n).sort(asc)
    log(a.slice(-k - 1).sum())
  }
}

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

    B();
});

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 = pi(readline());
        let a = 0;
        let b = 0;
        let c = 0;
        let isFound = false;
        for(let i = 0; i <= Math.floor(n/3); i++){
            if(isFound)
                break;
            if(3*i > n)
                break;
            else if(3*i === n){
                a = i;
                isFound = true;
                break;
            }
            for(let j = 0; j <= Math.floor(n/5); j++){
                if(isFound)
                    break;
                if(3*i + 5*j > n)
                    break;
                else if(3*i + 5*j === n){
                    a = i; b = j;
                    isFound = true;
                    break;
                }
                for(let k = 0; k <= Math.floor(n/7); k++){
                    if(3*i + 5*j + 7*k === n){
                        a = i; b = j; c = k;
                        isFound = true;
                        break;
                    }else if(3*i + 5*j + 7*k > n){
                        break;
                    }
                }
            }
        }

        if(isFound)
            console.log(a,b,c)
        else
            console.log(-1);
    }
}

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

        let d = 0;
        for(let i = 0; i < k; i++){
            if(i < n){
                d += a[i];
            }else{
                break;
            }
        }

        if(k < n)
            console.log(d+a[k]);
        else
            console.log(d);
    }
}