DZY has a sequence a, consisting of n integers.We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.You only need to output the length of the subsegment you find.

The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

In a single line print the answer to the problem — the maximum length of the required subsegment.

NoteYou can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4.

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

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

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

function main() {
	var n = parseInt(readline()),
		data = tokenizeIntegers(readline()),
		increasing = {},
		start = 0, starts = [];
	while (start < n) {
		var seek = start+1;
		while (seek < n && data[seek] > data[seek-1]) {
			++seek;
		}
		increasing[start] = seek-start;
		starts.push(start);
		start = seek;
	}
	var max = increasing[starts[0]];
	if (starts.length != 1) {
		max = Math.max(max, increasing[starts[starts.length-1]]+1);
	}
	for (var i = 1; i < starts.length; ++i) {
		var hinge = starts[i],
			prefix = increasing[starts[i-1]],
			suffix = increasing[starts[i]];
		if (suffix != 1 && (data[hinge-1]+1 < data[hinge+1] ||
					data[hinge-2]+1 < data[hinge])) {
			max = Math.max(max, prefix+suffix);
		} else {
			max = Math.max(max, prefix+1);
		}
	}
	print(max);
}

main();

var n = readline()*1;
var arr = readline().split(" ");
//=====================================================
var seqIni = [];
var seqLen = [];

var ini = -1;
var len = 1;

for (var i = 0; i < arr.length-1; i++) {
  if(arr[i]*1 < arr[i+1]*1){
    if(ini == -1){
      ini = i;
    }
    len++;
  }else{
    if(ini != -1){
      seqIni.push(ini);
      seqLen.push(len);
      ini = -1;
      len = 1;
    }
  }
}
if(ini != -1){
  seqIni.push(ini);
  seqLen.push(len);
}
/*
console.log(arr);
console.log(seqIni);
console.log(seqLen);
*/
//===================================================
if(arr.length == 1){
  var mayor = 1;
}else{
  var mayor = 2;

  for (var i = 0; i < arr.length-2; i++) {
    if(arr[i]*1+2 <= arr[i+2]*1 && ((arr[i]*1 >= arr[i+1]*1) || (arr[i+1]*1 >= arr[i+2]*1))){
      var l= buscar(i,i+1)+1+buscar(i+2,i+1);
      if(l > mayor){
        mayor = l;
      }
    }
  }
  var r= buscar(0,0)+1;
  if(r > mayor){
    mayor = r;
  }
  r= buscar(arr.length-1,arr.length-1)+1;
  if(r > mayor){
    mayor = r;
  }

  for (var i = 0; i < seqIni.length; i++) {
    if(seqLen[i]+1 <= arr.length){
      if(seqLen[i]+1 > mayor){
        mayor = seqLen[i]+1;
      }
    }else{
      if(seqLen[i] > mayor){
        mayor = seqLen[i];
      }
    }
  }

}

function buscar(i,elMalo){
  for(var j=0; j< seqIni.length; j++){
    if(i >= seqIni[j] && i <= seqIni[j]+seqLen[j]-1){
      //console.log(i,elMalo);
      if(elMalo >= seqIni[j] && elMalo <= seqIni[j]+seqLen[j]-1){
        return seqLen[j]-1;
      }
      return seqLen[j];
    }
  }
  return 1;
}

print(mayor);

;(function () {

	print(function (n) {

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

		var p = 0, l = [];
		for (var i = 1; i < n; i++) {
			if (s[i] <= s[i-1]) {
				l.push(i - p);
				p = i;
			}
		}
		l.push(n - p);

		var k = [];
		l.forEach(function (e) {
			k.push(s.splice(0, e));
		});

		k.push([]); k.unshift([]);

		var max = 0;
		for (var i = 0; i < l.length + 1; i++) {
			var a = k[i], b = k[i + 1];

			if (a.length === 0 || b.length === 0) {
				max = Math.max(max, a.length + b.length);
			} else
			if (a.length === 1 || b.length === 1) {
				max = Math.max(max, a.length + b.length);
			} else
			if (b[0] - a.slice(-2)[0] > 1 || b[1] - a.slice(-1)[0] > 1) {
				max = Math.max(max, a.length + b.length);
			} else
			if (true) {
				max = Math.max(max, a.length + 1, b.length + 1);
			}
		}

		return max;

	}(+readline()));

}.call(this));

var n = parseInt(readline());
var line = readline().split(' ');
var a = new Int32Array(n);
var inc = new Int32Array(n);
var dec = new Int32Array(n);
var i;
for (i = 0; i < n; i++) {
  a[i] = parseInt(line[i]);
}

inc[0] = 1;
for (i = 1; i < n; i++) {
  if (a[i] > a[i-1]) {
    inc[i] = inc[i-1]+1;
  } else {
    inc[i] = 1;
  }
}

dec[n-1] = 1;
for (i = n-2; i >= 0; i--) {
  if (a[i] < a[i+1]) {
    dec[i] = dec[i+1]+1;
  } else {
    dec[i] = 1;
  }
}

var max = n;
if (n > 2) {
  max = Math.max(dec[1]+1, inc[n-2]+1);
}

for (i = 1; i < n-1; i++) {
  if (a[i] <= a[i-1] || a[i] >= a[i+1]) { // si hay un hoyo
    if (a[i-1]+1 < a[i+1]) { // si se arregla la serie con un cambio
      max = Math.max(max, inc[i-1] + dec[i+1] + 1);
    } else { // si el cambio solamente agrega un elemento a las series originales
      max = Math.max(max, inc[i-1]+1, dec[i+1]+1);
    }
  }
}

print(max);

function main() {
    var n = Number(readline());
    var data = readline().split(' ').map(Number);

    var l = [1];
    for(var i=1;i<n;i++){
        if(data[i] > data[i-1]){
            l[i] = l[i-1] + 1;
        } else {
            l[i] = 1;
        }
    }
    var r = [];
    r[n-1] = 1;
    for(var i=n-2;i>=0;i--){
        if(data[i] < data[i+1]){
            r[i] = r[i+1] + 1;
        } else {
            r[i] = 1;
        }
    }
    var max = Math.max(...r);
    if(max == data.length){
        return print(max);
    } else {
        max++;
    }
    for(var i=1;i<n-1;i++){
        if(data[i-1] + 1 < data[i+1]){
           max = Math.max(max, l[i-1] + 1 + r[i+1])
        }
    }
    print(max)
}

main()

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

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

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

function main() {
	var n = parseInt(readline()),
		data = tokenizeIntegers(readline()),
		increasing = {},
		start = 0, starts = [];
	while (start < n) {
		var seek = start+1;
		while (seek < n && data[seek] > data[seek-1]) {
			++seek;
		}
		increasing[start] = seek-start;
		starts.push(start);
		start = seek;
	}
	var max = increasing[starts[0]];
	for (var i = 1; i < starts.length; ++i) {
		var hinge = starts[i],
			prefix = increasing[starts[i-1]],
			suffix = increasing[starts[i]];
		if (suffix != 1 && data[hinge-1]+1 < data[hinge+1]) {
			max = Math.max(max, prefix+suffix);
		} else {
			max = Math.max(max, prefix+1);
		}
	}
	print(max);
}

