const readline = require("readline");

var tcn = 0
var space = true
var lineCnt = 0
var sumsArr = [0,0,0,0,0,0,0,0]
var res = 0

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

rl.on('line', line => {
  if (!tcn) return tcn = Number(line)
  if (space) return space = false

  run(line, lineCnt)
  lineCnt++

  if (lineCnt == 8) {
    if (!--tcn) rl.close()
    lineCnt = 0
    sumsArr = [0,0,0,0,0,0,0,0]
    space = true
  }
})

function run(line, lineCnt) {
  line.split('').forEach((val, idx) => {
    sumsArr[idx] += (val == 'B')
  })

  if (line.split('').reduce((acc, val) => {
    return acc += (val == 'R')
  }, 0) == 8) {
    res = 'R'
  }

  if (lineCnt == 7) {
    sumsArr.forEach(val => {
      if (val == 8) {
        res = 'B'
      }
    })
    console.log(res)
  }
}

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let input=buf.split(EOL);
    let line=[];
    for(let i=0;i<input.length;i++) if(input[i]!=='') line.push(input[i]);
    let t=parseInt(line[0]);
    for(let k=1;k<=t;k++)
    {
        let arr=new Array(8);
        for(let i=8*(k-1)+1;i<=8*k;i++) arr[i-8*(k-1)-1]=line[i];
        let ans='';
        for(let i=0;i<8;i++) {
            let c1=0,c2=0;
            for(let j=0;j<8;j++) {
                if(arr[i][j]==='R') c1++;
                if(arr[i][j]==='B') c2++;
            }
            if(c1===8) ans='R';
        }
        for(let j=0;j<8;j++) {
            let c1=0,c2=0;
            for(let i=0;i<8;i++) {
                if(arr[i][j]==='R') c1++;
                if(arr[i][j]==='B') c2++;
            }
            if(c2===8) ans='B';
        }
        console.log(ans);
    }
})

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let input=buf.split(EOL);
    let line=[];
    for(let i=0;i<input.length;i++) if(input[i]!=='') line.push(input[i]);
    let t=parseInt(line[0]);
    for(let k=1;k<=t;k++)
    {
        let arr=new Array(8);
        for(let i=8*(k-1)+1;i<=8*k;i++) arr[i-8*(k-1)-1]=line[i];
        let a=new Array(8);
        for(let i=0;i<8;i++) {
            a[i]=new Array(8);
            for(let j=0;j<8;j++) {
                a[i][j]=arr[i][j];
            }
        }
        // console.log(a);
        // console.log(arr);
        let ans='';
        for(let i=0;i<8;i++) {
            let c1=0,c2=0;
            for(let j=0;j<8;j++) {
                if(a[i][j]==='R') c1++;
                if(a[i][j]==='B') c2++;
            }
            if(c1===8) ans='R';
            // if(c2===8) ans='B';
        }
        for(let j=0;j<8;j++) {
            let c1=0,c2=0;
            for(let i=0;i<8;i++) {
                if(a[i][j]==='R') c1++;
                if(a[i][j]==='B') c2++;
            }
            // if(c1===8) ans='R';
            if(c2===8) ans='B';
        }
        console.log(ans);
    }
})

/**
 * 10/13/22 morning
 * https://codeforces.com/contest/1742/problem/C
 */

const pr = console.log;

const R = "R".repeat(8), B = "B".repeat(8);

// WA
const solve = (g) => {
    let n = g.length, m = g[0].length, res = '';
    // pr(g, n, m)
    let rows = [], cols = [];
    for (let i = 0; i < n; i++) {
        let row = '';
        for (let j = 0; j < m; j++) {
            row += g[i][j];
        }
        rows.push(row);
    }
    // pr('rows', rows);
    for (let row of rows) {
        if (row = R) res = 'R';
        // if (row == R) return pr('R');
        // if (row == B) return pr('B');
    }
    for (let i = 0; i < n; i++) {
        let col = '';
        for (let j = 0; j < m; j++) {
            col += g[j][i];
        }
        cols.push(col);
    }
    // pr('cols', cols);
    for (let col of cols) {
        if (col == B) res = 'B';
        // if (col == R) return pr('R');
        // if (col == B) return pr('B');
    }
    pr(res);
};

const main = () => {
    const readLine = () => input[currentLine++];
    const ni = () => readLine() - '0';
    const nas = () => readLine().split(" ");
    const nai = () => nas().map(Number);
    const nal = () => nas().map(BigInt);
    let input = '', currentLine = 0;
    process.stdin.on('data', (stdin) => input += stdin)
    process.stdin.on('end', () => {
        input = input.split('\r\n');
        // pr("input", input)
        let t = ni();
        while (t--) {
            readLine();
            let g = [];
            for (let i = 0; i < 8; i++) {
                let row = readLine();
                g.push(row);
            }
            solve(g);
        }
    });
};

main()

//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 s = nextStrArray(8);
		var output = ".";
		for(var i = 0; i < 8; i++){
			var last = 'R';
			var ok = true;
			for(var j = 0; j < 8; j++){
				if(last != s[i][j]){
					ok = false;
					break;
				}
			}
			if(ok){
				output = last;
			}
		}
		for(var i = 0; i < 8; i++){
			var last = 'B';
			var ok = true;
			for(var j = 0; j < 8; j++){
				if(last != s[j][i]){
					ok = false;
					break;
				}
			}
			if(ok){
				output = last;
			}
		}
		myout(output);
	}
}

/*
* auther yeling
*
*
*/
'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 print(str) {
    console.log(str);
}

function begin(grid) {
    var row = new Array(8).fill(0);
    var col = new Array(8).fill(0);
    var i = 0;
    for(i = 7; i >= 0; i--) {
        for(var j = 0; j < 8; j++) {
            if(grid[i][j] == 'R') {
                row[i]++;
            } else if(grid[i][j] == 'B') {
                col[j]++;
            }
        }
    }
    for( i = 0; i < 8; i++) {
        if(row[i] == 8 ) {
            print("R");
            break;
        }
        if(col[i] == 8) {
            print("B");
            break;
        }
    }
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        readline();
        var grid = [];
        for(var j = 0; j < 8; j++) {
            var x = readline()
            .trim()
            .split('');
            grid.push(x);
        }
        begin(grid);
    }
}

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

function solve(arr) {
    for (let i = 0; i < 8; i++) {
        let ok = 1
        for (let j = 0; j < 8; j++) {
            if (arr[i][j] !== arr[i][0]) {
                ok = 0
            }
        }
        if (ok && arr[i][0] === 'R') return arr[i][0]
    }
    for (let j = 0; j < 8; j++) {
        let ok = 1
        for (let i = 0; i < 8; i++) {
            if (arr[i][j] !== arr[0][j]) {
                ok = 0
            }
        }
        if (ok && arr[0][j] === 'B') return arr[0][j]
    }
    // return [arr]
    // console.log('-')
}

'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) {
  let n = 8;
  let a = [];
  for (let i = 0; i <= n; i++) {
    if (i) a.push(read());
  }
  next: for (let i = 0; i < n; i++) {
    if (a[i][0] === '.') continue;
    for (let j = 0; j < n; j++) {
      if ('R' !== a[i][j]) continue next;
    }
    return 'R';
  }
  next: for (let i = 0; i < n; i++) {
    if (a[0][i] === '.') continue;
    for (let j = 0; j < n; j++) {
      if ('B' !== a[j][i]) continue next;
    }
    return 'B';
  }
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    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(/\s+/);
void function () {
  const read = ((i = 0) => () => inputs[i++])();
  const output = main(read);
  process.stdout.write(output);
}();

const lines = [];
let currentLineIndex = 0;
const readlineInterface = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
readlineInterface.on("line", (line) => {
  if (currentLineIndex > 0 && line.trim()) {
    lines.push(line);
  }
  currentLineIndex++;
});

const squareSize = 8;
const rowChar = "R";
const columnChar = "B";

readlineInterface.on("close", () => {
  const rows = lines.map((line) => line.split(""));
  let partialIndex = 0;
  let toPush = [];
  const tests = [];
  rows.forEach((row, index) => {
    if (partialIndex < squareSize) {
      toPush.push(row);
    } else {
      tests.push(toPush);
      toPush = [row];
      partialIndex = 0;
    }
    partialIndex++;
  });
  tests.push(toPush);

  tests
    .map((rows) => {
      return rows.find((row) => new Set(row).size === 1 && row[0] === rowChar)
        ? rowChar
        : columnChar;
    })
    .forEach((e) => console.log(e));
});

var tests = +readline();