main();

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

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

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

function main() {
	var n = parseInt(readline()),
		data = tokenizeIntegers(readline()),
		increasing = {},
		start = 0, starts = [];
	while (start < n) {
		var seek = start+1;
		while (seek < n && data[seek] > data[seek-1]) {
			++seek;
		}
		increasing[start] = seek-start;
		starts.push(start);
		start = seek;
	}
	var max = increasing[starts[0]];
	for (var i = 1; i < starts.length; ++i) {
		var hinge = starts[i],
			prefix = increasing[starts[i-1]],
			suffix = increasing[starts[i]];
		if (suffix != 1 && data[hinge]+1 < data[hinge+1]) {
			max = Math.max(max, prefix+suffix);
		} else {
			max = Math.max(max, prefix+1);
		}
	}
	print(max);
}

main();

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

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

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

function main() {
	var n = parseInt(readline()),
		data = tokenizeIntegers(readline()),
		increasing = {},
		start = 0, starts = [];
	while (start < n) {
		var seek = start+1;
		while (seek < n && data[seek] > data[seek-1]) {
			++seek;
		}
		increasing[start] = seek-start;
		starts.push(start);
		start = seek;
	}
	var max = increasing[starts[0]];
	if (starts.length > 1) {
		max = Math.max(max, 1+increasing[starts[starts.length-1]]);
	}
	for (var i = 1; i < starts.length; ++i) {
		var hinge = starts[i],
			prefix = increasing[starts[i-1]],
			suffix = increasing[starts[i]];
		if (suffix != 1 && data[hinge-1]+1 < data[hinge+1]) {
			max = Math.max(max, prefix+suffix);
		} else {
			max = Math.max(max, prefix+1);
		}
	}
	print(max);
}

main();

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

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

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

function main() {
	var n = parseInt(readline()),
		data = tokenizeIntegers(readline()),
		increasing = {},
		start = 0, starts = [];
	while (start < n) {
		var seek = start+1;
		while (seek < n && data[seek] > data[seek-1]) {
			++seek;
		}
		increasing[start] = seek-start;
		starts.push(start);
		start = seek;
	}
	var max = increasing[starts[0]];
	for (var i = 1; i < starts.length; ++i) {
		var hinge = starts[i],
			prefix = increasing[starts[i-1]],
			suffix = increasing[starts[i]];
		if (suffix != 1 && (data[hinge-1]+1 < data[hinge+1] ||
					data[hinge-2]+1 < data[hinge])) {
			max = Math.max(max, prefix+suffix);
		} else {
			max = Math.max(max, prefix+1);
		}
	}
	print(max);
}

main();

var n = readline()*1;
var arr = readline().split(" ");
//=====================================================
var seqIni = [];
var seqLen = [];

var ini = -1;
var len = 1;

for (var i = 0; i < arr.length-1; i++) {
  if(arr[i]*1 < arr[i+1]*1){
    if(ini == -1){
      ini = i;
    }
    len++;
  }else{
    if(ini != -1){
      seqIni.push(ini);
      seqLen.push(len);
      ini = -1;
      len = 1;
    }
  }
}
if(ini != -1){
  seqIni.push(ini);
  seqLen.push(len);
}
/*
console.log(arr);
console.log(seqIni);
console.log(seqLen);
*/
//===================================================
if(arr.length == 1){
  var mayor = 1;
}else{
  var mayor = 2;

  for (var i = 0; i < arr.length-2; i++) {
    if(arr[i]*1+2 <= arr[i+2]*1 && (arr[i]*1 >= arr[i+1]*1) || (arr[i+1]*1 >= arr[i+2]*1)){
      var l= buscar(i,i+1)+1+buscar(i+2,i+1);
      if(l > mayor){
        mayor = l;
      }
    }
  }

  var r= buscar(0,0)+1;
  if(r > mayor){
    mayor = r;
  }
  r= buscar(arr.length-1,arr.length-1)+1;
  if(r > mayor){
    mayor = r;
  }

  for (var i = 0; i < seqIni.length; i++) {
    if(seqLen[i]+1 <= arr.length){
      if(seqLen[i]+1 > mayor){
        mayor = seqLen[i]+1;
      }
    }else{
      if(seqLen[i] > mayor){
        mayor = seqLen[i];
      }
    }
  }

}

function buscar(i,elMalo){
  for(var j=0; j< seqIni.length; j++){
    if(i >= seqIni[j] && i <= seqIni[j]+seqLen[j]-1){
      if(elMalo >= seqIni[j] && elMalo <= seqIni[j]+seqLen[j]-1){
        return seqLen[j]-1;
      }
      return seqLen[j];
    }
  }
  return 1;
}

print(mayor);

var n = readline()*1;
var arr = readline().split(" ");
//=====================================================
var seqIni = [];
var seqLen = [];

var ini = -1;
var len = 1;

for (var i = 0; i < arr.length-1; i++) {
  if(arr[i]*1 < arr[i+1]*1){
    if(ini == -1){
      ini = i;
    }
    len++;
  }else{
    if(ini != -1){
      seqIni.push(ini);
      seqLen.push(len);
      ini = -1;
      len = 1;
    }
  }
}
if(ini != -1){
  seqIni.push(ini);
  seqLen.push(len);
}
/*
console.log(arr);
console.log(seqIni);
console.log(seqLen);
*/
//===================================================
if(arr.length == 1){
  var mayor = 1;
}else{
  var mayor = 2;

  for (var i = 0; i < arr.length-2; i++) {
    if(arr[i]*1+2 <= arr[i+2]*1 && arr[i]*1 >= arr[i+1]*1){
      var l= buscar(i,i+1)+1+buscar(i+2,i+1);
      if(l > mayor){
        mayor = l;
      }
    }
  }

  var r= buscar(0,0)+1;
  if(r > mayor){
    mayor = r;
  }
  r= buscar(arr.length-1,arr.length-1)+1;
  if(r > mayor){
    mayor = r;
  }

  for (var i = 0; i < seqIni.length; i++) {
    if(seqLen[i]+1 <= arr.length){
      if(seqLen[i]+1 > mayor){
        mayor = seqLen[i]+1;
      }
    }else{
      if(seqLen[i] > mayor){
        mayor = seqLen[i];
      }
    }
  }

}

function buscar(i,elMalo){
  for(var j=0; j< seqIni.length; j++){
    if(i >= seqIni[j] && i <= seqIni[j]+seqLen[j]-1){
      if(elMalo >= seqIni[j] && elMalo <= seqIni[j]+seqLen[j]-1){
        return seqLen[j]-1;
      }
      return seqLen[j];
    }
  }
  return 1;
}

print(mayor);

var n = readline()*1;
var arr = readline().split(" ");

var mayor = 0;

for (var i = 0; i < arr.length-2; i++) {
  if(arr[i]*1+2== arr[i+2]*1){
    var l=3;
    var j= i;
    while(j-1>=0){
      if(arr[j-1]*1 == arr[j]-1){
        l++;
        j--;
      }else{
        break;
      }
    }
    var j= i+2;
    while(j+1<arr.length){
      if(arr[j+1]*1 == arr[j]*1+1){
        l++;
        j++;
      }else{
        break;
      }
    }
    if(l > mayor){
      mayor = l;
    }
  }
}