for(var i=0; i<tests; i++) {
    var em = readline();
    var grid = [];
    for(var j = 0; j < 8;j++) {
        var l = readline().split("");
        grid.push(l);
    }

    var last = null;
    for(var j = 0; j < 8;j++) {
        var b = grid[0][j];
        if(b == "B") {
            var valid = true;
            for(var z = 0; z < 8; z++) {
                if(grid[z][j] != "B") {
                    valid = false;
                }
            }
            if(valid) {
                last = "B";
            }
        }
    }

    if(!last) {
        for(var j = 0; j < 8;j++) {
            var b = grid[j][0];
            if(b == "R") {
                var valid = true;
                for(var z = 0; z < 8; z++) {
                    if(grid[j][z] != "R") {
                        valid = false;
                    }
                }
                if(valid) {
                    last = "R";
                }
            }
        }
    }

    print(last)
}

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let input=buf.split(EOL);
    let line=[];
    for(let i=0;i<input.length;i++) if(input[i]!=='') line.push(input[i]);
    let t=parseInt(line[0]);
    for(let k=1;k<=t;k++)
    {
        let arr=new Array(8);
        for(let i=8*(k-1)+1;i<=8*k;i++) arr[i-8*(k-1)-1]=line[i];
        let a=new Array(8);
        for(let i=0;i<8;i++) {
            a[i]=new Array(8);
            for(let j=0;j<8;j++) {
                a[i][j]=arr[i][j];
            }
        }
        // console.log(a);
        // console.log(arr);
        let ans='';
        for(let i=0;i<8;i++) {
            let c1=0,c2=0;
            for(let j=0;j<8;j++) {
                if(a[i][j]==='R') c1++;
                if(a[i][j]==='B') c2++;
            }
            if(c1===8) ans='R';
            if(c2===8) ans='B';
        }
        for(let j=0;j<8;j++) {
            let c1=0,c2=0;
            for(let i=0;i<8;i++) {
                if(a[i][j]==='R') c1++;
                if(a[i][j]==='B') c2++;
            }
            if(c1===8) ans='R';
            if(c2===8) ans='B';
        }
        console.log(ans);
    }
})

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let input=buf.split(EOL);
    let line=[];
    for(let i=0;i<input.length;i++) if(input[i]!=='') line.push(input[i]);
    let t=parseInt(line[0]);
    for(let k=1;k<=t;k++)
    {
        let arr=new Array(8);
        for(let i=8*(k-1)+1;i<=8*k;i++) arr[i-8*(k-1)-1]=line[i];
        let a=new Array(8);
        for(let i=0;i<8;i++) {
            a[i]=new Array(8);
            for(let j=0;j<8;j++) {
                a[i][j]=arr[i][j];
            }
        }
        // console.log(a);
        // console.log(arr);
        let ans='';
        for(let i=0;i<8;i++) {
            let c1=0,c2=0;
            for(let j=0;j<8;j++) {
                if(a[i][j]=='R') c1++;
                if(a[i][j]=='B') c2++;
            }
            if(c1===8) ans='R';
            if(c2===8) ans='B';
        }
        for(let j=0;j<8;j++) {
            let c1=0,c2=0;
            for(let i=0;i<8;i++) {
                if(a[i][j]=='R') c1++;
                if(a[i][j]=='B') c2++;
            }
            if(c1===8) ans='R';
            if(c2===8) ans='B';
        }
        console.log(ans);
    }
})

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let k=1;k<=t;k++)
    {
        let arr=new Array(8);
        for(let i=8*(k-1)+1;i<=8*k;i++) arr[i-8*(k-1)-1]=line[i];
        let a=new Array(8);
        for(let i=0;i<8;i++) {
            a[i]=new Array(8);
            for(let j=0;j<8;j++) {
                a[i][j]=arr[i][j];
            }
        }
        // console.log(a);
        // console.log(arr);
        let ans='';
        for(let i=0;i<8;i++) {
            let c1=0,c2=0;
            for(let j=0;j<8;j++) {
                if(a[i][j]=='R') c1++;
                if(a[i][j]=='B') c2++;
            }
            if(c1===8) ans='R';
            if(c2===8) ans='B';
        }
        for(let j=0;j<8;j++) {
            let c1=0,c2=0;
            for(let i=0;i<8;i++) {
                if(a[i][j]=='R') c1++;
                if(a[i][j]=='B') c2++;
            }
            if(c1===8) ans='R';
            if(c2===8) ans='B';
        }
        console.log(ans);
    }
})

/**
 * 10/13/22 morning
 * https://codeforces.com/contest/1742/problem/C
 */

const pr = console.log;

const R = "R".repeat(8), B = "B".repeat(8);

const solve = (g) => {
    let n = g.length, m = g[0].length, se = new Set();
    // pr(g, n, m)
    let rows = [], cols = [];
    for (let i = 0; i < n; i++) {
        let row = '';
        for (let j = 0; j < m; j++) {
            row += g[i][j];
        }
        rows.push(row);
    }
    // pr('rows', rows);
    for (let row of rows) {
        if (row == R) return pr('R');
        if (row == B) return pr('B');
    }
    for (let i = 0; i < n; i++) {
        let col = '';
        for (let j = 0; j < m; j++) {
            col += g[j][i];
        }
        cols.push(col);
    }
    // pr('cols', cols);
    for (let col of cols) {
        if (col == R) return pr('R');
        if (col == B) return pr('B');
    }
};

const main = () => {
    const readLine = () => input[currentLine++];
    const ni = () => readLine() - '0';
    const nas = () => readLine().split(" ");
    const nai = () => nas().map(Number);
    const nal = () => nas().map(BigInt);
    let input = '', currentLine = 0;
    process.stdin.on('data', (stdin) => input += stdin)
    process.stdin.on('end', () => {
        input = input.split('\r\n');
        // pr("input", input)
        let t = ni();
        while (t--) {
            readLine();
            let g = [];
            for (let i = 0; i < 8; i++) {
                let row = readLine();
                g.push(row);
            }
            solve(g);
        }
    });
};

main()

/**
 * 10/13/22 morning
 * https://codeforces.com/contest/1742/problem/C
 */

const pr = console.log;

const solve = (g) => {
    let n = g.length, m = g[0].length, se = new Set();
    // pr(g, n, m)
    let rows = [], cols = [];
    for (let i = 0; i < n; i++) {
        let row = [];
        for (let j = 0; j < m; j++) {
            if (g[i][j] != '.') row.push(g[i][j]);
        }
        rows.push(row);
    }
    // pr('rows', rows);
    for (let row of rows) {
        let se = new Set(row);
        // pr("row set", se)
        if (se.size == 1 && row.length == n) return pr(row[0]);
    }
    for (let i = 0; i < n; i++) {
        let col = [];
        for (let j = 0; j < m; j++) {
            if (g[j][i] != '.') col.push(g[j][i]);
        }
        cols.push(col);
    }
    // pr('cols', cols);
    for (let col of cols) {
        let se = new Set(col);
        // pr("col set", se)
        if (se.size == 1 && col.length == m) return pr(col[0]);
    }
};

const main = () => {
    const readLine = () => input[currentLine++];
    const ni = () => readLine() - '0';
    const nas = () => readLine().split(" ");
    const nai = () => nas().map(Number);
    const nal = () => nas().map(BigInt);
    let input = '', currentLine = 0;
    process.stdin.on('data', (stdin) => input += stdin)
    process.stdin.on('end', () => {
        input = input.split('\r\n');
        // pr("input", input)
        let t = ni();
        while (t--) {
            readLine();
            let g = [];
            for (let i = 0; i < 8; i++) {
                let row = readLine();
                g.push(row);
            }
            solve(g);
        }
    });
};

main()

/**
 * 10/13/22 morning
 * https://codeforces.com/contest/1742/problem/C
 */

const pr = console.log;

const solve = (g) => {
    let n = g.length, m = g[0].length, se = new Set();
    // pr(g, n, m)
    for (let row of g) {
        let se = new Set(row);
        if (se.size == 1 && row[0] != '.') return pr(row[0]);
    }
    let cols = [];
    for (let i = 0; i < n; i++) {
        let col = [];
        for (let j = 0; j < m; j++) {
            col.push(g[j][i]);
        }
        cols.push(col);
    }
    // pr(cols);
    for (let col of cols) {
        let se = new Set(col);
        // pr(se)
        if (se.size == 1 && col[0] != '.') return pr(col[0]);
    }
};

const main = () => {
    const readLine = () => input[currentLine++];
    const ni = () => readLine() - '0';
    const nas = () => readLine().split(" ");
    const nai = () => nas().map(Number);
    const nal = () => nas().map(BigInt);
    let input = '', currentLine = 0;
    process.stdin.on('data', (stdin) => input += stdin)
    process.stdin.on('end', () => {
        input = input.split('\r\n');
        // pr("input", input)
        let t = ni();
        while (t--) {
            readLine();
            let g = [];
            for (let i = 0; i < 8; i++) {
                let row = readLine();
                g.push(row);
            }
            solve(g);
        }
    });
};