print(mayor);

;(function () {

	print(function (n) {

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

		var p = 0, l = [];
		for (var i = 1; i < n; i++) {
			if (s[i] <= s[i-1]) {
				l.push(i - p);
				p = i;
			}
		}
		l.push(n - p);

		var k = [];
		l.forEach(function (e) {
			k.push(s.splice(0, e));
		});

		k.push([]); k.unshift([]);

		var max = 0;
		for (var i = 0; i < l.length - 1; i++) {
			var a = k[i], b = k[i + 1];

			if (a.length === 1 || b.length === 1) {
				max = Math.max(max, a.length + b.length);
			} else
			if (b[0] - a.slice(-2)[0] > 1 || b[1] - a.slice(-1)[0] > 1) {
				max = Math.max(max, a.length + b.length);
			} else
			if (true) {
				max = Math.max(max, a.length + 1, b.length + 1);
			}
		}

		return max;

	}(+readline()));

}.call(this));

;(function () {

	print(function (n) {

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

		var p = 0, l = [];
		for (var i = 1; i < n; i++) {
			if (s[i] <= s[i-1]) {
				l.push(i - p);
				p = i;
			}
		}
		l.push(n - p);

		var k = [];
		l.forEach(function (e) {
			k.push(s.splice(0, e));
		});

		k.push([]); k.unshift([]);

		var max = 0;
		for (var i = 0; i < l.length + 1; i++) {
			var a = k[i], b = k[i + 1];

			if (a.length === 1 || b.length === 1) {
				max = Math.max(max, a.length + b.length);
			} else
			if (b[0] - a.slice(-2)[0] > 1 || b[1] - a.slice(-1)[0] > 1) {
				max = Math.max(max, a.length + b.length);
			} else
			if (true) {
				max = Math.max(max, a.length + 1, b.length + 1);
			}
		}

		return max;

	}(+readline()));

}.call(this));

;(function () {

	print(function (n) {

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

		var p = 0, l = [];
		for (var i = 1; i < n; i++) {
			if (s[i] <= s[i-1]) {
				l.push(i - p);
				p = i;
			}
		}
		l.push(n - p);

		var k = [];
		l.forEach(function (e) {
			k.push(s.splice(0, e));
		});

		var max = 0;
		for (var i = 0; i < l.length - 1; i++) {
			var a = k[i], b = k[i + 1];

			if (a.length === 1 || b.length === 1) {
				max = Math.max(max, a.length + b.length);
			} else
			if (b[0] - a.slice(-2)[0] > 1 || b[1] - a.slice(-1)[0] > 1) {
				max = Math.max(max, a.length + b.length);
			} else
			if (true) {
				max = Math.max(max, a.length + 1, b.length + 1);
			}
		}

		return max;

	}(+readline()));

}.call(this));

;(function () {

	print(function (n) {

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

		var p = 0, l = [];
		for (var i = 1; i < n; i++) {
			if (s[i] <= s[i-1]) {
				l.push(i - p);
				p = i;
			}
		}
		l.push(n - p);

		var k = [];
		l.forEach(function (e) {
			k.push(s.splice(0, e));
		});

		var max = 0;
		for (var i = 0; i < l.length - 1; i++) {
			var a = k[i], b = k[i + 1];

			if (a.length === 1 || b.length === 1) {
				max = Math.max(max, a.length + b.length);
			} else
			if (b[0] - a.slice(-2)[0] > 1 || b[1] - a.slice(-1)[0] > 1) {
				max = Math.max(max, a.length + b.length);
			} else
			if (true) {
				max = Math.max(max, a.length + 1, b.length + 1);
			}
		}

		return max || 1;

	}(+readline()));

}.call(this));

;(function () {

	print(function (n) {

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

		var p = 0, l = [];
		for (var i = 1; i < n; i++) {
			if (s[i] <= s[i-1]) {
				l.push(i - p);
				p = i;
			}
		}
		l.push(n - p);

		var k = [];
		for (var i = 1, _i = l.length; i < _i; i++) {
			k.push(l[i - 1] + l[i]);
		}

		return Math.max.apply(null, k);

	}(+readline()));

}.call(this));

var n = parseInt(readline());
var line = readline().split(' ');
var a = new Int32Array(n);
var inc = new Int32Array(n);
var dec = new Int32Array(n);
var i;
for (i = 0; i < n; i++) {
  a[i] = parseInt(line[i]);
}

inc[0] = 1;
for (i = 1; i < n; i++) {
  if (a[i] > a[i-1]) {
    inc[i] = inc[i-1]+1;
  } else {
    inc[i] = 1;
  }
}

dec[n-1] = 1;
for (i = n-1; i >= 0; i--) {
  if (a[i] < a[i+1]) {
    dec[i] = dec[i+1]+1;
  } else {
    dec[i] = 1;
  }
}

var max = 1;
if (n > 1) {
  max = dec[1]+1;
}

for (i = 1; i < n; i++) {
  if (a[i] <= a[i-1]) { // si hay un hoyo
    if (i < n-1) { // si hay siguiente
      if (a[i-1]+1 < a[i+1]) { // si se arregla la serie con un cambio
        max = Math.max(max, inc[i-1] + dec[i+1] + 1);
      } else { // si el cambio solamente agrega un elemento a las series originales
        max = Math.max(max, inc[i-1]+1, dec[i+1]+1);
      }
    } else {
      max = Math.max(max, inc[i-1]+1);
    }
  }
}

print(max);

var n = parseInt(readline());
var line = readline().split(' ');
var a = new Int32Array(n);
var inc = new Int32Array(n);
var dec = new Int32Array(n);
var i;
for (i = 0; i < n; i++) {
  a[i] = parseInt(line[i]);
}

inc[0] = 1;
for (i = 1; i < n; i++) {
  if (a[i] > a[i-1]) {
    inc[i] = inc[i-1]+1;
  } else {
    inc[i] = 1;
  }
}

dec[n-1] = 1;
for (i = n-2; i >= 0; i--) {
  if (a[i] < a[i+1]) {
    dec[i] = dec[i+1]+1;
  } else {
    dec[i] = 1;
  }
}

var max = 1;
if (n > 1) {
  max = dec[1]+1;
}

for (i = 1; i < n; i++) {
  if (a[i] <= a[i-1]) { // si hay un hoyo
    if (i < n-1) { // si hay siguiente
      if (a[i-1]+1 < a[i+1]) { // si se arregla la serie con un cambio
        max = Math.max(max, inc[i-1] + dec[i+1] + 1);
      } else { // si el cambio solamente agrega un elemento a las series originales
        max = Math.max(max, inc[i-1]+1, dec[i+1]+1);
      }
    } else {
      max = Math.max(max, inc[i-1]+1);
    }
  }
}

print(max);