main()

//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 s = nextStrArray(8);
		var output = ".";
		for(var i = 0; i < 8; i++){
			var last = s[i][0];
			if(last == "."){
				continue;
			}
			var ok = true;
			for(var j = 0; j < 8; j++){
				if(last != s[i][j]){
					ok = false;
					break;
				}
			}
			if(ok){
				output = last;
			}
		}
		for(var i = 0; i < 8; i++){
			var last = s[0][i];
			if(last == "."){
				continue;
			}
			var ok = true;
			for(var j = 0; j < 8; j++){
				if(last != s[j][i]){
					ok = false;
					break;
				}
			}
			if(ok){
				output = last;
			}
		}
		myout(output);
	}
}

/*
* auther yeling
*
*
*/
'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 print(str) {
    console.log(str);
}

function begin(grid) {
    var row = new Array(8).fill(0).map(() => new Array(2).fill(0));
    var col = new Array(8).fill(0).map(() => new Array(2).fill(0));
    var i = 0;
    for(i = 7; i >= 0; i--) {
        for(var j = 0; j < 8; j++) {
            if(grid[i][j] == 'R') {
                row[i][0]++;
                col[j][0]++;
            } else if(grid[i][j] == 'B') {
                row[i][1]++;
                col[j][1]++;
            }
        }
    }
    for( i = 0; i < 8; i++) {
        if(row[i][0] == 8 || col[i][0] == 8) {
            print("R");
            break;
        }
        if(row[i][1] == 8 || col[i][1] == 8) {
            print("B");
            break;
        }
    }
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        readline();
        var grid = [];
        for(var j = 0; j < 8; j++) {
            var x = readline()
            .trim()
            .split('');
            grid.push(x);
        }
        begin(grid);
    }
}

'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 print(str) {
    console.log(str);
}

function begin(grid) {
    var row = new Array(8).fill(0).map(() => new Array(2).fill(0));
    var col = new Array(8).fill(0).map(() => new Array(2).fill(0));
    var i = 0;
    for(i = 0; i < 8; i++) {
        for(var j = 0; j < 8; j++) {
            if(grid[i][j] == 'R') {
                row[i][0]++;
                col[j][0]++;
            } else if(grid[i][j] == 'B') {
                row[i][1]++;
                col[j][1]++;
            }
        }
    }
    for( i = 0; i < 8; i++) {
        if(row[i][0] == 8 || col[i][0] == 8) {
            print("R");
            break;
        }
        if(row[i][1] == 8 || col[i][1] == 8) {
            print("B");
            break;
        }
    }
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        readline();
        var grid = [];
        for(var j = 0; j < 8; j++) {
            var x = readline()
            .trim()
            .split('');
            grid.push(x);
        }
        begin(grid);
    }
}

const readline = require("readline");

var tcn = 0
var space = true
var lineCnt = 0
var sumsArr = [0,0,0,0,0,0,0,0]
var res = 0

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

rl.on('line', line => {
  if (!tcn) return tcn = Number(line)
  if (space) return space = false

  run(line, lineCnt)
  lineCnt++

  if (lineCnt == 8) {
    if (!--tcn) rl.close()
    lineCnt = 0
    sumsArr = [0,0,0,0,0,0,0,0]
    space = true
  }
})

function run(line, lineCnt) {
  line.split('').forEach((val, idx) => {
    sumsArr[idx] += (val == 'R') - (val == 'B')
  })

  if (line.split('').reduce((acc, val) => {
    return acc += (val == 'R')
  }, 0) == 8) {
    res = 'R'
  }
  else if (line.split('').reduce((acc, val) => {
    return acc -= (val == 'B')
  }, 0) == -8) {
    res = 'B'
  }

  if (lineCnt == 7) {
    sumsArr.forEach(val => {
      if (val == 8) {
        res = 'R'
        return
      }
      else if (val == -8) {
        res = 'B'
        return
      }
    })
    console.log(res)
  }
}

const readline = require("readline");

var tcn = 0
var space = true
var lineCnt = 0
var sumsArr = [0,0,0,0,0,0,0,0]
var res = 0

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

rl.on('line', line => {
  if (!tcn) return tcn = Number(line)
  if (space) return space = false

  run(line, lineCnt)
  lineCnt++

  if (lineCnt == 8) {
    if (!--tcn) rl.close()
    lineCnt = 0
    sumsArr = [0,0,0,0,0,0,0,0]
    space = true
  }
})

function run(line, lineCnt) {
  line.split('').forEach((val, idx) => {
    sumsArr[idx] += (val == 'R') - (val == 'B')
  })

  if (line.split('').reduce((acc, val) => {
    return acc = acc + (val == 'R') - (val == 'B')
  }, 0) == 8) {
    res = 'R'
    return
  }
  else if (line.split('').reduce((acc, val) => {
    return acc = acc + (val == 'R') - (val == 'B')
  }, 0) == -8) {
    res = 'B'
    return
  }

  if (lineCnt == 7) {
    sumsArr.forEach(val => {
      if (val == 8) {
        res = 'R'
        return
      }
      else if (val == -8) {
        res = 'B'
        return
      }
    })
    console.log(res)
  }
}

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

function solve(arr) {
    for (let i = 0; i < 8; i++) {
        let ok = 1
        for (let j = 0; j < 8; j++) {
            if (arr[i][j] !== arr[i][0]) {
                ok = 0
            }
        }
        if (ok && arr[i][0] !== '.') return arr[i][0]
    }
    for (let j = 0; j < 8; j++) {
        let ok = 1
        for (let i = 0; i < 8; i++) {
            if (arr[i][j] !== arr[0][j]) {
                ok = 0
            }
        }
        if (ok && arr[0][j] !== '.') return arr[0][j]
    }
    // return [arr]
}

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

function solve(arr) {
    for (let i = 0; i < 8; i++) {
        let ok = 1
        for (let j = 0; j < 8; j++) {
            if (arr[i][j] !== arr[i][0]) {
                ok = 0
            }
        }
        if (ok && arr[i][0] !== '.') return arr[i][0]
    }
    for (let j = 0; j < 8; j++) {
        let ok = 1
        for (let i = 0; i < 8; i++) {
            if (arr[i][j] !== arr[0][j]) {
                ok = 0
            }
        }
        if (ok && arr[0][j] !== '.') return arr[0][j]
    }
    // return [arr]
}

'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) {
  let n = 8;
  let a = [];
  for (let i = 0; i <= n; i++) {
    if (i) a.push(read());
  }
  next: for (let i = 0; i < n; i++) {
    if (a[i][0] === '.') continue;
    let pre = '';
    for (let j = 0; j < n; j++) {
      if (!pre) pre = a[i][j];else if (pre !== a[i][j]) continue next;
    }
    return pre;
  }
  next: for (let i = 0; i < n; i++) {
    if (a[0][i] === '.') continue;
    let pre = '';
    for (let j = 0; j < n; j++) {
      if (!pre) pre = a[j][i];else if (pre !== a[j][i]) continue next;
    }
    return pre;
  }
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    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(/\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) {
    let p, c
    const arr = []
    for (let i = 0; i < str.length; i++) {
        const x = str[i]
        if (x === p) {
            c++
        } else {
            if (c) {
                arr.push([p, c])
            }
            c = 1
            p = x
        }
    }
    arr.push([p, c])
    if (arr[0][0] === '0') arr.shift()
    if (arr.length && arr[arr.length - 1][0] === '0') arr.pop()
    //
    return cal(arr)
}
function cal(arr) {
    if (arr.length < 2) return 0
    const s0 = []
    const s1 = []
    arr.forEach(([p, c], i) => {
        const c0 = p === '0' ? c : 0
        const c1 = p === '1' ? c : 0
        s0[i] = i ? c0 + s0[i - 1] : c0
        s1[i] = i ? c1 + s1[i - 1] : c1
    })
    let ans = Infinity
    // [i, j]
    const helper = (i, j) => {
        // j++, a--, b++
        const a = s1[arr.length - 1] - (j < arr.length ? (s1[j] || 0) : s1[arr.length - 1])
            + (s1[i - 1] || 0)
        const b = (s0[j] || 0) - (s0[i - 1] || 0)
// if (isNaN(a) || isNaN(b)) {
//     console.log(arr, i, j)
//     throw 'sb'
// }
        return [a - b, Math.max(a, b)]
    }
    arr.forEach(([p, c], i) => {
        if (p === '1') {
            const k = binarySearch(i - 1, arr.length - 1, x => helper(i, x)[0] >= 0)
    // console.log(i, helper(i, k)[1], helper(i, k + 1)[1])
            ans = Math.min(
                ans,
                helper(i, k)[1],
                k + 1 < arr.length ? helper(i, k + 1)[1] : Infinity
            )
        }
    })
    return ans
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

'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(s) {
  const n = s.length;
  let s0 = [],
      s1 = [];
  for (let i = 0; i < n; i++) {
    var _s, _s2;
    s0[i] = (_s = s0[i - 1]) !== null && _s !== void 0 ? _s : 0;
    s1[i] = (_s2 = s1[i - 1]) !== null && _s2 !== void 0 ? _s2 : 0;
    if (s[i] === '0') s0[i]++;else s1[i]++;
  }
  const dp = [];
  for (let i = 0; i < n; i++) {
    dp[i] = s1[i] + s0[n - 1] - s0[i];
  }
  let res = Math.min(s0[n - 1], n - s0[n - 1]);
  for (let j = n - 1; j >= 0; j--) {
    const a = s1[n - 1] - s1[j],
          b = s0[j];
    if (a >= b) {
      res = Math.min(res, a);
    } else {
      const i = b - a - 1;
      res = Math.min(res, a + s1[i], b - s0[i]);
    }
  }
  return res;
}