Alice and Bob are playing a game on a matrix, consisting of $$$2$$$ rows and $$$m$$$ columns. The cell in the $$$i$$$-th row in the $$$j$$$-th column contains $$$a_{i, j}$$$ coins in it.Initially, both Alice and Bob are standing in a cell $$$(1, 1)$$$. They are going to perform a sequence of moves to reach a cell $$$(2, m)$$$.The possible moves are:   Move right — from some cell $$$(x, y)$$$ to $$$(x, y + 1)$$$;  Move down — from some cell $$$(x, y)$$$ to $$$(x + 1, y)$$$. First, Alice makes all her moves until she reaches $$$(2, m)$$$. She collects the coins in all cells she visit (including the starting cell).When Alice finishes, Bob starts his journey. He also performs the moves to reach $$$(2, m)$$$ and collects the coins in all cells that he visited, but Alice didn't.The score of the game is the total number of coins Bob collects.Alice wants to minimize the score. Bob wants to maximize the score. What will the score of the game be if both players play optimally?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of the testcase contains a single integer $$$m$$$ ($$$1 \le m \le 10^5$$$) — the number of columns of the matrix. The $$$i$$$-th of the next $$$2$$$ lines contain $$$m$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i,m}$$$ ($$$1 \le a_{i,j} \le 10^4$$$) — the number of coins in the cell in the $$$i$$$-th row in the $$$j$$$-th column of the matrix. The sum of $$$m$$$ over all testcases doesn't exceed $$$10^5$$$.

For each testcase print a single integer — the score of the game if both players play optimally.

NoteThe paths for the testcases are shown on the following pictures. Alice's path is depicted in red and Bob's path is depicted in blue.

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
function solve(e, n, t) {
  if (e <= 1) return 0
  let s = 0
  for (let t = 0; t < e; ++t) s += n[t]
  let i = Number.MAX_SAFE_INTEGER
  for (let r = 0, o = 0, d = 0; r < e; ++r) {
    o += n[r]
    const e = Math.max(s - o, d)
    ;(d += t[r]), i > e && (i = e)
  }
  return i
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve(
      Number(e.readLine()),
      e.readIntegersOfLine(),
      e.readIntegersOfLine(),
    )
    e.print(n + '\n')
  }
})

'use strict'
Object.defineProperty(exports, '__esModule', { value: !0 })
var os = require('os')
const stdin = process.stdin,
  stdout = process.stdout,
  integerRegex = /-?\d+/g,
  decimalRegex = /-?\d+(?:\.\d+)?/g
class InputAndOutput {
  lineIndex = 0
  lines = []
  dried() {
    return this.lineIndex >= this.lines.length
  }
  readLine() {
    const e = this.lines[this.lineIndex]
    return (this.lineIndex += 1), e
  }
  readIntegersOfLine() {
    const e = this.readLine().match(integerRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  readNumsOfLine() {
    const e = this.readLine().match(decimalRegex)
    return null == e ? [] : e.map(e => Number(e))
  }
  print(e) {
    stdout.write(e)
  }
  async init() {
    const e = await this.readLines()
    this.lines = e
  }
  readLines() {
    const e = []
    return new Promise(n => {
      stdin.on('data', n => e.push(n)),
        stdin.on('end', function () {
          const t = e.join('').split(os.EOL)
          n(t)
        })
    })
  }
}
async function __main__(e) {
  const n = new InputAndOutput()
  await n.init(), e(n)
}
const MAX_N = 100010,
  sum1 = new Array(MAX_N)
function solve(e, n, t) {
  if (e <= 1) return 0
  sum1[0] = n[0]
  for (let t = 1; t < e; ++t) sum1[t] = sum1[t - 1] + n[t]
  const s = e - 1
  let i = sum1[s] - n[0]
  for (let n = 1, r = t[0]; n < e; ++n) {
    const e = Math.max(sum1[s] - sum1[n], r)
    ;(r += t[n]), i > e && (i = e)
  }
  return i
}
__main__(function (e) {
  const n = Number(e.readLine())
  for (let t = 1; t <= n; ++t) {
    const n = solve(
      Number(e.readLine()),
      e.readIntegersOfLine(),
      e.readIntegersOfLine(),
    )
    e.print(n + '\n')
  }
})

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr1 = iInpArr();
    let arr2 = iInpArr();
    let psum1 = [],
      psum2 = [],
      s1 = 0,
      s2 = 0;
    for (let i = 0; i < n; i++) {
      s1 += arr1[i];
      s2 += arr2[i];
      psum1[i] = s1;
      psum2[i] = s2;
    }
    let ans = Infinity,
      end = n - 1,
      st = 0;
    for (let i = 0; i < n; i++) {
      let v1 = psum1[end] - psum1[i];
      let v2 = i !== 0 ? psum2[i - 1] : 0;
      ans = Math.min(ans, Math.max(v1, v2));
    }
    console.log(ans);
  }
};
solve();

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

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

const INF = Number.POSITIVE_INFINITY;
function main () {
	let t = rn();
	while (t--) {
		let m = rna();
		let a = [];
		a[0] = rna();
		a[1] = rna();

		let sm1 = 0;
		for (let i = 0; i < m; i++)
			sm1 += a[0][i];

		let ans = INF;
		for(let i = 0, cursm1 = cursm2 = 0; i < m; i++) {
			cursm1 += a[0][i];
			cursm2 += a[1][i];
			ans = Math.min(ans, Math.max(sm1 - cursm1, cursm2 - a[1][i]))
		}

		console.log(ans);
	}
}

var readline = require('readline');

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

function solve(n, a, b) {
    const sa = []
    a.forEach((x, i) => sa[i] = i ? x + sa[i - 1] : x)
    const sb = []
    b.forEach((x, i) => sb[i] = i ? x + sb[i - 1] : x)

    let min = Infinity
    for (let i = 0; i < n; i++) {
        // row 0, 0-i is a
        // row 1, i-n is a
        const score = Math.max(sa[n - 1] - sa[i], i ? sb[i - 1] : 0)
        min = Math.min(min, score)
    }
    return min
}

var T = parseInt(readline());

for (var t = 0; t < T; t++) {
    var m = parseInt(readline());
    var a1 = readline().split(' ').map((x) => parseInt(x));
    var a2 = readline().split(' ').map((x) => parseInt(x));

    var acc1 = 0, acc2 = 0;
    for (var i = 0; i < m; i++) {
        acc1 += a1[i];
    }

    var mi = Infinity;
    for (var i = 0; i < m; i++) {
        acc1 -= a1[i];
        mi = Math.min(mi, Math.max(acc1, acc2));
        acc2 += a2[i];
    }
    print(mi);
}

var limit = parseInt(readline());
    for (var i = 0; i < limit; i++) {
        var caseLength = parseInt(readline());
        var topArray = readline().split(" ");
        var bottomArray = readline().split(" ");
        var topIntArray = new Array(caseLength);
        topIntArray[0] = 0;
        var bottomIntArray = new Array(caseLength);
        bottomIntArray[caseLength - 1] = 0;
        var index = 0;
        var revIndex = caseLength - 1;
        var topTotal = 0;
        var bottomTotal = 0;
        while (index < caseLength - 1) {
            var topValue = parseInt(topArray[revIndex]);
            topTotal += topValue;
            topIntArray[revIndex] = topTotal;
            var bottomValue = parseInt(bottomArray[index]);
            bottomTotal += bottomValue;
            bottomIntArray[index] = bottomTotal;
            index++;
            revIndex--;
        }
        var minValue = Math.min(topTotal, bottomTotal);
        for (var k = 1; k < caseLength - 1; k++) {
            var higher = Math.max(topIntArray[k + 1], bottomIntArray[k - 1]);
            minValue = (higher < minValue) ? higher : minValue;
        }
        print(minValue);
    }