async function main(read) {
  let t = Number(await read());
  let res = [];
  while (t--) {
    const s = await read();
    res.push(solve(s));
  }
  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';
// HEADER:
const print = console.log;
let IS_MULTITEST, testN;
const pcalc = testN=>{
  let res = calc(testN);
  if (Array.isArray(res)){
    pa(res);
  } else if (Number.isFinite(res) || typeof res=='string'){
    print(res);
  }
};

const main = ()=>{
  if (IS_MULTITEST){
    let T = +readline()
    for (testN=1; testN<=T; testN++)
      pcalc(T);
  } else
   pcalc();
};

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(`Test #${testN}`, obj);

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

// SOLUTION:
IS_MULTITEST = 1;

const calc = ()=>{
  // READING:
  let s = readline();
  let n = s.length;
  // PROCESSING:
  let Sl = new Array(n).fill(0);
  let Sr = new Array(n).fill(0);
  for (let i=n-1; i>=0; i--)
    Sr[i] = (i<n-1 ? Sr[i+1] : 0) + +(s[i]=='1');
  for (let i=0; i<n; i++)
    Sl[i] = (i>0 ? Sl[i-1] : 0) + +(s[i]=='1');
  LT({s, Sl, Sr});
  let l = 0, r = n;
  let check = (cnt)=>{
    let l = 0;
    let r = 0;
    for (let leftTake = 0; leftTake<=cnt; leftTake++){
      while (l<n && Sl[l]<=leftTake){
        l++;
      }
      while (r<n && Sr[r]>cnt-leftTake){
        r++;
      }
      let middleItems = r-l;
      let middleZeros = middleItems-((Sl[r-1]||0)-(Sl[l-1]||0));
      if (middleZeros<=cnt)
        return true;
    }
    return false;
  }
  while (l+2<r){
    let m = (l+r)>>1;
    L({l, m, r})
    if (check(m)){
      r = m+1;
    } else {
      l = m+1;
    }
  }
  if (check(l))
    return l;
  if (check(l+1))
    return l+1;
  return l+2;
};

//import { readline, print } from '@ip-algorithmics/codeforces-io';
var t = +readline();
while (t--) {
    var a = readline();
    var n = a.length;
    //print(n);
    var ans = 0;
    var max = [0];
    var pos = [0];
    var del = [0];
    var cur = 0;
    var curd = 0;
    for (var i = 0; i < n; i++) {
        ans += +(a[i] === '0');
        cur += +(a[i] === '0');
        curd += +(a[i] === '1');
        if (cur > max[max.length - 1]) {
            max.push(cur);
            pos.push(i + 1);
            del.push(curd);
        }
    }
    /*print('ans',ans);
    print('max', max);
    print('pos',pos);
    print('del', del);*/
    var win = 0;
    var r = max.length - 1;
    cur = 0;
    curd = 0;
    root: for (var i = n;;) {
        while (pos[r] > i || del[r] + curd > ans - cur - max[r]) {
            r--;
            if (r < 0) {
                break root;
            }
        }
        win = Math.max(win, cur + max[r]);
        //print('win', win, cur, max[r], r);
        if ((--i) < 0)
            break;
        cur += +(a[i] === '0');
        curd += +(a[i] === '1');
    }
    print(ans - win);
}

const readline = require('readline')

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

function solve(str) {
    let p, c
    const arr = []
    for (let i = 0; i < str.length; i++) {
        const x = str[i]
        if (x === p) {
            c++
        } else {
            if (c) {
                arr.push([p, c])
            }
            c = 1
            p = x
        }
    }
    arr.push([p, c])
    if (arr[0][0] === '0') arr.shift()
    if (arr.length && arr[arr.length - 1][0] === '0') arr.pop()
    //
    return cal(arr)
}
function cal(arr) {
    if (arr.length < 2) return 0
    const s0 = []
    const s1 = []
    arr.forEach(([p, c], i) => {
        const c0 = p === '0' ? c : 0
        const c1 = p === '1' ? c : 0
        s0[i] = i ? c0 + s0[i - 1] : c0
        s1[i] = i ? c1 + s1[i - 1] : c1
    })
    let ans = Infinity
    // [i, j]
    const helper = (i, j) => {
        // j++, a--, b++
        const a = s1[arr.length - 1] - (j < arr.length ? s1[j] : s1[arr.length - 1])
            + (s1[i - 1] || 0)
        const b = (s0[j] || 0) - (s0[i - 1] || 0)
        return [a - b, Math.max(a, b)]
    }
// console.log(arr, s0, s1)
    arr.forEach(([p, c], i) => {
        if (p === '1') {
            const k = binarySearch(i - 1, arr.length - 1, x => helper(i, x)[0] >= 0)
    // console.log(i, helper(i, k)[1], helper(i, k + 1)[1])
            ans = Math.min(
                ans,
                helper(i, k)[1],
                k + 1 < arr.length ? helper(i, k + 1)[1] : Infinity
            )
        }
    })
    return ans
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

const readline = require('readline')

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

function solve(str) {
    let p, c
    let total0 = 0
    const arr = []
    for (let i = 0; i < str.length; i++) {
        const x = str[i]
        if (x === p) {
            c++
        } else {
            if (c) {
                arr.push([p, c])
                if (p === '0') total0 += c
            }
            c = 1
            p = x
        }
    }
    arr.push([p, c])
    if (p === '0') total0 += c
// console.log(arr, total0)
    let i = 0
    let j = arr.length - 1
    let ans1 = 0
    while (i <= j) {
        if (arr[i][0] === '0') {
            total0 -= arr[i][1]
            i++
        } else if (arr[j][0] === '0') {
            total0 -= arr[j][1]
            j--
        } else if (arr[i][1] <= arr[j][1]) {
            const cur = Math.max(ans1, total0)
            let ok = false
            if (i + 1 <= j) {
                const next = Math.max(ans1 + arr[i][1], total0 - arr[i + 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[i][1]
                    i++
                }
            }
            if (!ok && j - 1 >= i) {
                const next = Math.max(ans1 + arr[j][1], total0 - arr[j - 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[j][1]
                    j--
                }
            }
            if (!ok) break
        } else {
            const cur = Math.max(ans1, total0)
            let ok = false
            if (j - 1 >= i) {
                const next = Math.max(ans1 + arr[j][1], total0 - arr[j - 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[j][1]
                    j--
                }
            }
            if (!ok && i + 1 <= j) {
                const next = Math.max(ans1 + arr[i][1], total0 - arr[i + 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[i][1]
                    i++
                }
            }
            if (!ok) break
        }
    }
    // let ans0 = 0
    // for (let k = i; k <= j; k++) {
    //     if (arr[k][0] === '0') ans0 += arr[k][1]
    // }
    return Math.max(total0, ans1)
}

const readline = require('readline')

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

function solve(str) {
    let p, c
    let total0 = 0
    const arr = []
    for (let i = 0; i < str.length; i++) {
        const x = str[i]
        if (x === p) {
            c++
        } else {
            if (c) {
                arr.push([p, c])
                if (p === '0') total0 += c
            }
            c = 1
            p = x
        }
    }
    arr.push([p, c])
    if (p === '0') total0 += c
// console.log(arr, total0)
    let i = 0
    let j = arr.length - 1
    let ans1 = 0
    while (i <= j) {
        if (arr[i][0] === '0') {
            total0 -= arr[i][1]
            i++
        } else if (arr[j][0] === '0') {
            total0 -= arr[j][1]
            j--
        } else if (arr[i][1] <= arr[j][1]) {
            const cur = Math.max(ans1, total0)
            let ok = false
            if (i + 1 <= j) {
                const next = Math.max(ans1 + arr[i][1], total0 - arr[i + 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[i][1]
                    i++
                }
            }
            if (!ok) break
        } else {
            const cur = Math.max(ans1, total0)
            let ok = false
            if (j - 1 >= i) {
                const next = Math.max(ans1 + arr[j][1], total0 - arr[j - 1][1])
                if (next <= cur) {
                    ok = true
                    ans1 += arr[j][1]
                    j--
                }
            }
            if (!ok) break
        }
    }
    // let ans0 = 0
    // for (let k = i; k <= j; k++) {
    //     if (arr[k][0] === '0') ans0 += arr[k][1]
    // }
    return Math.max(total0, ans1)
}


function main(n){

    print(n+1);
    print("2 " + n + " " + 1);
    print("1 " + n + " " + 1000000);
    for(var i = 1 ; i < n ; i++)print("2 " + i + " " + (1000000-i+1));

}

var n = parseInt(readline());
var arr = readline().split(" ");
main(n);

n = +readline();
res = (n+1)+'\n1 '+n+' 500000\n';
ar = readline().split(' ').forEach((num,ind)=>{
    num = +num;
    res += '2 '+ ind +' '+(num - ind)+'\n';
});
print(res);

n = +readline();
res = '1 '+n+' 500000\n';
ar = readline().split(' ').forEach((num,ind)=>{
    num = +num;
    res += '2 '+ ind +' '+(num - ind)+'\n';
});
print(res);

function main(n){

    print(n+1);
    print("2 " + n + " " + 1);
    print("1 " + n + " " + 1000000);
    for(var i = 1 ; i < n ; i++)print("2 " + i + " " + 1000000 - i + 1 );

}

var n = parseInt(readline());
var arr = readline().split(" ");
main(n);


var i = 3;
var res = [];
var slogs = ['a', 'e', 'i', 'o', 'u'];
while(i--) {
	var str = readline();
	var curr = 0;
	for (var j = 0; j < str.length; j++) {
		if (slogs.indexOf(str[j]) !== -1) {
			curr++;
		}
	}
	res.push(curr);
}

var check = (res[0] === 5 && res[1] === 7 && res[2] === 5);
print( check ? 'YES' : 'NO');

print(function(a, b, c) {

	return cnt(a) === 5 && cnt(b) === 7 && cnt(c) === 5 ? 'YES' : 'NO';

	function cnt(s) {
		return s.split(/[aeiou]/).length - 1;
	}

}(readline(), readline(), readline()));

;(function () {

	print(function () {

		var s = [], n = 3, l = ['a', 'e', 'i', 'o', 'u'];
		while (n--) s.push(readline().split('').filter(function (e) { return l.indexOf(e) !== -1; }));

		return (s[0].length === 5 && s[1].length === 7 && s[2].length === 5) ? 'YES' : 'NO';

	}());

}.call(this));

function count(s) {
  var n = 0;
  for (var c of s)
    if ("aeiou".includes(c)) n++;
  return n;
}

print(count(readline()) === 5 && count(readline()) === 7 && count(readline()) === 5 ? "YES" : "NO");

'use strict'

const {EOL} = require('os')

let ipt = ''
process.stdin.on('data', s => ipt += s)
process.stdin.on('end', () => {
  const ils = ipt.split(EOL).slice(0, -1)
  console.log(
       (ils[0].match(/[aeiou]/g) || '').length == 5
    && (ils[1].match(/[aeiou]/g) || '').length == 7
    && (ils[2].match(/[aeiou]/g) || '').length == 5
      ? 'YES'
      : 'NO'
  )
})

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

const vowels = ['a', 'e', 'i', 'o', 'u'];
const arr = [];

rl.on('line', (str) => {
  arr.push(str);
});

rl.on('close', () => {
  let r = [5, 7, 5];
  let ans = 'YES';

  for (let i = 0; i < arr.length; i++) {
    const v = r[i];
    let count = 0;

    for (let j = 0; j < arr[i].length; j++) {
      if (vowels.includes(arr[i][j])) {
        count++;
      }
    }

    if (count !== v) {
      ans = 'NO';
      break;
    }
  }

  console.log(ans);
});

'use strict';

/*let input = `how many gallons
of edo s rain did you drink
                                cuckoo`.split('\n');
function print(out) {
    console.log(out);
}
function readline() {
    return input.shift();
}*/

//code

var l1 = readline();
var l2 = readline();
var l3 = readline();
var result = [l1, l2, l3].map(function (line) {
    return line.split('').filter(function (char) {
        return ['a', 'e', 'i', 'o', 'u'].includes(char);
    }).length;
});
if (result[0] === 5 && result[1] === 7 && result[2] === 5) {
    print('YES');
} else {
    print('NO');
}


var n = +readline();
var m = +readline();
var a = new Array(n);
while (n--) {
    a.push(+readline());
}
a.sort((ai, aj) => aj - ai);
var minCount = 0;
var sumVolume = 0;
while (sumVolume < m) {
    sumVolume += a[minCount++];
}
write(minCount + "\n");

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

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

  if (c === 1) {
    m = +d;
    c++;
    return;
  }

  arr.push(+d);

  c++;
});

rl.on('close', () => {
  arr.sort((a, b) => b - a);
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    m -= arr[i];
    ans++;

    if (m <= 0) {
      break;
    }
  }

  console.log(ans);
});

var n = +readline()
var m = +readline()
var a = []

for (var i = 0; i < n; i++)
{
	a.push(+readline())
}

function descendingComparator(a, b){return b-a}

a.sort(descendingComparator)

var numOfDrives = 0
var availableSpace = 0

for (var i = 0; i < n && availableSpace < m; i++)
{
	numOfDrives++;
	availableSpace += a[i];
}

print(numOfDrives)

n = +readline();
m = +readline();
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(+readline());
}
a.sort(function(a,b){return b - a;});
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += +a[i];
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

n = parseInt(readline());
m = parseInt(readline());
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort((a,b)=>b-a);
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += a[i];
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

n = +readline();
m = +readline();
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(+readline());
}
a.sort((a,b)=>b-a);
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += +a[i];
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

var USB = readline();
var size = readline();
var usbArr = [], sum=0, howMany=0;

for(var i=0; i<USB; i++){
        usbArr.push(readline())
        usbArr[i] = parseInt(usbArr[i])
}

function descendingComparator(usbArr, b){return b-usbArr}

usbArr.sort(descendingComparator)
for(var j=0; j<USB && sum < size; j++){
        howMany++
        sum+=usbArr[j]

}

print(howMany)

var count = readline();   var read = new Array(count-1);
var filesize = parseInt(readline());
var calc = 0;

for (var i = 0; i < count; i++){read[i] = readline();}
read.sort(function(a, b){return b - a;})

for (var x = 0; x < count; x++){
if (read[x] < filesize){filesize -= read[x];calc+=1;}
else{calc+=1; x = count + 1;}
}
print(calc);

// 620B - Brooks Mershon
function drives(m, a) {
  var count = 0,
      sum = 0;

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

  for (var i = 0; i < a.length; i++) {
    if (sum >= m) return count;
    count++;
    sum += a[i];
  }

  return count;
}
var n = parseInt(readline());
var m = parseInt(readline());

var d = [];
for(var k = 0; k < n; k++) {
  d.push(parseInt(readline()));
}

print(drives(m, d));

// console.log(drives(5, [2, 1, 3]));

n = parseInt(readline());
m = parseInt(readline());
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort();
a.reverse();
var sum = parseInt(0);
for (var i = 0 ; i < n ; i ++)
{
    sum += parseInt(a[i]);
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

n = parseInt(readline());
m = parseInt(readline());
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort();
a.reverse();
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += a[i];
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

n = readline();
m = readline();
a = [];
for (i = 0 ; i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort();
a.reverse();

var sum = 0;
for (i = 0 ; i < n ; i ++){
    sum += a[i];
    if (sum >= m){
        write(i + 1);
        break;
    }
}

n = parseInt(readline());
m = parseInt(readline());
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort((a,b)=>b-a);
a.reverse();
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += a[i];
    print(sum);
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}

n = parseInt(readline());
m = parseInt(readline());
a = [];
for (var i = 0 ;  i < n ; i ++)
{
    a.push(parseInt(readline()));
}
a.sort((a,b)=>b-a);
var sum = 0;
for (var i = 0 ; i < n ; i ++)
{
    sum += a[i];
    print(sum);
    if (sum >= m)
    {
        write(i + 1);
        break;
    }
}


/*only to understand how to use JS on codeforces*/

var t = +readline()
for ( var i = 0 ; i < t ; i++ ) {
  var n = +readline()
    , s = readline()
    , p = s.indexOf('8')
  if ( p != -1 && n - p >= 11 )
    print('YES')
  else
    print('NO')
}

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

const lines = [];

readline.on('line', (line) => {
  lines.push(line);
});

const processLine = (len, str) => {
  if (len < 11) {
    return 'NO';
  }

  const prefixPosition = str.indexOf('8');
  if (prefixPosition === -1) {
    return 'NO';
  }

  if (len - prefixPosition >= 11) {
    return 'YES';
  }

  return 'NO';
};

readline.on('close', () => {
  const [t, ...cases] = lines;

  for (let i = 0; i < Number(t) * 2; i += 2) {
    const len = cases[i];
    const str = cases[i + 1];
    console.log(processLine(len, str));
  }
});

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

let i = 0;

readline.on('line', line => {
    if (i > 0 && i%2 == 0) {
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            console.log('YES');
        else
            console.log('NO');
    }
    i++;
});

const { createInterface } = require('readline');
const lines = []

function solve() {
    const t = +lines[0];
for (let i =2; i <= t * 2; i+=2 ) {
    const s = lines[i]
    const l = lines[i].length;
    const pos8 = s.indexOf('8');
    if (pos8 === -1 || (l - pos8) < 11) {
        console.log('NO')
    } else {
        console.log('YES')
    }
}
}
( function processLineByLine() {
    const rl = createInterface({
      input: process.stdin
    });

    rl.on('line', (line) => {
        lines.push(line);
      });
      rl.on('close', solve)

})();

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

let i = 0, result = '';

readline.on('line', line => {
    if (i > 0 && i%2 == 0) {
        line = line.trim();
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            console.log('YES');
        else
            console.log('NO');
    }
    i++;
});

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

let i = 0, result = '';

readline.on('line', line => {
    if (i > 0 && i%2 == 0) {
        line = line.trim();
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            result += 'YES\n';
        else
            result += 'NO\n';
    }
    i++;
});

readline.on('close', () => {
    console.log(result);
});

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

let i = 0;

readline.on('line', line => {
    if (i > 0 && i%2 == 0) {
        line = line.trim();
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            console.log('YES');
        else
            console.log('NO');
    }
    i++;
});

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var n = read.number();

    for(var i = 0; i < n ;i++) {
        var l = read.number();
        var s = readline();

        if(l >= 11 && s.slice(0,l - 10).indexOf('8') > -1) {
            print('YES');
        }
        else {
            print('NO');
        }
    }
}());

class CodeForcesNodeJS
{
    constructor()
    {
        this.stdin_input = "";
        this.arrInput = [];
        this.nInputIndex = 0;
    }

    start()
    {
        process.stdin.resume();
        process.stdin.setEncoding("utf-8");

        process.stdin.on("data", this.onData.bind(this));
        process.stdin.on("end", this.solveWrapper.bind(this));
    }

    onData(input)
    {
        this.stdin_input += input;
    }

    prepareInput(input)
    {
        this.arrInput = input.replace(/\n/g, " ").split(" ");
        this.nInputIndex = 0;
    }

    nextInput(strConvertType = null)
    {
        let _response = this.arrInput[this.nInputIndex];
        ++this.nInputIndex;

        if(typeof _response === "undefined")
        {
            throw new Error("End of input reached.");
        }

        if(typeof _response !== "string")
        {
            throw new Error("Internal Error: input at current step not an instance of string!");
        }

        switch(strConvertType)
        {
            case "Integer":
                _response = parseInt(_response, 10);
                break;

            case null:
                break;

            default:
                throw new Error("Unrecognized type for conversion!");
        }

        return _response;

    }

    async solveWrapper()
    {
        this.prepareInput(this.stdin_input);
        await this.solve().catch(console.error);
    }

    solve()
    {
        const _FIXED_LENGTH = 11;
        const _START_CHAR = "8";

        const _count = this.nextInput("Integer");
        for(let index = 0; index < _count; ++index)
        {
            const _length = this.nextInput("Integer");
            const _string = this.nextInput();

            const _start_index = _string.indexOf(_START_CHAR);

            if(_start_index === -1 || ((_length - _start_index) < _FIXED_LENGTH))
            {
                process.stdout.write("NO\n");
            }
            else
            {
                process.stdout.write("YEs\n");
            }
        }
    }
}

const _solver = new CodeForcesNodeJS();
_solver.start();

function main(input) {
    try
    {
        const _FIXED_LENGTH = 11;
        const _START_CHAR = "8";

        const arrInput = input.replace(/\n/g, " ").split(" ");
        let _input_index = 0;

        const _count = parseInt(arrInput[_input_index++], 10);
        for(let index = 0; index < _count; ++index)
        {
            const _length = parseInt(arrInput[_input_index++], 10);
            const _string = arrInput[_input_index++];

            const _start_index = _string.indexOf(_START_CHAR);

            if(_start_index === -1 || ((_length - _start_index) < _FIXED_LENGTH))
            {
                process.stdout.write("NO\n");
            }
            else
            {
                process.stdout.write("YEs\n");
            }
        }
    }
    catch(_error)
    {
        console.log(_error);
    }
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;
});