var T = parseInt(readline());

for (var t = 0; t < T; t++) {
    var m = parseInt(readline());
    var a1 = readline().split(' ').map((x) => parseInt(x));
    var a2 = readline().split(' ').map((x) => parseInt(x));

    var acc1 = 0, acc2 = 0;
    for (var i = 0; i < m; i++) {
        acc1 += a1[i];
    }

    var mi = 10000000;
    for (var i = 0; i < m; i++) {
        acc1 -= a1[i];
        mi = Math.min(mi, Math.max(acc1, acc2));
        acc2 += a2[i];
    }
    print(mi);
}

var T = parseInt(readline());

for (var t = 0; t < T; t++) {
    var m = parseInt(readline());
    var a1 = readline().split(' ').map((x) => parseInt(x));
    var a2 = readline().split(' ').map((x) => parseInt(x));

    var acc1 = 0, acc2 = 0;
    for (var i = 0; i < m; i++) {
        acc1 += a1[i];
    }

    var m = 10000000;
    for (var i = 0; i < m; i++) {
        acc1 -= a1[i];
        print(m, acc1, acc2);
        m = Math.min(m, Math.max(acc1, acc2));
        acc2 += a2[i];
    }
    print(m);
}

var T = parseInt(readline());

for (var t = 0; t < T; t++) {
    var m = parseInt(readline());
    var a1 = readline().split(' ').map((x) => parseInt(x));
    var a2 = readline().split(' ').map((x) => parseInt(x));

    var acc1 = 0, acc2 = 0;
    for (var i = 0; i < m; i++) {
        acc1 += a1[i];
    }

    var m = 10000000;
    for (var i = 0; i < m; i++) {
        acc1 -= a1[i];
        m = Math.min(m, Math.max(acc1, acc2));
        acc2 += a2[i];
    }
    print(m);
}

var T = parseInt(readline());

for (var t = 0; t < T; t++) {
    var m = parseInt(readline());
    var a1 = readline().split(' ').map((x) => parseInt(x));
    var a2 = readline().split(' ').map((x) => parseInt(x));

    var acc1 = 0, acc2 = 0;
    for (var i = 0; i < m; i++) {
        acc1 += a1[i];
    }

    var m = 10000000;
    for (var i = 0; i < m; i++) {
        acc1 -= a1[i];
        m = Math.min(m, Math.max(acc1, acc2));
        acc2 += a1[i];
    }
    print(m);
}

var T = parseInt(readline());

for (var t = 0; t < T; t++) {
    var m = parseInt(readline());
    var a1 = readline().split(' ').map((x) => parseInt(x));
    var a2 = readline().split(' ').map((x) => parseInt(x));

    var acc1 = 0, acc2 = 0;
    for (var i = 0; i < m; i++) {
        acc1 += a1[i];
    }

    var m = 10000000;
    for (var i = 0; i < m; i++) {
        acc1 -= a1[i];
        m = Math.min(m, acc1, acc2);
        acc2 += a1[i];
    }
    print(m);
}

var T = parseInt(readline());

for (var t = 0; t < T; t++) {
    var m = parseInt(readline());
    var a1 = readline().split(' ').map((x) => parseInt(x));
    var a2 = readline().split(' ').map((x) => parseInt(x));
    var a = [a1, a2];

    var s1 = find(a, m);

    for (var i = 0; i <= s1[1]; i++)
        a[0][i] = 0;
    for (var i = s1[1]; i < m; i++)
        a[1][i] = 0;

    print(JSON.stringify(a));

    var s2 = find(a, m);
    print(s2[0]);
}

function find(a, m) {
    var acc1 = 0, acc2 = 0;
    for (var i = 0; i < m; i++)
        acc2 += a[1][i];

    var max = 0, maxi = 0;
    for (var i = 0; i < m; i++) {
        acc1 += a[0][i];

        if (acc1 + acc2 > max) {
            max = acc1 + acc2;
            maxi = i;
        }

        acc2 -= a[1][i];
    }

    return [max, maxi];
}

var T = parseInt(readline());

for (var t = 0; t < T; t++) {
    var m = parseInt(readline());
    var a1 = readline().split(' ').map((x) => parseInt(x));
    var a2 = readline().split(' ').map((x) => parseInt(x));
    var a = [a1, a2];

    var s1 = find(a, m);

    for (var i = 0; i <= s1[1]; i++)
        a[0][i] = 0;
    for (var i = s1[1]; i < m; i++)
        a[1][i] = 0;

    var s2 = find(a, m);
    print(s2[0]);
}

function find(a, m) {
    var acc1 = 0, acc2 = 0;
    for (var i = 0; i < m; i++)
        acc2 += a[1][i];

    var max = 0, maxi = 0;
    for (var i = 0; i < m; i++) {
        acc1 += a[0][i];

        if (acc1 + acc2 > max) {
            max = acc1 + acc2;
            maxi = i;
        }

        acc2 -= a[1][i];
    }

    return [max, maxi];
}


You and your friends live in $$$n$$$ houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with integer coordinates), so that the summary distance from all the houses to the exhibition is minimal. The exhibition can be built in the same point as some house. The distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.

First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 1000)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 1000)$$$. Next $$$n$$$ lines describe the positions of the houses $$$(x_i, y_i)$$$ $$$(0 \leq x_i, y_i \leq 10^9)$$$. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$1000$$$.

For each test case output a single integer - the number of different positions for the exhibition. The exhibition can be built in the same point as some house.

NoteHere are the images for the example test cases. Blue dots stand for the houses, green — possible positions for the exhibition.First test case.Second test case. Third test case. Fourth test case. Fifth test case. Sixth test case. Here both houses are located at $$$(0, 0)$$$.

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();

var height = []

function main() {
    var xx = Number(readline())
    Array(Number(xx)).fill(1).map((t, i) => {

        var n = parseInt(readline())
        var y = new Array(n)
        var x = new Array(n)
        var xx, yy
        for (let j = 0; j < n; j++) {
            [xx, yy] = readline().split(' ').map((x, i) => {
                return parseInt(x)
            })
            x[j] = xx;
            y[j] = yy;
        }

        x = x.sort((a, b) => a - b)
        y = y.sort((a, b) => a - b)

        if (n % 2 === 1) return console.log(1)
        var a = x[Math.floor((n) / 2)] - x[Math.floor(n / 2 - 1)] + 1
        var b = y[Math.floor((n) / 2)] - y[Math.floor(n / 2 - 1)] + 1
        a = BigInt(a)
        b = BigInt(b)
        // console.log(x)
        // console.log(y)
        console.log((a*b).toString())
    })
}

let i = ''
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)
    preRun(lines);
});