process.stdin.on("end", function () {
    main(stdin_input);
});

var t=+readline()
for(var i=0;i<t;i++){
	var n=+readline(),s=readline(),	p=s.indexOf('8');
	if(p!=-1&&n-p>=11) print('YES')
	else print('NO')
}

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  const idx = str.indexOf('8');
  const len = str.length - idx;

  if (idx === -1) {
    console.log('NO');
  }
  else if (len >= 11) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});

let input = [];

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

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

RL.on('close', () => {
    let k = parseInt(input[0]);

    for(let i = 2; i <= k*2; i+=2){
        let flag = false; let pos = 0;
        [...input[i]].forEach( (j, index) => {
            if(j === '8' && !flag){
                flag = true; pos = index; return;
            }
        });
        if(flag && input[i].length - pos >= 11)
            console.log("YES");
        else
            console.log("NO");
    }
});

let input = [];

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

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

RL.on('close', () => {
    let k = parseInt(input[0]);

    for(let i = 2; i <= k*2; i+=2){
        let flag = false; let pos = 0;
        [...input[i]].forEach( (j, index) => {
            if(j === '8' && !flag){
                flag = true; pos = index; return;
            }
        });
        if(flag && input[i].length - pos >= 8)
            console.log("YES");
        else
            console.log("NO");
    }
});

let input = [];

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

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

RL.on('close', () => {
    let k = parseInt(input[0]);

    for(let i = 2; i <= k*2; i+=2){
        let flag = false; let pos = 0;
        [...input[i]].forEach( (j, index) => {
            if(j === '8' && !flag){
                flag = true; pos = index+1; return;
            }
        });
        if(flag && input[i].length - pos >= 8)
            console.log("YES");
        else
            console.log("NO");
    }
});

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

const lines = [];

readline.on('line', (line) => {
  lines.push(line);
});

const processLine = (len, str) => {
  if (len < 11) {
    return 'NO';
  }

  const prefixPosition = str.indexOf('8');
  if (prefixPosition === -1) {
    return 'NO';
  }

  if (len - prefixPosition >= 11) {
    return 'YES';
  }

  return 'NO';
};

readline.on('close', () => {
  const [t, ...cases] = lines;

  for (let i = 0; i < Number(t); i += 1) {
    const len = cases[i];
    const str = cases[i + 1];
    console.log(processLine(len, str));
  }
});

let i = 0;
process.stdin.on('data', line => {
    if (i > 0 && i%2 == 0) {
        line = line.toString().trim();
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            console.log('YES');
        else
            console.log('NO');
    }
    i++;
});

let i = 0, result = '';

process.stdin.on('data', line => {
    if (i > 0 && i%2 == 0) {
        line = line.toString().trim();
        let pos = line.length;
        for (let i = 0; i < line.length; i++)
            if (line[i] == '8') {
                pos = i;
                break;
            }
        if (line.length - pos >= 11)
            result += 'YES\n';
        else
            result += 'NO\n';
    }
    i++;
});

process.stdin.on('end', () => {
    console.log(result);
});