// preRun([
// 	"1",
// 	"6",
// 	"62190969 830257761",
// 	"133433399 602982864",
// 	"249519268 512360334",
// 	"706277914 269089955",
// 	"763878605 823076990",
// 	"860629446 664543503"
// ]);

function preRun(lines)
{
	let cases = parseInt(lines[0]);
	let p = 1;
	for(let i=0;i<cases;i++)
	{
		let n = parseInt(lines[p]);p++;
		let xs = [];
		let ys = [];
		for(let i=0;i<n;i++)
		{
			let [x,y] = lines[p].split(" ").map((e) => parseInt(e));p++;
			xs.push(x);
			ys.push(y);
		}
		xs.sort((a,b) => a-b);
		ys.sort((a,b) => a-b);
		let rx = BigInt(calcRange(xs));
		let ry = BigInt(calcRange(ys));
		console.log((rx*ry)+"");
	}
}

function calcRange(cs)
{
	if (cs.length%2==1)
	{
		return 1;
	}
	else
	{
		let m = (cs.length/2);
		return (cs[m]-cs[m-1])+1;
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		let n = rn();
		let x = Array(n);
		let y = Array(n);
		for (let i = 0; i < n; i++) {
			[x[i], y[i]] = rna();;
		}

		x.sort((a, b) => a - b);
		y.sort((a, b) => a - b);

		let ans = 1;
		if (n%2 == 0) {
			const k = n/2 - 1;
			ans = BigInt(x[k+1] - x[k] + 1) * BigInt(y[k+1] - y[k] + 1);
		}

		console.log(ans.toString());
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();

var height = []

function main() {
    var xx = Number(readline())
    Array(Number(xx)).fill(1).map((t, i) => {

        var n = parseInt(readline())
        var y = new Array(n)
        var x = new Array(n)
        var xx, yy
        for (let j = 0; j < n; j++) {
            [xx, yy] = readline().split(' ').map((x, i) => {
                return parseInt(x)
            })
            x[j] = xx;
            y[j] = yy;
        }

        x = x.sort((a, b) => a - b)
        y = y.sort((a, b) => a - b)

        if (n%2 === 1) return console.log(1)
        var asnwer = x[Math.floor((n ) / 2)] - x[Math.floor(n/2-1)] + 1
        asnwer *= y[Math.floor((n ) / 2)]- y[Math.floor(n/2-1)] + 1

        // console.log(x)
        // console.log(y)
        console.log(asnwer)
    })
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();

var height = []

function main() {
    var xx = Number(readline())
    Array(Number(xx)).fill(1).map((t, i) => {

        var n = parseInt(readline())
        var y = new Array(n)
        var x = new Array(n)
        var xx, yy
        for (let j = 0; j < n; j++) {
            [xx, yy] = readline().split(' ').map((x, i) => {
                return parseInt(x)
            })
            x[j] = xx;
            y[j] = yy;
        }

        x = x.sort((a, b) => a - b)
        y = y.sort((a, b) => a - b)

        if (n === 1) return console.log(1)
        var asnwer = x[Math.floor((n ) / 2)] - x[Math.floor(n/2-1)] + 1
        asnwer *= y[Math.floor((n ) / 2)]- y[Math.floor(n/2-1)] + 1

        // console.log(x)
        // console.log(y)
        console.log(asnwer)
    })
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();

var height = []

function main() {
    var xx = Number(readline())
    Array(Number(xx)).fill(1).map((t, i) => {

        var n = parseInt(readline())
        var xy = new Array(n)
        var xx, yy
        var sameLineX = true
        var sameLineY = true
        for (let j = 0; j < n; j++) {
            [xx, yy] = readline().split(' ').map((x, i) => {
                return parseInt(x)
            })
            xy[j] = {x: xx, y: yy}
        }

        var sumx = 0
        var sumY = 0
        for (let i = 0; i < n; i++) {
            sumx += xy[i].x
            sumY += xy[i].y
        }
        // console.log(xy)
        // console.log(sumx, sumY, sumx / n, sumY / n)
        sumx = sumx / n
        var sumy = sumY / n
        if (sumx === 0 && sumy === 0) return console.log(1)
        if (n === 2) {
            if (sumx === Math.ceil(sumx) && sumy === Math.ceil(sumy)) {
                // if (sumx === xy[0].x && sumy === xy[0].y) {
                //     return console.log(1)
                // }
                // if (sumx !== xy[0][0] || sumy !== xy[0][1]) {
                return console.log(3)
                // }
                // return console.log(1)
            }
            if (sumx === (Math.ceil(sumx) + Math.floor(sumx)) * 0.5 && sumy === (Math.ceil(sumy) + Math.floor(sumy)) * 0.5) {
                return console.log(4)
            }
            return console.log(2)
        }
        if (n === 3) {
        }

        if (sumx === Math.ceil(sumx) && sumy === Math.ceil(sumy)) {
            return console.log(1)
        }

        // console.log(sumx, sumy)
        // if(sumx === Math.ceil(sumx) || sumy === Math.ceil(sumy) ){
        //     return console.log(2)
        // }
        // console.log(sumx, sumy)
        // console.log(sumx === (Math.ceil(sumx) + Math.floor(sumx)) * 0.5, sumy)

        if (sumx === (Math.ceil(sumx) + Math.floor(sumx)) * 0.5 && sumy === (Math.ceil(sumy) + Math.floor(sumy)) * 0.5) {
            return console.log(4)
        }
        console.log(1)

    })
}

var lower_limit = 0.01;

// Function to return the sum of Euclidean
// Distances
function distSum(p, arr, n) {
    var sum = 0;
    for (var i = 0; i < n; i++) {
        var distx = Math.abs(arr[i].x - p.x);
        var disty = Math.abs(arr[i].y - p.y);
        sum += Math.sqrt((distx * distx) + (disty * disty));
    }

    // Return the sum of Euclidean Distances
    return sum;
}

var test_point = [{x: -1.0, y: 0.0},
    {x: 0.0, y: 1.0},
    {x: 1.0, y: 0.0},
    {x: 0.0, y: -1.0}];
// function geometricMedian(arr, n) {
//
//     // Current x coordinate and y coordinate
//     var current_point = {x: 0, y: 0};
//
//     for (var i = 0; i < n; i++) {
//         current_point.x += arr[i].x;
//         current_point.y += arr[i].y;
//     }
//
//     // Here current_point becomes the
//     // Geographic MidPoint
//     // Or Center of Gravity of equal
//     // discrete mass distributions
//     current_point.x /= n;
//     current_point.y /= n;
//
//     // minimum_distance becomes sum of
//     // all distances from MidPoint to
//     // all given points
//     var minimum_distance = distSum(current_point, arr, n);
//
//     var k = 0;
//     while (k < n) {
//         for (var i = 0; i < n && i !== k; i++) {
//             var newpoint = {};
//             newpoint.x = arr[i].x;
//             newpoint.y = arr[i].y;
//             var newd =
//                 distSum(newpoint, arr, n);
//             console.log(newd)
//             console.log(minimum_distance)
//             if (newd < minimum_distance) {
//                 minimum_distance = newd;
//                 current_point.x = newpoint.x;
//                 current_point.y = newpoint.y;
//             }
//         }
//         k++;
//     }
//
//     // Assume test_distance to be 1000
//     var test_distance = 1000.0;
//     var flag = 0;
//
//     // Test loop for approximation starts here
//     while (test_distance > lower_limit) {
//
//         flag = 0;
//
//         // Loop for iterating over all 4 neighbours
//         for (var i = 0; i < 4; i++) {
//
//             // Finding Neighbours done
//             var newpoint = {}
//             newpoint.x = current_point.x
//                 + test_distance * test_point[i].x;
//             newpoint.y = current_point.y
//                 + test_distance * test_point[i].y;
//
//             // New sum of Euclidean distances
//             // from the neighbor to the given
//             // data points
//             var newd = distSum(newpoint, arr, n);
//
//             if (newd < minimum_distance) {
//
//                 // Approximating and changing
//                 // current_point
//                 minimum_distance = newd;
//                 current_point.x = newpoint.x;
//                 current_point.y = newpoint.y;
//                 flag = 1;
//                 break;
//             }
//         }
//
//         // This means none of the 4 neighbours
//         // has the new minimum distance, hence
//         // we divide by 2 and reiterate while
//         // loop for better approximation
//         if (flag === 0)
//             test_distance /= 2;
//     }
//
//     // cout << "Geometric Median = ("
//     // console.log(current_point)
//     return current_point
//     // current_point.x << ", "
//     // << current_point.y << ")";
//     // cout << " with minimum distance = "
//     // console.log(minimum_distancecurrent_point);
// }

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

// Make a Snippet for the code above this and then write your logic in main();

var height = []

function main() {
    var xx = Number(readline())
    Array(Number(xx)).fill(1).map((t, i) => {

        var n = parseInt(readline())
        var nn = n
        var xy = new Array(n)
        var xx, yy
        var sameLineX = true
        var sameLineY = true
        for (let j = 0; j < n; j++) {
            [xx, yy] = readline().split(' ').map((x, i) => {
                return parseInt(x)
            })
            xy[j] = {x: xx, y: yy}
        }
        if (n === 1) return console.log(1)
        // console.log(xy)
        // console.log(geometricMedian(xy, n))
        var point = geometricMedian(xy, n)
        // console.log(point.x === (Math.ceil(point.x) + Math.floor(point.x))*0.5 )

        var sameX = point.x === (Math.ceil(point.x) + Math.floor(point.x)) * 0.5
        var sameY = point.y === (Math.ceil(point.y) + Math.floor(point.y)) * 0.5

        // console.log(sameX, sameY, point)
        if (Math.ceil(point.y) === point.y && Math.ceil(point.x) === point.x) {
            if(n===2) {
                if(xy[0].x === point.x &&xy[0].y === point.y) return console.log(1)
                return console.log(3)
            }
            return console.log(1)
        }
        if (Math.ceil(point.y) === point.y && sameX) {
            return console.log(2)
        }
        if (Math.ceil(point.x) === point.x && sameY) {
            return console.log(2)
        }

        if (sameX && sameY) {
            return console.log(4)
        }
        console.log(1)
    })

}

var lower_limit = 0.01;

// Function to return the sum of Euclidean
// Distances
function distSum(p, arr, n) {
    var sum = 0;
    for (var i = 0; i < n; i++) {
        var distx = Math.abs(arr[i].x - p.x);
        var disty = Math.abs(arr[i].y - p.y);
        sum += Math.sqrt((distx * distx) + (disty * disty));
    }

    // Return the sum of Euclidean Distances
    return sum;
}

function geometricMedian(arr, n) {

    // Current x coordinate and y coordinate
    var current_point = {x: 0, y: 0};

    for (var i = 0; i < n; i++) {
        current_point.x += arr[i].x;
        current_point.y += arr[i].y;
    }

    // Here current_point becomes the
    // Geographic MidPoint
    // Or Center of Gravity of equal
    // discrete mass distributions
    current_point.x /= n;
    current_point.y /= n;

    // minimum_distance becomes sum of
    // all distances from MidPoint to
    // all given points
    var minimum_distance = distSum(current_point, arr, n);

    var k = 0;
    while (k < n) {
        for (var i = 0; i < n && i !== k; i++) {
            var newpoint = {};
            newpoint.x = arr[i].x;
            newpoint.y = arr[i].y;
            var newd =
                distSum(newpoint, arr, n);
            if (newd < minimum_distance) {
                minimum_distance = newd;
                current_point.x = newpoint.x;
                current_point.y = newpoint.y;
            }
        }
        k++;
    }

    // Assume test_distance to be 1000
    var test_distance = 1000.0;
    var flag = 0;

    // Test loop for approximation starts here
    // while (test_distance > lower_limit) {
    //
    //     flag = 0;
    //
    //     // Loop for iterating over all 4 neighbours
    //     for (var i = 0; i < 4; i++) {
    //
    //         // Finding Neighbours done
    //         var newpoint = {}
    //         newpoint.x = current_point.x
    //             + test_distance * test_point[i].x;
    //         newpoint.y = current_point.y
    //             + test_distance * test_point[i].y;
    //
    //         // New sum of Euclidean distances
    //         // from the neighbor to the given
    //         // data points
    //         var newd = distSum(newpoint, arr, n);
    //
    //         if (newd < minimum_distance) {
    //
    //             // Approximating and changing
    //             // current_point
    //             minimum_distance = newd;
    //             current_point.x = newpoint.x;
    //             current_point.y = newpoint.y;
    //             flag = 1;
    //             break;
    //         }
    //     }
    //
    //     // This means none of the 4 neighbours
    //     // has the new minimum distance, hence
    //     // we divide by 2 and reiterate while
    //     // loop for better approximation
    //     if (flag === 0)
    //         test_distance /= 2;
    // }

    // cout << "Geometric Median = ("
    // console.log(current_point)
    return current_point
    // current_point.x << ", "
    // << current_point.y << ")";
    // cout << " with minimum distance = "
    // console.log(minimum_distancecurrent_point);
}

// let i = ''
// process.stdin.on('data', c => i += c);
// process.stdin.on('end', () => {
//     const {EOL} = require('os')
//     const lines = i.split(EOL)
//     preRun(lines);
// });

preRun([
	"1",
	"6",
	"62190969 830257761",
	"133433399 602982864",
	"249519268 512360334",
	"706277914 269089955",
	"763878605 823076990",
	"860629446 664543503"
]);

function preRun(lines)
{
	let cases = parseInt(lines[0]);
	let p = 1;
	for(let i=0;i<cases;i++)
	{
		let n = parseInt(lines[p]);p++;
		let xs = [];
		let ys = [];
		for(let i=0;i<n;i++)
		{
			let [x,y] = lines[p].split(" ").map((e) => parseInt(e));p++;
			xs.push(x);
			ys.push(y);
		}
		xs.sort((a,b) => a-b);
		ys.sort((a,b) => a-b);
		let rx = BigInt(calcRange(xs));
		let ry = BigInt(calcRange(ys));
		console.log((rx*ry)+"");
	}
}

function calcRange(cs)
{
	if (cs.length%2==1)
	{
		return 1;
	}
	else
	{
		let m = (cs.length/2);
		return (cs[m]-cs[m-1])+1;
	}
}

let i = ''
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)
    preRun(lines);
});

// preRun([
// 	"1",
// 	"6",
// 	"62190969 830257761",
// 	"133433399 602982864",
// 	"249519268 512360334",
// 	"706277914 269089955",
// 	"763878605 823076990",
// 	"860629446 664543503"
// ]);

function preRun(lines)
{
	let cases = parseInt(lines[0]);
	let p = 1;
	for(let i=0;i<cases;i++)
	{
		let n = parseInt(lines[p]);p++;
		let xs = [];
		let ys = [];
		for(let i=0;i<n;i++)
		{
			let [x,y] = lines[p].split(" ").map((e) => parseInt(e));p++;
			xs.push(x);
			ys.push(y);
		}
		xs.sort((a,b) => a-b);
		ys.sort((a,b) => a-b);
		let rx = calcRange(xs);
		let ry = calcRange(ys);
		console.log(rx*ry);
	}
}

function calcRange(cs)
{
	if (cs.length%2==1)
	{
		return 1;
	}
	else
	{
		let m = (cs.length/2);
		return (cs[m]-cs[m-1])+1;
	}
}

let i = ''
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)
    preRun(lines);
});