function main(input) {
    try
    {
        const _FIXED_LENGTH = 11;
        const _START_CHAR = "8";

        const arrInput = input.replace(/\n/g, " ").split(" ");
        let _input_index = 0;

        const _count = parseInt(arrInput[_input_index++], 10);
        for(let index = 0; index < _count; ++i)
        {
            const _length = parseInt(arrInput[_input_index++], 10);
            const _string = arrInput[_input_index++];

            const _start_index = _string.indexOf(_START_CHAR);

            if(_start_index === -1 || ((_length - _start_index) < _FIXED_LENGTH))
            {
                process.stdout.write("NO\n");
            }
            else
            {
                process.stdout.write("YEs\n");
            }
        }
    }
    catch(_error)
    {
        console.log(_error);
    }
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;
});

process.stdin.on("end", function () {
    main(stdin_input);
});

function main(input) {
    try
    {
        const _FIXED_LENGTH = 11;
        const _START_CHAR = "8";

        const arrInput = examinputle.replace(/\n/g, " ").split(" ");
        let _input_index = 0;

        const _count = parseInt(arrInput[_input_index++], 10);
        for(let index = 0; index < _count; ++i)
        {
            const _length = parseInt(arrInput[_input_index++], 10);
            const _string = arrInput[_input_index++];

            const _start_index = _string.indexOf(_START_CHAR);

            if(_start_index === -1)
            {
                print("NO");
            }
            else if((_length - _start_index) >= _FIXED_LENGTH)
            {
                print("YES");
            }
            else
            {
                print("NO");
            }
        }
    }
    catch(_error)
    {
        console.log(_error);
    }
    process.stdout.write("\n Your input multiplied by 10="+input*10);
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;
});

process.stdin.on("end", function () {
    main(stdin_input);
});

try
{
    const _FIXED_LENGTH = 11;
    const _START_CHAR = "8";

    const _count = parseInt(readline(), 10);
    for(let index = 0; index < _count; ++i)
    {
        const _length = parseInt(readline(), 10);
        const _string = readline();
        const _start_index = _string.indexOf(_START_CHAR);

        if(_start_index === -1)
        {
            print("NO");
        }
        else if((_length - _start_index) >= _FIXED_LENGTH)
        {
            print("YES");
        }
        else
        {
            print("NO");
        }
    }
}
catch(_error)
{
    console.log(_error);
}

try
{
    const _FIXED_LENGTH = 11;
    const _START_CHAR = "8";

    const _count = parseInt(readline(), 10);
    for(let index = 0; index < _count; ++i)
    {
        const _length = parseInt(readline(), 10);
        const _string = readline();
        const _start_index = _string.indexOf(_START_CHAR);

        if(_start_index === -1)
        {
            print("NO");
        }
        else if((_length - _start_index) >= _FIXED_LENGTH)
        {
            print("YES");
        }
        else
        {
            print("NO");
        }
    }
}
catch(_error)
{
    console.error(_error);
}

function main(input) {
    try
    {
        const _FIXED_LENGTH = 11;
        const _START_CHAR = "8";

        const arrInput = input.replace(/\n/g, " ").split(" ");
        let _input_index = 0;

        const _count = parseInt(arrInput[_input_index++], 10);
        for(let index = 0; index < _count; ++i)
        {
            const _length = parseInt(arrInput[_input_index++], 10);
            const _string = arrInput[_input_index++];

            const _start_index = _string.indexOf(_START_CHAR);

            if(_start_index === -1)
            {
                print("NO");
            }
            else if((_length - _start_index) >= _FIXED_LENGTH)
            {
                print("YES");
            }
            else
            {
                print("NO");
            }
        }
    }
    catch(_error)
    {
        console.log(_error);
    }
    process.stdout.write("\n Your input multiplied by 10="+input*10);
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";

process.stdin.on("data", function (input) {
    stdin_input += input;
});

process.stdin.on("end", function () {
    main(stdin_input);
});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  const idx = str.indexOf('8');
  const len = str.length - idx;

  if (idx === -1) {
    console.log('NO');
  }
  else if (len >= 10) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  if (str.length < 11) {
    console.log('NO');
    return;
  }

  const idx = str.indexOf('8');

  if (idx === -1) {
    console.log('NO');
  }
  else {
    const len = str.length - idx;

    if (len <= 11) {
      console.log('NO');
    }
    else {
      console.log('YES');
    }
  }

  c++;
});

rl.on('close', () => {

});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  if (str.length < 11) {
    console.log('NO');
    return;
  }

  const idx = str.indexOf('8');

  if (idx === -1) {
    console.log('NO');
  }
  else {
    const len = str.length - idx;

    if (len < 11) {
      console.log('NO');
    }
    else {
      console.log('YES');
    }
  }

  c++;
});

rl.on('close', () => {

});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  const idx = str.indexOf('8');
  const len = str.length - idx;

  if (len >= 10) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  if (str.length < 11) {
    console.log('NO');
    return;
  }

  let i = 0;
  while (str.length > 11 && i < str.length) {
    if (str[i] !== '8') {
      str = str.substr(0, i) + str.substr(i + 1);
      i = 0;
    }
    else {
      i++;
    }
  }

  if (str.length === 11 && str[0] === '8') {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});

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

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

  if (c % 2 === 1) {
    c++;
    return;
  }

  const idx = str.indexOf('8');
  const len = str.length - idx;

  if (idx === -1) {
    console.log('NO');
    return;
  }

  if (len >= 10) {
    console.log('YES');
  }
  else {
    console.log('NO');
  }

  c++;
});

rl.on('close', () => {

});

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var n = read.number();

    for(var i = 0; i < n ;i++) {
        var l = read.number();
        var s = readline();

        if(l >= 11 && s.slice(0,l - 11).indexOf('8') > -1) {
            print('YES');
        }
        else {
            print('NO');
        }
    }
}());

(function () {
    var read = {
        number: function () {
            return +readline();
        },
        arr: function (divider) {
            return readline().split(divider ? divider : '');
        },
        arrNumber: function (divider) {
            return readline()
                .split(divider ? divider : '')
                .map(item => +item);
        }
    }

    var n = read.number();

    for(var i = 0; i < n ;i++) {
        var l = read.number();
        var s = readline();

        if(l >= 11 && s[l - 12] === '8') {
            print('YES');
        }
        else {
            print('NO');
        }
    }
}());


/**
 * Created by Grizix
 */

function readIntTabLine(n) {
  var l = readline().split(' ')
  for (var i = 0 ; i < n ; i++) {
    l[i] = parseInt(l[i])
  }
  return l
}

var n = parseInt(readline())

readline()

var p = readIntTabLine(2),
    dir = 1,
    result = 0

for (var i = 1 ; i < n ; i ++) {
  var np = readIntTabLine(2)
  switch (dir) {
    case 1:
      if (np[0] < p[0]) result++, dir = 4
      else dir = 2
      break
    case 2:
      if (np[1] > p[1]) result++, dir = 1
      else dir = 3
      break
    case 3:
      if (np[0] > p[0]) result++, dir = 2
      else dir = 4
      break
    case 4:
      if (np[1] < p[1]) result++, dir = 3
      else dir = 1
      break
  }
  p = np
}

print(result)

function isLeft(point1, point2, point3) {
    if (point1[0] === point2[0] &&
        point2[1] === point3[1]) {
        if (point2[1] > point1[1]) {
            return point3[0] < point2[0];
        } else {
            return point3[0] > point2[0];
        }
    } else {
        if (point2[0] > point1[0]) {
            return point3[1] > point2[1];
        } else {
            return point3[1] < point2[1];
        }
    }
}

var arr = readline().split(" ", 1).map(Number);
var n = arr[0], xArr, yArr, ans = 0;
for (var i = 0; i <= n; ++i) {
    arr = readline().split(" ", 2).map(Number);
    if (i === 0) {
        xArr = arr;
    } else if (i === 1) {
        yArr = arr;
    } else {
        if (isLeft(xArr, yArr, arr)) {
            ++ans;
        }
        xArr = yArr;
        yArr = arr;
    }
}
print(ans);


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

function For(a, b, cb) {
  let res;
  if (a < b) {
    for (let i = a; i <= b; i++) {
      if ((res = cb(i)) !== undefined) return res;
    }
  } else {
    for (let i = a; i >= b; i--) {
      if ((res = cb(i)) !== undefined) return res;
    }
  }
}

function Arr(a, b, cb, prev) {
  let p = prev || 0;
  if (a < b) return Array(b - a + 1).fill(0).map((v, i) => cb ? (p = cb(a + i, p)) : a + i);
  return Array(a - b + 1).fill(0).map((v, i) => cb ? (p = cb(a - i, p)) : a - i);
}