function preRun(lines)
{
	let cases = parseInt(lines[0]);
	let p = 1;
	for(let i=0;i<cases;i++)
	{
		let n = parseInt(lines[p]);p++;
		let xs = [];
		let ys = [];
		for(let i=0;i<n;i++)
		{
			let [x,y] = lines[p].split(" ").map((e) => parseInt(e));p++;
			xs.push(x);
			ys.push(y);
		}
		xs.sort();
		ys.sort();
		let rx = calcRange(xs);
		let ry = calcRange(ys);
		console.log(rx*ry);
	}
}

function calcRange(cs)
{
	if (cs.length%2==1)
	{
		return 1;
	}
	else
	{
		let m = (cs.length/2);
		return (cs[m]-cs[m-1])+1;
	}
}

let i = ''
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL)
    preRun(lines);
});

// preRun([

// 	"6",
// 	"3",
// 	"0 0",
// 	"2 0",
// 	"1 2",
// 	"4",
// 	"1 0",
// 	"0 2",
// 	"2 3",
// 	"3 1",
// 	"4",
// 	"0 0",
// 	"0 1",
// 	"1 0",
// 	"1 1",
// 	"2",
// 	"0 0",
// 	"1 1",
// 	"2",
// 	"0 0",
// 	"2 0",
// 	"2",
// 	"0 0",
// 	"0 0"
// ]);

function preRun(lines)
{
	let cases = parseInt(lines[0]);
	let p = 1;
	for(let i=0;i<cases;i++)
	{
		let n = parseInt(lines[p]);p++;
		let xs = [];
		let ys = [];
		for(let i=0;i<n;i++)
		{
			let [x,y] = lines[p].split(" ").map((e) => parseInt(e));p++;
			xs.push(x);
			ys.push(y);
		}
		xs.sort();
		ys.sort();
		let rx = calcRange(xs);
		let ry = calcRange(ys);
		console.log(rx*ry);
	}
}

function calcRange(cs)
{
	if (cs.length==1) return 1;

	let t = 0;
	for(let i=0;i<cs.length;i++) t+= cs[i];
	let m = t/cs.length;
	let bef = 0,aft = 0,b = 0, a = -1;
	for(let i=0;i<cs.length;i++)
	{
		if (cs[i]==m) return 1;
		if (cs[i]<m)
		{
			bef++;
			b = cs[i];
		}
		if (cs[i]>m)
		{
			aft++;
			if (a==-1) a = cs[i];
		}
	}
	if (bef==aft)
	{
		return (a-b)+1;
	}
	else
	{
		return 1;
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		let n = rn();
		let x = Array(n);
		let y = Array(n);
		for (let i = 0; i < n; i++) {
			[x[i], y[i]] = rna();;
		}

		x.sort((a, b) => a - b);
		y.sort((a, b) => a - b);

		let ans = 1;
		if (n%2 == 0) {
			const k = n/2 - 1;
			ans = (x[k+1] - x[k] + 1) * (y[k+1] - y[k] + 1);
		}

		console.log(ans);
	}
}


A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute i, he makes a note in his logbook with number ti:   If Petya has visited this room before, he writes down the minute he was in this room last time;  Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute i. Initially, Petya was in one of the rooms at minute 0, he didn't write down number t0.At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya's logbook?

The first line contains a single integer n (1 ≤ n ≤ 2·105) — then number of notes in Petya's logbook. The second line contains n non-negative integers t1, t2, ..., tn (0 ≤ ti < i) — notes in the logbook.

In the only line print a single integer — the minimum possible number of rooms in Paris catacombs.

NoteIn the first sample, sequence of rooms Petya visited could be, for example 1 → 1 → 2, 1 → 2 → 1 or 1 → 2 → 3. The minimum possible number of rooms is 2.In the second sample, the sequence could be 1 → 2 → 3 → 1 → 2 → 1.

var n = Number(readline())
var arr = readline().split(" ");
var arrMarked = [];

var count = 1;

for(var i = n-1; i>=0; i--) {
	var minute = i+1;
	if (arrMarked[minute])
		continue;
	while (minute >= 0 && !arrMarked[minute]) {
		arrMarked[minute] = count;
		minute = arr[minute-1];
	}
	count++;
}

print(count-1);

var cat = [{rep: 0}]
var min = 1

readline() // ignore # of catacombs
// var line = '0 0'
// var line = '0 1 0 1 3'
      //t 0 1 2 3 4 5
var line = readline()
var history = line.split(' ').map(function(x) { return parseInt(x) })

var rep = null
for (var i = 0; i < history.length; i++) {
  rep = cat[history[i]]
  if (rep.rep === history[i]) {
    rep.rep = i+1
    cat.push(rep)
  } else {
    min++
    cat.push({rep: i+1})
  }
  // console.log(i, history[i], cat)
}
// console.log(cat)
// console.log(min)
print(min)


On an $$$8 \times 8$$$ grid, some horizontal rows have been painted red, and some vertical columns have been painted blue, in some order. The stripes are drawn sequentially, one after the other. When the stripe is drawn, it repaints all the cells through which it passes.Determine which color was used last.  The red stripe was painted after the blue one, so the answer is R.

The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 4000$$$) — the number of test cases. The description of test cases follows. There is an empty line before each test case. Each test case consists of $$$8$$$ lines, each containing $$$8$$$ characters. Each of these characters is either 'R', 'B', or '.', denoting a red square, a blue square, and an unpainted square, respectively. It is guaranteed that the given field is obtained from a colorless one by drawing horizontal red rows and vertical blue columns. At least one stripe is painted.

For each test case, output 'R' if a red stripe was painted last, and 'B' if a blue stripe was painted last (without quotes).

NoteThe first test case is pictured in the statement.In the second test case, the first blue column is painted first, then the first and last red rows, and finally the last blue column. Since a blue stripe is painted last, the answer is B.

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");

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

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