Object.defineProperty(Object.prototype, '$k', {
  value: function () { return Object.keys(this) }
});
Object.defineProperty(Object.prototype, '$v', {
  value: function () { return Object.values(this) }
});
Object.defineProperty(Object.prototype, '$kv', {
  value: function () { return Object.entries(this) }
});
Array.prototype.sum = function (fn) { return this.reduce((p, v) => p + (fn ? fn(v) : v), 0) }
Array.prototype.uniq = function (fn) {
  var set = new Set();
  return this.filter(v => {
    var newValue = !set.has(fn ? fn(v) : v);
    set.add(fn ? fn(v) : v);
    return newValue;
  });
}
Array.prototype.toObj = function (fn) {
  return this.map(v => fn(v)).reduce((p, v) => {
    p[v[0]] = v[1];
    return p;
  }, {})
}

function gcd(a, b) {
  if (!b) return a;
  return gcd(b, a % b);
}
function mod(a, n, m) {
  if (n == 0n) return 1n;
  if (n % 2n == 0n) return mod(a * a % m, n / 2n, m);
  return a * mod(a, n - 1n, m) % m;
}
function extendedEuclid(a, b) {
  if (!b) return [1, 0];
  else {
    let [x, y] = extendedEuclid(b, a % b);
    return [y, x - (a / b | 0) * y];
  }
}

function max(a, b) {
  if (a > b) return a;
  return b;
}

(async () => {
  await inputPromise;
  let inp = input.split(/\D+/).map(v => +v); r = 0;
  let t = inp[r++];
  For(1, t, i => {
    let n = inp[r++];
    let a = inp.slice(r,r=r+n);
    let c = Arr(0,100,i=>a.filter(v=>v==i).length);
    let d1 = Arr(0,101).find(i=>c[i]<1);
    let d2 = Arr(0,101).find(i=>c[i]<2);
    console.log(d1+d2);
  })
})();

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 = +readLine();
    const [arr1, arr2] = [Array(101).fill(0), Array(101).fill(0)];
    const arr = readLine()
      .split(" ")
      .map((n) => {
        n = parseInt(n);
        if (arr1[n] !== 0) arr2[n]++;
        else arr1[n]++;
        return n;
      });
    let ans = 0;

    for (let i = 0; i < arr1.length; i++) {
      if (arr1[i] === 0) {
        ans += i;
        break;
      }
    }

    for (let i = 0; i < arr2.length; i++) {
      if (arr2[i] === 0) {
        ans += i;
        break;
      }
    }
    console.log(ans);
  }
}

//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();
		list.sort(function(a, b){
			return a - b;
		});
		var a = [];
		var b = [];
		for(var j = 0; j < N; j++){
			if(a.indexOf(list[j]) == -1){
				a.push(list[j]);
			}else{
				b.push(list[j]);
			}
		}
		var amin = 0;
		var bmin = 0;
		for(var j = 0; j <= 100; j++){
			if(a.indexOf(j) != -1){
				amin++;
			}else{
				break;
			}
		}
		for(var j = 0; j <= 100; j++){
			if(b.indexOf(j) != -1){
				bmin++;
			}else{
				break;
			}
		}
		output[i] = amin + bmin;
	}
	myout(myconv(output, 9));
}

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')

    main()
})

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

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

const readLineOfBigInts = () => {
  const split = readLine().split(' ')
  const result = []
  for (let i = 0, l = split.length; i < l; i++) {
    result.push(BigInt(split[i]));
  }
  return result
}

const cmpi = (a, b) => a - b

function main() {
  let T = s2i(readLine())
  let out = ''

  while (T--) {
    const n = s2i(readLine())
    const a = readLine().split(' ').map(s2i)

    let result = 0
    const counts = []
    for (let i = 0; i <= 100; i++) {
      counts.push(0)
    }

    for (let i = 0, l = a.length; i < l; i++) {
      counts[a[i]] += 1
    }

    let add = 2

    if (counts[0] === 0) {
      out += '0\n'
      continue
    } else if (counts[0] === 1) {
      add = 1
    }

    for (let i = 1; i <= 100; i++) {
      const x = counts[i]
      result += add
      if (x === 0) break
      else if (x === 1) {
        add = 1
      }
    }

    out += result + '\n'
  }

  console.log(out)
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const testQtd = readline();

    for (let i = 0; i < testQtd; i++) {
        const length = parseInt(readline());
        if (length === 0) {
            console.log(0);
            continue;
        }

        const array = readline().split(' ').map(x => parseInt(x)).sort((a, b) => a - b);

        let a = [];
        let b = [];
        let bigger = array[0]

        for (let i = 0; i < array.length; i++) {
            if (array[i] > bigger) {
                bigger = array[i];
            }

            const found = a.find(x => x === array[i]);

            if (found !== undefined) {
                b.push(array[i]);
            } else {
                a.push(array[i]);
            }
        }

        let respA = null;
        let respB = null;
        for (let i = 0; i <= bigger + 1; i++) {
            if (respA === null && a.find(x => x === i) === undefined) {
                respA = i;
            }
            if (respB === null && b.find(x => x === i) === undefined) {
                respB = i;
            }

            if (respA !== null && respB !== null) {
                console.log(respA + respB);
                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 main() {

    const testQtd = readline();

    for (let i = 0; i < testQtd; i++) {
        const length = parseInt(readline());
        if (length === 0) {
            console.log(0);
            continue;
        }

        const array = readline().split(' ').map(x => parseInt(x)).sort((a, b) => a - b);

        let a = [];
        let aIsDead = false;
        let b = [];
        let bIsDead = false;
        let bigger = array[0]

        for (let i = 0; i < array.length; i++) {
            if (array[i] > bigger) {
                bigger = array[i];
            }

            if (!aIsDead) {
                const found = a.find(x => x === array[i]);

                if (found !== undefined) {
                    if (!bIsDead) {
                        b.push(array[i]);
                    }
                } else {
                    a.push(array[i]);
                }
            } else {
                if (!bIsDead) {
                    b.push(array[i]);
                }
            }
        }

        let respA = null;
        let respB = null;
        for (let i = 0; i <= bigger + 1; i++) {
            if (respA === null && a.find(x => x === i) === undefined) {
                respA = i;
            }
            if (respB === null && b.find(x => x === i) === undefined) {
                respB = i;
            }

            if (respA !== null && respB !== null) {
                console.log(respA + respB);
                break;
            }
        }
    }
}

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 = pi(readline());
        let arr = ti(readline().split(' '));

        let map = new Array(105);
        map.fill(0);
        let max = 0;
        for(let i = 0; i < n; i++){
            map[arr[i]] += 1;
            max = Math.max(max, arr[i]);
        }

        if(map[0] === 0){
            console.log(0);
            continue;
        }

        let a = [];
        let b = [];
        let aMax = 0;
        let bMax = 0;
        for(let i = 0; i <= max; i++){
            if(map[i] >= 2){
                a.push(i);
                b.push(i);
                aMax = i;
                bMax = i;
            }else if(map[i] !== 0){
                a.push(i);
                aMax = i;
            }
        }

        let res = 0;
        let mapA = new Array(aMax+2);
        let mapB = new Array(bMax+2);
        mapA.fill(0);
        mapB.fill(0);
        for(let i = 0; i < a.length; i++)
            mapA[a[i]] = 1;

        for(let i = 0; i < b.length; i++)
            mapB[b[i]] = 1;

        for(let i = 0; i < aMax+2; i++){
            if(mapA[i] === 0){
                res += i;
                break;
            }
        }

        for(let i = 0; i < bMax+2; i++){
            if(mapB[i] === 0){
                res += i;
                break;
            }
        }

        if(res === 0)
            console.log(max + 1);
        else
            console.log(res);
    }
}

function B(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let n = pi(readline());
        let a = ti(readline().split(' '));
        let neg = [];
        let pos = [];

        for(let i = 0; i < n; i++){
            if(a[i] < 0){
                neg.push({val: a[i], index: i});
            }else{
                pos.push({val: a[i], index: i});
            }
        }

        neg.sort((a,b) => a.val - b.val);
        pos.sort((a,b) => b.val - a.val);

    }
}

var cases = parseInt(readline());
for(var i = 0; i<cases; i++){
    var test = parseInt(readline());
    var input = readline().split(" ").map(x=>parseInt(x));
    input.sort(function(a,b){return a-b});
    var A = [];
    var B = [];
    var result = 0;
    for(var j = 0; j< input.length; j ++){
        if(!A.includes(input[j]))A.push(input[j]);
        else B.push(input[j]);
    }
    for(var x of [A,B]){
        var n = find(x);
        result+=n;
    }
    print(result);
}

function find (input){
    for(var k=0; k<=input[input.length-1]+1; k++){
        if(!input.includes(k)) return k;
    }
    return 0;
}