var n = Number(readline());
var tab = new Array(n);
for (var i = 0; i < n; ++i) {
    tab[i] = readline();
}

var sum = 0;
for (var i = 0; i < n; ++i) {
    var num = 0;
    for (var j = 0; j < n; ++j) {
        if (tab[i][j] === "C") {
            ++num;
        }
    }
    sum += num * (num - 1) / 2;
}
for (var i = 0; i < n; ++i) {
    var num = 0;
    for (var j = 0; j < n; ++j) {
        if (tab[j][i] === "C") {
            ++num;
        }
    }
    sum += num * (num - 1) / 2;
}

print(sum);

function rda(){ return readline().split(" ").map(Number); };
function rdn(){ return +readline(); };

var cnt = [];
for(var i = 0, s = 0; i <= 100; i++){
    s += i;
    cnt[i] = s;
}

var n = rdn();

var ans = 0;
var cake = [];
for(var i = 0; i < n; i++){
    var line = readline();
    cake.push(line);
    var c = 0;
    for(var j = 0; j < n; j++){
        if(line[j] == "C") c++;
    }

    ans += (cnt[c-1] == undefined) ? 0 : cnt[c-1];
}

for(var j = 0; j < n; j++){
    var c = 0;
    for(var i = 0; i < n; i++){
        if(cake[i][j] == "C") c++;
    }

    ans += (cnt[c-1] == undefined) ? 0 : cnt[c-1];
}

write(ans);

var n = +readline();
var arr = [];
for(var i=0;i<n;i++)
arr.push(readline());
print(main(n, arr));
function main(n, arr) {
	var x = [], y = [];
	arr.forEach(function(row, i){
		row.split('').forEach(function(cell, j){
			x[i] = (x[i]|0)+(cell=='C');
			x[n+j] = (x[n+j]|0)+(cell=='C');
		});
	});
	var ans = 0;
	x.forEach(function(h){ans += (h*(h-1))/2});
	return ans;
}

var n = Number(readline());

var row_count = {};
var col_count = {};

var cake_row = [];

for (var i = 0; i < n; i++) {
	cake_row = readline().split('').map(String);
	for (var j = 0; j < n; j++) {
		if (cake_row[j] == 'C') {
			if (j in col_count) {
				col_count[j] += 1;
			} else {
				col_count[j] = 1;
			}
			if (i in row_count) {
				row_count[i] += 1;
			} else {
				row_count[i] = 1;
			}
		}
	}
}

var C_choose_2 = function(C) {
	return C * (C - 1) / 2;
};

var sum = 0;

for (var key in row_count) {
	sum += C_choose_2(row_count[key]);
}

for (var key in col_count) {
	sum += C_choose_2(col_count[key]);
}

print(sum);

/* TEST CASE
input
3
.CC
C..
C.C
output
4
input
4
CC..
C..C
.CC.
.CC.
output
9
 */
function main() {
	var n = parseInt(readline());
	var answer = 0;
	var cakesInRow = new Array(n);
	var cakesInCol = new Array(n);
	var i, j;
	for (i = 0; i < n; i++) {
		cakesInRow[i] = 0;
		cakesInCol[i] = 0;
	}

	for (i = 0; i < n; i++) {
		var s = readline();
		for (j = 0; j < n; j++) {
			if (s.charAt(j) == 'C') {
				cakesInRow[i]++;
				cakesInCol[j]++;
			}
		}
	}

	for (i = 0; i < n; i++) {
		var nCakes = cakesInRow[i];
		if (nCakes > 1) {
			answer += nCakes * (nCakes - 1) / 2;
		}

		nCakes = cakesInCol[i];
		if (nCakes > 1) {
			answer += nCakes * (nCakes - 1) / 2;
		}
	}
	print(answer);
}

main();

/* TEST CASE
input
3
.CC
C..
C.C
output
4
input
4
CC..
C..C
.CC.
.CC.
output
9
 */
function main() {
	var n = parseInt(readline());
	var answer = 0;
	var cakesInRow = []
	var cakesInCol = []
	var i, j;
	for (i = n; i >= 0; i--) {
		cakesInRow[i] = 0;
		cakesInCol[i] = 0;
	}

	for (i = 0; i < n; i++) {
		var s = readline();
		for (j = 0; j < n; j++) {
			if (s.charAt(j) == 'C') {
				cakesInRow[i]++;
				cakesInCol[j]++;
			}
		}
	}

	for (i = 0; i < n; i++) {
		var nCakes = cakesInRow[i];
		if (nCakes > 1) {
			answer += nCakes * (nCakes - 1) / 2;
		}

		nCakes = cakesInCol[i];
		if (nCakes > 1) {
			answer += nCakes * (nCakes - 1) / 2;
		}
	}
	print(answer);
}

main();

'use strict';

const n = Number(readline());
let cake = [];
let count = 0;

for (let i = 0; i < n; i++) {
  let line = readline().split('');
  count += calc(line.filter((c) => c === 'C').length);
  cake.push(line);
}

for (let i = 0; i < n; i++) {
  let _line = [];
  for (let j = 0; j < n; j++) {
    _line.push(cake[j][i])
  }
  count += calc(_line.filter((c) => c === 'C').length);
}

print(count)

function calc(n) {
  return n * (n - 1) / 2;
}

var readInt = () => parseInt(readline())
var readIntArray = () => readline().split(' ').forEach(item => parseInt(item))
var fact = n => n > 0 ? n*fact(n-1) : 1;

var N = readInt()
var cake = []
for (var i = 0; i < N; i++) {
    cake.push(readline())
}

var ans = 0
cake.forEach(function(s,i) {
    var n = Array.prototype.filter.call(s, c => c === 'C').length
    if (n > 1)
        ans+=fact(n)/(2*fact(n-2))

    n = cake.map(s => s[i]).filter(c => c ==='C').length
    if (n > 1)
        ans+=fact(n)/(2*fact(n-2))
})
print(ans)

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    const n = +d;
    for (let i = 3; i <= n; i++) {
      t[i] = t[i - 1] + i - 1;
    }
    return;
  }

  matrix.push([...d]);

  c++;
});

rl.on('close', () => {
  let ans = 0;

  for (let i = 0; i < matrix.length; i++) {
    let countX = 0;
    let countY = 0;

    for (let j = 0; j < matrix[i].length; j++) {
      if (matrix[i][j] === 'C') {
        countX++;
      }

      if (matrix[j][i] === 'C') {
        countY++;
      }
    }

    ans += t[countX];
    ans += t[countY];
  }

  console.log(ans);
});

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    const n = +d;
    for (let i = 3; i <= n; i++) {
      t[i] = t[i - 1] + i - 1;
    }
    return;
  }

  matrix.push([...d]);

  c++;
});

rl.on('close', () => {
  let ans = 0;

  for (let i = 0; i < matrix.length; i++) {
    let countX = 0;
    let countY = 0;

    for (let j = 0; j < matrix[i].length; j++) {
      if (matrix[i][j] === 'C') {
        countX++;
      }

      if (matrix[j][i] === 'C') {
        countY++;
      }
    }

    ans += t[countX];
    ans += t[countY];
  }

  console.log(ans);
});

function rda(){ return readline().split(" ").map(Number); };
function rdn(){ return +readline(); };

var cnt = [];
for(var i = 0, s = 0; i <= 100; i++){
    s += i;
    cnt[i] = s;
}

var n = rdn();

var ans = 0;
var cake = [];
for(var i = 0; i < n; i++){
    var line = readline();
    cake.push(line);
    var c = 0;
    for(var j = 0; j < n; j++){
        if(line[j] == "C") c++;
    }

    ans += cnt[c-1];
}

for(var j = 0; j < n; j++){
    var c = 0;
    for(var i = 0; i < n; i++){
        if(cake[i][j] == "C") c++;
    }

    ans += (cnt[c-1] == undefined) ? 0 : cnt[c-1];
}

write(ans);

function rda(){ return readline().split(" ").map(Number); };
function rdn(){ return +readline(); };

var cnt = [];
for(var i = 0, s = 0; i <= 100; i++){
    s += i;
    cnt[i] = s;
}

var n = rdn();

var ans = 0;
var cake = [];
for(var i = 0; i < n; i++){
    var line = readline();
    cake.push(line);
    var c = 0;
    for(var j = 0; j < n; j++){
        if(line[j] == "C") c++;
    }

    ans += cnt[c-1];
}

for(var j = 0; j < n; j++){
    var c = 0;
    for(var i = 0; i < n; i++){
        if(cake[i][j] == "C") c++;
    }

    ans += cnt[c-1];
}

write(ans);


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

function query(arr){
    let set = new Set(arr);
    if (set.size==1)
        return print('NO');
    print('YES');
    let left = [], last;
    for (let i=1; i<arr.length; i++)
    {
        if (arr[0]==arr[i])
            left.push(i);
        else
        {
            print('1 '+(i+1));
            last = i;
        }
    }
    for (let i=0; i<left.length; i++)
        print((last+1)+' '+(left[i]+1));

}

function main() {
    var q = +readline();
    while (q--)
    {
        var n = +readline();
        let arr = readline().split(' ').map(a=>+a);
        query(arr);
    }
}

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

let lineNum = 0;
let countOfData = null;
let data = [];
readline.on('line', line => {
  lineNum++;
  if(lineNum === 1) {
    countOfData = +line * 2;
    return;
  }

  data.push(line);

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

});

function goToSolution(data) {
  data.forEach((districts, i) => {
    if(i % 2 !== 0) {

      districts = districts.split(' ');
      const map = districts.reduce((acc, band, i) => {
        (band in acc) ?
          acc[band].push(i + 1) :
          acc[band] = [i + 1];
        return acc;
      }, {});

      const bands = Object.keys(map);
      if(bands.length > 1) {
        console.log('YES');
        for(let i = 0; i < bands.length; i++) {
          if(bands.length - 1 !== i) console.log(`${map[bands[i]][0]} ${map[bands[i + 1]][0]}`);

          if(i > 0) {
            for(let j = 1; j < map[bands[i - 1]].length; j++) {
              console.log(`${map[bands[i]][0]} ${map[bands[i - 1]][j]}`)
            }
          }

          if(bands.length - 1 === i) {
            for(let j = 1; j < map[bands[i]].length; j++) {
              console.log(`${map[bands[i - 1]][map[bands[i - 1]].length - 1]} ${map[bands[i]][j]}`)
            }
          }

        }
      } else {
        console.log('NO');
      }
    }
  })
}

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

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

function main() {
  let t = +readLine();
  while (t--) {
    const len = +readLine();
    const arr = readLine().split(" ").map(Number);
    const map = new Map();

    for (let i = 0; i < len; i++) {
      const num = arr[i];
      if (map.has(num)) {
        map.set(num, [...map.get(num), i + 1]);
      } else {
        map.set(num, [i + 1]);
      }
    }

    if (map.size === 1) console.log("NO");
    else {
      console.log("YES");
      const values = [...map.values()];
      const [firstRow, secondRow] = [values[0], values[1]];
      for (let row = 1; row < values.length; row++) {
        for (let col = 0; col < values[row].length; col++) {
          console.log(`${firstRow[0]} ${values[row][col]}`);
        }
      }
      for (let col = 1; col < firstRow.length; col++) {
        console.log(`${secondRow[0]} ${firstRow[col]}`);
      }
    }
  }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = [];
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var tmp = nextIntArray();
		var isOK = false;
		var list = new Array(N);
		var uf = unionFind(N);
		for(var j = 0; j < N; j++){
			list[j] = {
				no : j,
				G : tmp[j],
				child : new Set()
			}
		}
		var connect = new Set();
		for(var j = 0; j < N - 1; j++){
			for(var k = j + 1; k < N; k++){
				if(list[j].child.has(list[k].no) || list[k].child.has(list[j].no)){
					continue;
				}
				if(list[j].G != list[k].G && !uf.isSame(j, k)){
					isOK = true;
					list[j].child.add(list[k].no);
					list[k].child.add(list[j].no);
					connect.add((j + 1) + ":" + (k + 1));
					uf.doUnion(j, k);
				}
			}
		}
		if(isOK){
			output.push("YES");
			var keys = Array.from(connect);
			for(var j = 0; j < keys.length; j++){
				output.push(keys[j].split(":").join(" "));
			}
		}else{
			output.push("NO");
		}
	}
	myout(myconv(output, 9));
}
function unionFind(n){
  var uf = {
    //全てのインデックスは「-X(親、絶対値はグループの大きさ)」「自分が属する親(≒根)」のいずれかを持つ。
    //最初はみんなグループの大きさ1の親
    "list" : new Array(n).fill(-1),

    //同じ親を持つか
    "isSame" : function(mae, ato){
      return this.getRootIndex(mae) == this.getRootIndex(ato);
    },
    //自身の親インデックスをたどって根っこに着く
    //親にたどり終えたら子に帰っていくついでに、子たちに「共通の親を持っている」ことを知らせる
    "getRootIndex" : function(index){
      if(this.list[index] < 0){
        return index;
      }else{
        this.list[index] = this.getRootIndex(this.list[index]);
        return this.list[index];
      }
    },
    //異なる親同士のまとまりを一つにする（同じ親ならスルー）
    //小さいグループの親が大きいグループの親の直下に着く
    //グループの大きさも更新する
    "doUnion" : function(mae, ato){
      var maeRoot = this.getRootIndex(mae);
      var atoRoot = this.getRootIndex(ato);
      if(!this.isSame(maeRoot, atoRoot)){
        if(maeRoot >= atoRoot){
          this.list[maeRoot] += this.list[atoRoot];
          this.list[atoRoot] = maeRoot;
        }else{
          this.list[atoRoot] += this.list[maeRoot];
          this.list[maeRoot] = atoRoot;
        }
      }
    },
    //「-X(親、絶対値はグループの大きさ)」
    //なので、インデックスを指定→親を知る→親の持つグループの大きさがわかる。
    //ただしマイナス値なので、掛け算して返す。
    "getSize" : function(index){
      return -this.list[this.getRootIndex(index)];
    }
  }
  return uf;
}

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

let stdinInput = '';

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

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

function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 2;
    let i = 1;
    while (i <= testCases) {
      // let a = data[i].trim();
      // const n = data[i] * 1;
      // const k = a[1];
      const s = data[i + 1].trim().split(' ').map(Number);
      // s.sort((a, b) => b - a);
      let idx = 0;
      let max = 0;
      let obj = {};

      for (let j = 0; j < s.length; j += 1) {
        if (obj[s[j]]) obj[s[j]].push(j);
        else obj[s[j]] = [j];
        // if (s[j] > max) {
        //   max = s[j];
        //   idx = j;
        // }
      }

      let arr = Object.values(obj);
      // console.log(arr);

      if (arr.length < 2) console.log('NO');
      else {
        console.log('YES');
        for (let j = 1; j < arr.length; j += 1) {
          for (let k = 0; k < arr[j].length; k += 1) {
            console.log(arr[0][0] + 1 + ' ' + (arr[j][k] + 1));
          }
        }
        for (let j = 1; j < arr[0].length; j += 1) {
          console.log(arr[1][0] + 1 + ' ' + (arr[0][j] + 1));
        }
      }

      i += 2;
    }
}

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

    districtConnections();
});

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

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

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

    return a;
}

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

        let count = 0;
        let map = new Array(1000000005);
        let x = [];
        for(let i = 0; i < n; i++){
            if(map[a[i]] === undefined){
                count++;
                map[a[i]] = i+1;
                x.push(a[i]);
            }

            if(count >= 2)
                break;
        }

        if(count < 2){
            console.log('NO');
            continue;
        }

        console.log('YES');
        let visited = new Array(n+1);

        for(let i = 1; i <= n; i++){
            if(a[i-1] !== x[0]){
                if(!(visited[i] && visited[map[x[0]]])){
                    console.log(i, map[x[0]]);
                    visited[i] = true;
                    visited[map[x[0]]] = true;
                }
            }else{
                if(!(visited[i] && visited[map[x[1]]])){
                    console.log(i, map[x[1]]);
                    visited[i] = true;
                    visited[map[x[1]]] = true;
                }
            }
        }
    }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = [];
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var tmp = nextIntArray();
		var isOK = false;
		var list = new Array(N);
		for(var j = 0; j < N; j++){
			list[j] = {
				no : j,
				G : tmp[j],
				child : new Set()
			}
		}
		var connect = 0;
		for(var j = 0; j < N - 1; j++){
			if(connect == N - 1){
				break;
			}
			for(var k = j + 1; k < N; k++){
				if(list[j].child.has(list[k].no) || list[k].child.has(list[j].no)){
					continue;
				}
				if(list[j].G != list[k].G){
					isOK = true;
					list[j].child.add(list[k].no);
					connect++;
					if(connect == N - 1){
						break;
					}
					//list[k].child.add(list[j].no);
				}
			}
		}
		if(isOK){
			output.push("YES");
			for(var j = 0; j < N; j++){
				var keys = Array.from(list[j].child);
				for(var k = 0; k < keys.length; k++){
					output.push((j + 1) + " " + (keys[k] + 1));
				}
			}
		}else{
			output.push("NO");
		}
	}
	myout(myconv(output, 9));
}

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

let inputString = '';
let currentLine = 0;

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

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

    districtConnections();
});

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

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

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

    return a;
}

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

        let count = 0;
        let map = new Array(1000000005);
        let x = [];
        for(let i = 0; i < n; i++){
            if(map[a[i]] === undefined){
                count++;
                map[a[i]] = i+1;
                x.push(a[i]);
            }

            if(count >= 2)
                break;
        }

        if(count < 2){
            console.log('NO');
            continue;
        }

        console.log('YES');
        for(let i = 1; i < n; i++){
            if(a[i-1] !== x[0]){
                console.log(i, map[x[0]]);
            }else{
                console.log(i, map[x[1]]);
            }
        }
    }
}


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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var K = nextInt();
		var list = nextIntArray(N);
		if(list.indexOf(1) == -1){
			myout("NO");
		}else{
			myout("YES");
		}
	}
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    for(i = 1; i <= t * 2; i++){
        var a = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            n = a[0];
        }else{
            var ans = 0;
            var flag = false;
            for(j = 0; j < n; j++){
                if(a[j] == 1){
                    flag = true;
                    break;
                }
            }
            console.log(flag ? 'YES' : 'NO');
        }
    }
});

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 _=1;_<=t;_++)
    {
        let [n,k]=line[2*_-1].split(' ').map(x=>{return parseInt(x)});
        let a=line[2*_].split(' ').map(x=>{return parseInt(x)});
        flag=false;
        for(let i=0;i<n;i++) {
            if(a[i]) {
                flag=true;
            }
        }
        if(flag) console.log("YES");
        else console.log("NO");
    }
})

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  rns();
  const a = rns();
  if (a.includes(1)) return 'YES';
  return 'NO';
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

"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, k] = iInpArr();
    let arr = iInpArr();
    let ans = "NO";
    for (let i = 0; i < n; i++) {
      if (arr[i] === 1) {
        ans = "YES";
        break;
      }
    }
    console.log(ans);
  }
};
solve();

function solve() {
    read();
    write(~(read().indexOf('1')) ? 'YES' : 'NO');
}

function start() {
    var T = 1;
    T = Number(read());
    for (var t = 0; t < T; t++) {
        solve();
    }
    writeAns();
}

var MEMORY;
var MEMORY_INDEX = 0;
var ANS = '';

try {
    initInput(start);
} catch (e) {
    console.log(e);
}
function readArray(f) {
    return read().split(' ').map(f);
}

function sortNumbers(a, b) {
    return a - b;
}
function sortNumbersDec(a, b) {
    return b - a;
}
var ANS;
// вывод через ANS быстрее, но ест кучу памяти.
// К тому же, максимальная длина строки - 2097151.
function write(value) {
    // console.log(value);
    ANS += value + '\n';
}
function writeAns() {
    if (ANS) {
        console.log(ANS);
    }
}
function read() {
    return MEMORY[MEMORY_INDEX++];
}
function initInput(callback) {
    var fs = require('fs');
    var isLocalStart = process.argv[2] === 'lorelvate';
    if (!isLocalStart) {
        MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
        callback();
        return;
    }
    var path = require('path');
    fs.readFile(path.join(__dirname, 'input.txt'), 'utf8', (err, data) => {
        if (err) {
            write(err);
            return;
        }
        MEMORY = data.split('\r\n');
        callback();
    });
}

var test_number = readline();
var n = 0,
  k = 0;
var temp_line = "",
  array_number;
while (test_number--) {
  temp_line = readline();
  array_number = readline();
  if (array_number.includes("1")) print("YES");
  else print("NO");
}

var n = parseInt(readline());

for (var i = 0; i < n; i++){
    var num = readline();
    var arr = readline().split(" ");
    var counter = false;

    for(var k = 0; k < arr.length; k++){
        if(arr[k] == 1){
            counter = true;
            break;
        }
    }
    if(counter === true) {
        print("YES");
    }else{
    print("NO");
    }
}

var t = readline();
    for(var i = 0 ; i < t ; ++i){
        var inputs = readline().split(' '), n = inputs[0] , k = inputs[1];
        var a = readline().split(' ');
        a.indexOf('1') == -1 ? print("NO") : print("YES");
    }

const cntLines = readline();

for (var i=0; i<cntLines; i++) {
    readline();
    var arr =  readline().split(" ");
    arr.find(item => item == 1) ? print('YES') : print('NO');
}

var test_number = readline();
var n = 0;


function getInput() {
    var line = readline();
    var lines = [line];
    while (line = readline()) {
        lines.push(line);
    }
    return lines;
}

function main() {
    var items = getInput().pop().split(' ').map(i => Number(i));
    var max = 0;
    items.forEach(item => {
        if (max < item) {
            max = item;
        }
    });

    print(max - (items.reduce((res, cur) => res + cur, 0) - max) + 1);
}

main();

var n = parseInt(readline());
var input = readline().split(' ').map(function (item) {
    return parseInt(item);
});
var max = 0;
var sum = input.reduce(function(acc, curr){
    if(curr > max){
        max = curr;
    }
    return acc+curr;
}, 0)
print(2*max-sum+1);


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 str = lines[l++]
        console.log(solve(str));
    }
});

function solve(str) {
    let sum = 0
    let expect = '?'
    let prev = 0
    for (let i = 0; i < str.length; i++) {
        const ch = str[i]
        if (isMatch(expect, ch)) {
            prev++

            if (expect === '?') {
                if (ch !== '?') expect = getOther(ch)
            } else {
                expect = getOther(expect)
            }
        } else {
            let j = i
            while (j >= 0) {
                const change = (i - j) & 1
                const other = getOther(str[j])
                if (str[j] !== '?'
                    && !isMatch(ch, change ? other : str[j])) {
                    j++
                    break
                }
                j--
            }
            prev = i - j + 1
            expect = getOther(ch)
        }

// console.log(prev)
        sum += prev
    }
// console.log('----')
    return sum
}

function isMatch(expect, actual) {
    if (expect === '?' || actual === '?') return true
    return expect === actual
}
function getOther(ch) {
    return ch === '0' ? '1' : '0'
}

///////////////////////////////// pre-define ////////////////////////////////////////////////////////////////////////////////
const pr = console.log;
const mi = Math.min;
const mx = Math.max;
const mxll = (...args) => args.reduce((m, e) => e > m ? e : m);
const mill = (...args) => args.reduce((m, e) => e < m ? e : m);
const sqll = (v) => { if (v < 0n) throw 'negative input'; if (v < 2n) return v; const dfs = (n, x0) => { let x1 = ((n / x0) + x0) >> 1n; if (x0 === x1 || x0 === (x1 - 1n)) return x0; return dfs(n, x1); }; return dfs(v, 1n); }; // has >> 0
const abs = Math.abs;
const fl = Math.floor;
const ce = Math.ceil;
const sq = Math.sqrt;
const lge = Math.log;
const lg10 = Math.log10;
const ll = BigInt;
const combination = (m, n) => { return factorial(m, n) / factorial(n, n); };
const factorial = (m, n) => { let num = 1n; let cnt = 0; for (let i = ll(m); i > 0; i--) { if (cnt == n) break; num *= i; cnt++; } return num; };
const gcd = (a, b) => b == 0 ? a : gcd(b, a % b);
const lcm = (a, b) => (a / gcd(a, b)) * b;
const bitCount = (n) => { n = n - ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; };
const powmod = (a, b, mod) => { let r = 1n; while (b > 0n) { if (b % 2n == 1) r = r * a % mod; b >>= 1n; a = a * a % mod; } return r; };
const amax = (a) => mx.apply(Math, a);
const amin = (a) => mi.apply(Math, a);
const sm = (a) => a.reduce(((x, y) => x + y), 0);
const aeq = (a, b) => JSON.stringify(a) == JSON.stringify(b);
const swap = (a, i, j) => [a[i], a[j]] = [a[j], a[i]];
const stin = (a) => a.sort((x, y) => x - y);
const stde = (a) => a.sort((x, y) => y - x);
const sortPart = (a, k) => { let l = a.slice(0, k); l.sort((x, y) => x - y); let r = a.slice(k); return l.concat(r); }; // sort first kth
const initialize2DArrayNew = (m, n) => { let data = []; for (let i = 0; i < m; i++) { let tmp = Array(n).fill(0); data.push(tmp); } return data; };
const stmkey_in = (m) => new Map([...m].sort((x, y) => x[0] - y[0]));
const stmkey_de = (m) => new Map([...m].sort((x, y) => y[0] - x[0]));
const stmvalue_in = (m) => new Map([...m].sort((x, y) => x[1] - y[1]));
const stmvalue_de = (m) => new Map([...m].sort((x, y) => y[1] - x[1]));
const counter = (a_or_s) => { let map = new Map(); for (const i of a_or_s) map.set(i, map.get(i) + 1 || 1); return map; };
const counter_value_in_indexA_in = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).push(i); } return m; };
const counter_value_in_indexA_de = (a_or_s) => { let m = new Map(); let n = a_or_s.length; for (let i = 0; i < n; i++) { if (!m.has(a_or_s[i])) m.set(a_or_s[i], []); m.get(a_or_s[i]).unshift(i); } return m; };
const reverse2 = (s) => { let res = ""; for (let i = s.length - 1; i >= 0; i--) { res += s[i]; } return res; };
const isPalindrome = (s) => { let n = s.length; let i = 0; let j = n - 1; while (i < j) { if (s[i++] != s[j--]) return false; } return true; };
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
 * 06/04/21 morning
 * https://codeforces.com/contest/1535/problem/C
 */

const solve = (s) => {
    let n = s.length;
    let pos = Array(n).fill(-1);
    for (let i = 0; i < n; i++) {
        if (s[i] != '?') pos[i] = s[i] ^ (i % 2);
    }
    let zero = one = res = 0;
    // pr(pos);
    let j = -1; // right
    for (let i = 0; i < n; i++) {
        while (j < n && (zero == 0 || one == 0)) {
            j++;
            if (pos[j] == 0) {
                zero++;
            } else if (pos[j] == 1) {
                one++;
            }
        }
        res += j - i;
        if (pos[i] == 0) {
            zero--;
        } else if (pos[i] == 1) {
            one--;
        }
    }
    pr(res);
};

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

main()

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--) {
		const s = rl().split('');
		const n = s.length;

		const px = Array(n).fill(0); px[-1] = 0;
		for (let i = 0; i < n; i++) if (s[i] == '?') px[i] = px[i-1] + 1;

		let ans = 0;
		for (let i = 0, cnt = 0; i < n; i++) {

			if (s[i] == '?') s[i] = 1 ^ s[i-1];

			if (s[i] == s[i-1]) cnt = 1 + px[i-1];
			else cnt++;

			ans += cnt;
		}

		console.log(ans);
	}
}

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--) {
		const S = rl().split('');
		const n = S.length;

		for (let i = 0; i < n; i++) if (S[i] != '?') S[i] = S[i] - 0;
		const px = Array(n).fill(0); px[-1] = 0;
		for (let i = 0; i < n; i++) if (S[i] == '?') px[i] = px[i-1] + 1;

		s = S.slice();
		if (s[0] == '?') s[0] = 0;

		let ans = 0;

		let res = 1, cnt = 1;
		for (let j = 1; j < n; j++) {
			if (s[j] == '?') s[j] = 1 ^ s[j-1];
			if (s[j] == s[j-1]) {
				cnt = 1 + px[j-1];
			} else {
				cnt++;
			}
			res += cnt;
		}
		ans = Math.max(ans, res);

		console.log(ans);
	}
}

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--) {
		const S = rl().split('');
		const n = S.length;

		for (let i = 0; i < n; i++) if (S[i] != '?') S[i] = S[i] - 0;

		let ans = 0;
		for (let i = 0; i < 2; i++) {
			s = S.slice();
			if (s[0] == '?') s[0] = i;

			let res = 1, cnt = 1;
			for (let j = 1; j < n; j++) {
				if (s[j] == '?') s[j] = 1 ^ s[j-1];
				if (s[j] == s[j-1]) {
					cnt = 1;
					k = j-1;
					while (k >= 0 && S[k] == '?') { cnt++; k--;}
				} else {
					cnt++;
				}
				res += cnt;
			}

			ans = Math.max(ans, res);
		}

		console.log(ans);
	}
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function solve() {
   var str = read();
   var mark = [];
   var n = str.length;
   var curStreak = -1;
   var lastIndex = -1n;
   var lastDigitIndex = -1n;
   var questionStreak = 0n;
   var ans = 0n;
   for (var i = 0; i < n; i++) {
      var char = str[i];
      if (char === '?') {
         questionStreak += 1n;
         continue;
      }
      var x = (char === '1') ? !(i & 1) : !!(i & 1);
      if (curStreak === -1) {
         curStreak = x;
      }
      var bigi = BigInt(i);
      if (curStreak === x) {
         lastDigitIndex = bigi;
         questionStreak = 0n;
         continue;
      }
      curStreak = x;
      var len = bigi - 1n - lastIndex;
      ans = ans + (len * (len + 1n) / 2n) - (questionStreak * (questionStreak + 1n) / 2n);
      lastIndex = lastDigitIndex;
      lastDigitIndex = bigi;
      questionStreak = 0n;
   }
   var len = BigInt(n - 1) - lastIndex;
   ans = ans + (len * (len + 1n) / 2n);
   write(ans);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

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--) {
		const S = rl().split('');
		const n = S.length;

		for (let i = 0; i < n; i++) if (S[i] != '?') S[i] = S[i] - 0;
		const px = Array(n).fill(0); px[-1] = 0;
		for (let i = 0; i < n; i++) if (S[i] == '?') px[i] = px[i-1] + 1;

		s = S.slice();
		if (s[0] == '?') s[0] = 0;

		let ans = 0;

		let res = 1, cnt = 1;
		for (let j = 1; j < n; j++) {
			if (s[j] == '?') s[j] = 1 ^ s[j-1];
			if (s[j] == s[j-1]) {
				cnt = 1 + px[j-1];
			} else {
				cnt++;
			}
			res += cnt;

			ans = Math.max(ans, res);
		}

		console.log(ans);
	}
}

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--) {
		const S = rl().split('');
		const n = S.length;

		for (let i = 0; i < n; i++) if (S[i] != '?') S[i] = S[i] - 0;

		let ans = 0;
		for (let i = 0; i < 2; i++) {
			s = S.slice();
			if (s[0] == '?') s[0] = i;
			//else s[0] = s[0]-0;

			let res = 1, cnt = 1;
			for (let j = 1; j < n; j++) {
				if (s[j] == '?') s[j] = 1 ^ s[j-1];
				if (s[j] == s[j-1]) {
					cnt = 1;
					k = j-1;
					while (k >= 0 && S[k] == '?') { cnt++; k++;}
				} else {
					cnt++;
				}
				res += cnt;
			}

			ans = Math.max(ans, res);
		}

		console.log(ans);
	}
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function solve() {
   var str = read();
   var mark = [];
   var n = str.length;
   var curStreak = -1;
   var lastIndex = -1n;
   var lastDigitIndex = -1n;
   var questionStreak = 0n;
   var ans = 0n;
   for (var i = 0; i < n; i++) {
      var char = str[i];
      if (char === '?') {
         questionStreak += 1n;
         continue;
      }
      var x = (char === '1') ? !(i & 1) : !!(i & 1);
      if (curStreak === -1) {
         curStreak = x;
      }
      var bigi = BigInt(i);
      if (curStreak === x) {
         lastDigitIndex = bigi;
         questionStreak = 0n;
         continue;
      }
      curStreak = x;
      var len = bigi - 1n - lastIndex;
      ans = ans + (len * (len + 1n) / 2n) - (questionStreak * (questionStreak + 1n) / 2n);
      lastIndex = lastDigitIndex;
   }
   var len = BigInt(n - 1) - lastIndex;
   ans = ans + (len * (len + 1n) / 2n);
   write(ans);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function solve() {
   var str = read();
   var mark = [];
   var n = str.length;
   var curStreak = -1;
   var lastIndex = -1n;
   var lastDigitIndex = -1n;
   var ans = BigInt(n);
   for (var i = 0; i < n; i++) {
      var char = str[i];
      if (char === '?') {
         continue;
      }
      var x = (char === '1') ? !(i & 1) : !!(i & 1);
      if (curStreak === -1) {
         curStreak = x;
      }
      var bigi = BigInt(i);
      if (curStreak === x) {
         lastDigitIndex = bigi;
         continue;
      }
      curStreak = x;
      var len = bigi - 1n - lastIndex;
      ans = ans + (len * (len - 1n) / 2n);
      lastIndex = lastDigitIndex;
      lastDigitIndex = bigi;
   }
   var len = BigInt(n - 1) - lastIndex;
   ans = ans + (len * (len - 1n) / 2n);
   write(ans);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function gcd(x, y) {
   if (y === 0) {
      return x;
   }
   return gcd(y, x % y);
}

function solve() {
   var str = read();
   var mark = [];
   var n = str.length;
   var curStreak = -1;
   var lastIndex = -1n;
   var lastDigitIndex = -1n;
   var ans = BigInt(n);
   for (var i = 0; i < n; i++) {
      var char = str[i];
      if (char === '?') {
         continue;
      }
      var x = (char === '1') ? !(i & 1) : !!(i & 1);
      if (curStreak === -1) {
         curStreak = x;
      }
      var bigi = BigInt(i);
      if (curStreak === x) {
         lastDigitIndex = bigi;
         continue;
      }
      curStreak = x;
      var len = bigi - 1n - lastIndex;
      ans = ans + (len * (len - 1n) / 2n);
      lastIndex = lastDigitIndex;
   }
   var len = BigInt(n - 1) - lastIndex;
   ans = ans + (len * (len - 1n) / 2n);
   write(ans);
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}


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]);
	};
	return tokens;
}

function main() {
	var vertexNum = parseInt(readline());

	var edges = {
		augment: function(u, v) {
			if (edges[u] === undefined) {
				edges[u] = [v];
			}
			else {
				edges[u].push(v);
			}
		}
	};

	for (var i = 1; i < vertexNum; ++i) {
		var pair = tokenizeIntegers(readline());
		edges.augment(pair[0], pair[1]);
		edges.augment(pair[1], pair[0]);
	}

	var nodes = {};
	var root = 1;

	function descend(path) {
		var current = path[path.length-1];
		nodes[current] = {
				children: [],
				leadsToLeaf: {},
				parent: path[path.length-2], visitCount: 0
		};

		var neighbors = edges[current];
		if (neighbors.length == 1 && current != root) {  // it's a leaf
			for (var i = path.length-1; i >= 0; --i) {
				var node = nodes[path[i]];
				node.leadsToLeaf[current] = true;
			}
			return;
		}

		for (var i = 0; i < neighbors.length; ++i) {
			var child = neighbors[i];
			if (path.length > 1 && path[path.length-2] == child) {
				continue;  // don't descend to the parent
			}

			nodes[current].children.push(child);

			path.push(child);
			descend(path);
			path.pop();
		}
	}

	descend([root]);

	var order = tokenizeIntegers(readline());

	var seek = root,
		route = [root],
		node = nodes[root];
	node.visitCount = 1;

	for (var i = 0; i < order.length; ++i) {
		var target = order[i];
		while (!node.leadsToLeaf[target]) {  // ascend
			seek = node.parent;
			route.push(seek);
			node = nodes[seek];
			node.visitCount += 1;
			if (node.visitCount > 1+node.children.length) {
				print(-1);
				return;
			}
		}
		while (seek != target) {  // descend
			for (var j = 0; j < node.children.length; ++j) {
				if (nodes[node.children[j]].leadsToLeaf[target]) {
					seek = node.children[j];
					break;
				}
			}
			route.push(seek);
			node = nodes[seek];
			node.visitCount += 1;
		}
	}

	while (seek != root) {  // ascend to the root one last time
		seek = node.parent;
		route.push(seek);
		node = nodes[seek];
		node.visitCount += 1;
		if (node.visitCount != 1+node.children.length) {
			print(-1);
			return;
		}
	}

	print(route.join(" "));
}

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]);
	};
	return tokens;
}

function main() {
	var vertexNum = parseInt(readline());

	var edges = {
		augment: function(u, v) {
			if (edges[u] === undefined) {
				edges[u] = [v];
			}
			else {
				edges[u].push(v);
			}
		}
	};

	for (var i = 1; i < vertexNum; ++i) {
		var pair = tokenizeIntegers(readline());
		edges.augment(pair[0], pair[1]);
		edges.augment(pair[1], pair[0]);
	}

	var nodes = {};
	var root = 1;

	function descend(path) {
		var current = path[path.length-1];
		nodes[current] = { index: current,
				children: [],
				leaves: [], hasLeaf: {}, leafCount: 0,
				parent: path[path.length-2], visitCount: 0 };

		var neighbors = edges[current];
		if (neighbors.length == 1 && current != root) {
			nodes[current].isLeaf = true;
			for (var i = path.length-1; i >= 0; --i) {
				var node = nodes[path[i]];
				node.leaves.push(current);
				node.hasLeaf[current] = true;
				node.leafCount += 1;
			}
			return;
		}

		for (var i = 0; i < neighbors.length; ++i) {
			var child = neighbors[i];
			if (path.length > 1 && path[path.length-2] == child) {
				continue;
			}

			nodes[current].children.push(child);

			path.push(child);
			descend(path);
			path.pop();
		}
	}

	descend([root]);

	var order = tokenizeIntegers(readline());

	var seek = root,
		route = [root],
		node = nodes[root];
	node.visitCount = 1;

	for (var i = 0; i < order.length; ++i) {
		var target = order[i];
		while (!node.hasLeaf[target]) {  // ascend
			seek = node.parent;
			route.push(seek);
			node = nodes[seek];
			node.visitCount += 1;
			if (node.visitCount > 1+node.children.length) {
				print(-1);
				return;
			}
		}
		while (seek != target) {  // descend
			for (var j = 0; j < node.children.length; ++j) {
				if (nodes[node.children[j]].hasLeaf[target]) {
					seek = node.children[j];
					break;
				}
			}
			route.push(seek);
			node = nodes[seek];
			node.visitCount += 1;
		}
	}

	while (seek != root) {
		seek = node.parent;
		route.push(seek);
		node = nodes[seek];
		node.visitCount += 1;
		if (node.visitCount != 1+node.children.length) {
			print(-1);
			return;
		}
	}

	print(route.join(" "));
}

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]);
	};
	return tokens;
}

function main() {
	var vertexNum = parseInt(readline());

	var edges = {
		augment: function(u, v) {
			if (edges[u] === undefined) {
				edges[u] = [v];
			}
			else {
				edges[u].push(v);
			}
		}
	};

	for (var i = 1; i < vertexNum; ++i) {
		var pair = tokenizeIntegers(readline());
		edges.augment(pair[0], pair[1]);
		edges.augment(pair[1], pair[0]);
	}

	var nodes = {};
	var root = 1;

	function descend(path) {
		var current = path[path.length-1];
		nodes[current] = { index: current,
				children: [],
				leaves: [], hasLeaf: {}, leafCount: 0,
				parent: path[path.length-2], visitCount: 0 };

		var neighbors = edges[current];
		if (neighbors.length == 1 && current != root) {
			nodes[current].isLeaf = true;
			for (var i = path.length-1; i >= 0; --i) {
				var node = nodes[path[i]];
				node.leaves.push(current);
				node.hasLeaf[current] = true;
				node.leafCount += 1;
			}
			return;
		}

		for (var i = 0; i < neighbors.length; ++i) {
			var child = neighbors[i];
			if (path.length > 1 && path[path.length-2] == child) {
				continue;
			}

			nodes[current].children.push(child);

			path.push(child);
			descend(path);
			path.pop();
		}
	}

	descend([root]);

	var order = tokenizeIntegers(readline());

	var seek = root,
		route = [root],
		node = nodes[root];

	for (var i = 0; i < order.length; ++i) {
		var target = order[i];
		while (!node.hasLeaf[target]) {  // ascend
			seek = node.parent;
			route.push(seek);
			node = nodes[seek];
			node.visitCount += 1;
			if (node.visitCount > 2*node.children.length) {
				print(-1);
				return;
			}
		}
		while (seek != target) {  // descend
			for (var i = 0; i < node.children.length; ++i) {
				if (nodes[node.children[i]].hasLeaf[target]) {
					seek = node.children[i];
					break;
				}
			}
			route.push(seek);
			node = nodes[seek];
			node.visitCount += 1;
		}
	}

	while (true) {
		seek = node.parent;
		route.push(seek);
		node = nodes[seek];
		node.visitCount += 1;
		if (seek == root) {
			print(route.join(" "));
			return;
		}
		if (node.visitCount != 2*node.children.length) {
			print(-1);
			return;
		}
	}
}

main();


var lines = parseInt(readline());

for (var i = 0; i < lines; i++) {
  var line = readline().split(" ");
  var hpC = parseInt(line[0]);
  var damC = parseInt(line[1]);
  line = readline().split(" ");
  var hpE = parseInt(line[0]);
  var damE = parseInt(line[1]);
  line = readline().split(" ");
  var coins = parseInt(line[0]);
  var attack = parseInt(line[1]);
  var defense = parseInt(line[2]);
  var h = 0;
  var win = false;
  while (!win && h <= coins) {
    var turnsC = Math.ceil(hpE / (damC + attack * h));
    var turnsE = Math.ceil((hpC + defense * (coins - h)) / damE);
    if (turnsC <= turnsE) {
      win = true;
      print("YES");
    } else {
      var hForSpeedUp = Math.ceil((hpE / (turnsC - 1) - damC) / attack);
      var hForSlowDown = Math.ceil(((turnsE + 1) * damE - hpC) / defense);
      h += Math.min(hForSpeedUp - h, hForSlowDown - (coins - h));
    }
  }
  if (!win) print("NO");
}

const solve = (ch,cd,mh,md,k,w,a)=>{
     let chelath = Math.ceil(ch/md);
     let cdamage = Math.ceil(mh/cd);
     if(cdamage<=chelath) console.log("YES");
     else if(k===0) console.log("NO");
     else{
          cd = cd + (k*w);
          for(let i=0;i<=k;i++){
               if(i!=0){
                    cd-=w;
                    ch+=a;
               }
               chelath = Math.ceil(ch/md);
               cdamage = Math.ceil(mh/cd);
               if(cdamage<=chelath){
                    console.log("YES");
                    return;
               }
          }
          console.log("NO");
     }
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let arr1 = readline().trim().split(" ").map(cur=>parseInt(cur));
       let arr2 = readline().trim().split(" ").map(cur=>parseInt(cur));
       let arr3 = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr1[0],arr1[1],arr2[0],arr2[1],arr3[0],arr3[1],arr3[2]);
  }
}
main();

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 [hc, dc] = lines[l++].trim().split(' ').map(Number)
        const [hm, dm] = lines[l++].trim().split(' ').map(Number)
        const [k, w, a] = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(hc, dc, hm, dm, k, w, a) ? 'YES' : 'NO'
    }
    console.log(output.join('\n'))
// })()
})

function solve(hc, dc, hm, dm, k, w, a) {
    for (let i = 0; i <= k; i++) {
        const j = k - i
        if (win(hc + i * a, dc + j * w, hm, dm)) return true
    }
    return false
}
function win(hc, dc, hm, dm) {
    const a = Math.ceil(hc / dm)
    const b = Math.ceil(hm / dc)
    return a >= b
}

const check = (hc,dc,hm,dm) =>{
    return (Math.ceil(hc/dm)>=Math.ceil(hm/dc));
}
var t=readline();
while(t--){
    var h=readline().split(" ").map(x => parseInt(x));
    var m=readline().split(" ").map(x => parseInt(x));
    var att=readline().split(" ").map(x => parseInt(x));
    var pos=0;
    var l,r;
    for(var i=0;i<=att[0];i++){
        l=i;
        r=att[0]-i;
        pos|=check(h[0]+att[2]*l,h[1]+att[1]*r,m[0],m[1]);
    }

    if(pos>0){
        print("YES");
    }else print("NO");
}

function check(hc,dc,hm,dm){
    return (Math.ceil(hc/dm)>=Math.ceil(hm/dc));
}
var t=readline();
while(t--){
    var h=readline().split(" ").map(x => parseInt(x));
    var m=readline().split(" ").map(x => parseInt(x));
    var att=readline().split(" ").map(x => parseInt(x));
    var pos=0;
    var l,r;
    for(var i=0;i<=att[0];i++){
        l=i;
        r=att[0]-i;
        pos|=check(h[0]+att[2]*l,h[1]+att[1]*r,m[0],m[1]);
    }

    if(pos>0){
        print("YES");
    }else print("NO");
}

const solve = (ch,cd,mh,md,k,w,a)=>{
     let chelath = Math.floor(ch/md)+1;
     let cdamage = Math.ceil(mh/cd);
     if(cdamage<=chelath) console.log("YES");
     else if(k===0) console.log("NO");
     else{
          cd = cd + (k*w);
          for(let i=0;i<=k;i++){
               if(i!=0){
                    cd-=w;
                    ch+=a;
               }
               chelath = Math.floor(ch/md)+1;
               cdamage = Math.ceil(mh/cd);
               if(cdamage<=chelath){
                    console.log("YES");
                    return;
               }
          }
          console.log("NO");
     }
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let arr1 = readline().trim().split(" ").map(cur=>parseInt(cur));
       let arr2 = readline().trim().split(" ").map(cur=>parseInt(cur));
       let arr3 = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr1[0],arr1[1],arr2[0],arr2[1],arr3[0],arr3[1],arr3[2]);
  }
}
main();


// Polyfill for NodeJS
if (undefined == readline) {
	var rLines = require('fs').readFileSync("/dev/stdin", "utf8").split("\n"),
		rIndex = 0,
		readline = function() {
			rIndex ++
			return rLines[rIndex - 1]
		}
}
if (undefined == print) {
	var print = console.log
}

// Useful Read functions
var int = function() {
	return parseInt(readline())
}

var ints = function() {
	return readline().split(' ')
		.map(function(x) {
			return parseInt(x)
		})
}

// The answer

var ns = ints(),
	n = ns[0],
	m = ns[1]
	links_count = [],
	links = [],
	i = 0,
	x = 0,
	y = 0,
	pos = [],
	failed = false

if (m == 0) {
	print("YES")
} else {
	for(i = 0; i <=n; i++) {
		links[i] = []
		links_count[i] = 0
	}

	for(i = 0; i < m; i++) {
		pos = ints()
		links_count[pos[0]] ++
		links_count[pos[1]] ++
		if (pos[0] < pos[1])
			links[pos[0]].push(pos[1])
		else
			links[pos[1]].push(pos[0])
	}

	for (x = 1; x < n && !failed; x ++) {
		i = links[x].length - 1
		while (i >= 0 && !failed) {
			failed = links_count[x] != links_count[links[x][i]]
			links_count[links[x][i]] --
			i --
		}
	}

	if (failed)
		print("NO")
	else
		print("YES")
}

  var tmp = readline().split(' ').map(function(x) { return parseInt(x)});
  var n = tmp[0];
  var m = tmp[1];
  var e = [];
  var vis = [];
  for(var i = 1; i <= n; i += 1) {
    e[i] = [];
    vis[i] = false;
  }
  for(var i = 1; i <= m; i += 1) {
    var tmp = readline().split(' ').map(function(x) { return parseInt(x)});
    e[tmp[0]].push(tmp[1]);
    e[tmp[1]].push(tmp[0]);
  }
  var finding = true;
  for(var i = 1; i <= n && finding; i += 1) {
    if(!vis[i]) {
      vis[i] = true;
      var vn = 1;
      var en = e[i].length;
      var stack = [i];
      while(stack.length > 0) {
        var d = stack.pop();
        for(var b in e[d]) {
          if(!vis[e[d][b]]) {
            vis[e[d][b]] = true;
            stack.push(e[d][b]);
            vn += 1;
            en += e[e[d][b]].length;
          }
        }
      }
      if(en !== vn * (vn - 1)) {
        finding = false;
      }
    }
  }
  if(finding) {
    print('YES');
  } else {
    print('NO');
  }

/*filesystem = require('fs');
var inputLines = filesystem.readFileSync('input.txt').toString().split('\n');
var inputIndex = 0;

function readline() {
    return inputLines[inputIndex++];
}

function print() {
    var ans = "";
    for (var i = 0; i < arguments.length; i++) {
        if (i != 0) ans += " ";
        ans += arguments[i].toString();
    }
    console.log(ans);
}*/
//FILESYSTEM

var currentLine;
var currentIndex;
function read() {
    if ((currentLine == null) || (currentIndex == currentLine.length)) {
        currentLine = readline().split(' ');
        currentIndex = 0;
    }
    return currentLine[currentIndex++];
}

function readInt() {
    return parseInt(read());
}
//HELPERS
function dfs(v) {
    var q = [];
    q.push(v);
    w[v] = true;
    for (var i = 0; i < q.length; i++) {
        var v = q[i];
        for (var j = 0; j < e[v].length; j++) {
            var u = e[v][j];
            if (!w[u]) {
                q.push(u);
                w[u] = true;
            }
        }
    }
    return q.length;
}

var n = readInt(), m = readInt();
var w = new Array(n + 1).fill(false);
var e = new Array(n + 1);
for (var i = 1; i <= n; i++) e[i] = [];
for (var i = 0; i < m; i++) {
    var a = readInt(), b = readInt();
    e[a].push(b);
    e[b].push(a);
}
var tot = 0;
for (var i = 1; i <= n; i++) {
    if (!w[i]) {
        var size = dfs(i);
        tot += size * (size - 1);
    }
}
if (tot == 2 * m) print('YES');
else print('NO');

  var tmp = readline().split(' ').map(function(x) { return parseInt(x)});
  var n = tmp[0];
  var m = tmp[1];
  var e = [];
  var vis = [];
  for(var i = 1; i <= n; i += 1) {
    e[i] = [];
    vis[i] = false;
  }
  for(var i = 1; i <= m; i += 1) {
    var tmp = readline().split(' ').map(function(x) { return parseInt(x)});
    e[tmp[0]].push(tmp[1]);
    e[tmp[1]].push(tmp[0]);
  }
  var cnt_vertices = 0
  var cnt_edges = 0;
  var stack = [];
  var dfs = function(x) {
    stack.push(x);
    while(stack.length > 0) {
      var a = stack.pop();
      if(vis[a]) {
        continue;
      }
      vis[a] = true;
      vn += 1;
      en += e[a].length;
      for(var b in e[a]) {
        stack.push(e[a][b]);
        // dfs(e[a][b]);
      }
    }
  };
  var finding = true;
  var vn = 0;
  var en = 0;
  for(var i = 1; i <= n && finding; i += 1) {
    if(!vis[i]) {
      vn = 0
      en = 0;
      dfs(i);
      if(en !== vn * (vn - 1)) {
        finding = false;
      }
    }
  }
  if(finding) {
    print('YES');
  } else {
    print('NO');
  }

  var tmp = readline().split(' ').map(function(x) { return parseInt(x)});
  var n = tmp[0];
  var m = tmp[1];
  var e = [];
  var vis = [];
  for(var i = 1; i <= n; i += 1) {
    e[i] = [];
    vis[i] = false;
  }
  for(var i = 1; i <= m; i += 1) {
    var tmp = readline().split(' ').map(function(x) { return parseInt(x)});
    e[tmp[0]].push(tmp[1]);
    e[tmp[1]].push(tmp[0]);
  }
  var finding = true;
  for(var i = 1; i <= n && finding; i += 1) {
    if(!vis[i]) {
      vis[i] = true;
      var vn = 1;
      var en = e[i].length;
      var stack = [i];
      while(stack.length > 0) {
        var d = stack.pop();
        for(var b in e[d]) {
          if(!vis[e[d][b]]) {
            vis[e[d][b]] = true;
            stack.push(e[d][b]);
            vn += 1;
            en += e[d].length;
          }
        }
      }
      if(en !== vn * (vn - 1)) {
        finding = false;
      }
    }
  }
  if(finding) {
    print('YES');
  } else {
    print('NO');
  }

// Polyfill for NodeJS
if (undefined == readline) {
	var rLines = require('fs').readFileSync("/dev/stdin", "utf8").split("\n"),
		rIndex = 0,
		readline = function() {
			rIndex ++
			return rLines[rIndex - 1]
		}
}
if (undefined == print) {
	var print = console.log
}

// Useful Read functions
var int = function() {
	return parseInt(readline())
}

var ints = function() {
	return readline().split(' ')
		.map(function(x) {
			return parseInt(x)
		})
}

// The answer

var ns = ints(),
	n = ns[0],
	m = ns[1]
	links_count = [],
	links = [],
	i = 0,
	x = 0,
	y = 0,
	pos = [],
	failed = false

if (m == 0) {
	print("YES")
} else {
	for(i = 0; i <=n; i++) {
		links[i] = []
		links_count[i] = 0
	}

	for(i = 0; i < m; i++) {
		pos = ints()
		links_count[pos[0]] ++
		links_count[pos[1]] ++
		if (pos[0] < pos[1])
			links[pos[0]].push(pos[1])
		else
			links[pos[1]].push(pos[0])
	}

	for (x = 1; x < n && !failed; x ++) {
		i = links[x].length - 1
		while (i >= 0 && !failed) {
			failed = links_count[x] != links_count[links[x][i]]
			i --
		}
	}

	if (failed)
		print("NO")
	else
		print("YES")
}

// Polyfill for NodeJS
if (undefined == readline) {
	var rLines = require('fs').readFileSync("/dev/stdin", "utf8").split("\n"),
		rIndex = 0,
		readline = function() {
			rIndex ++
			return rLines[rIndex - 1]
		}
}
if (undefined == print) {
	var print = console.log
}

// Useful Read functions
var int = function() {
	return parseInt(readline())
}

var ints = function() {
	return readline().split(' ')
		.map(function(x) {
			return parseInt(x)
		})
}

// The answer

var ns = ints(),
	n = ns[0],
	m = ns[1]
	mem = [],
	i = 0,
	x = 0,
	y = 0,
	pos = [],
	friend = function(x, y) {
		return x < y ? (mem[x][y] !== undefined) : (mem[y][x] !== undefined)
	},
	failed = false

for(i = 0; i <=n; i++) {
	mem[i] = {}
}

for(i = 0; i < m; i++) {
	pos = ints()
	if (pos[0] < pos[1]) {
		x = pos[0]
		y = pos[1]
	} else {
		x = pos[1]
		y = pos[0]
	}
	mem[x][y] = true
}

i = 1
while (i <= n && !failed) {
	for (x in mem[i]) {
		for(y in mem[x]) {
			if (! friend(i, y)) {
				failed = true
				break
			}
		}
		if (failed)
			break
	}
	i ++
}

if (failed)
	print("NO")
else
	print("YES")

// Polyfill for NodeJS
if (undefined == readline) {
	var rLines = require('fs').readFileSync("/dev/stdin", "utf8").split("\n"),
		rIndex = 0,
		readline = function() {
			rIndex ++
			return rLines[rIndex - 1]
		}
}
if (undefined == print) {
	var print = console.log
}

// Useful Read functions
var int = function() {
	return parseInt(readline())
}

var ints = function() {
	return readline().split(' ')
		.map(function(x) {
			return parseInt(x)
		})
}

// The answer

var ns = ints(),
	n = ns[0],
	m = ns[1]
	mem = [],
	i = 0,
	x = 0,
	y = 0,
	pos = [],
	friend = function(x, y) {
		return x < y ? (mem[x][y] !== undefined) : (mem[y][x] !== undefined)
	},
	failed = false

if (m == 0) {
	print("YES")
} else {
	for(i = 0; i <=n; i++) {
		mem[i] = {}
		mem[i][i] = true
	}

	for(i = 0; i < m; i++) {
		pos = ints()
		if (pos[0] < pos[1]) {
			x = pos[0]
			y = pos[1]
		} else {
			x = pos[1]
			y = pos[0]
		}
		mem[x][y] = true
	}

	i = 1
	while (i <= n && !failed) {
		for (x in mem[i]) {
			for(y in mem[x]) {
				if (! friend(i, y)) {
					failed = true
					break
				}
			}
			if (failed)
				break
		}
		i ++
	}

	if (failed)
		print("NO")
	else
		print("YES")
}

// Polyfill for NodeJS
if (undefined == readline) {
	var rLines = require('fs').readFileSync("/dev/stdin", "utf8").split("\n"),
		rIndex = 0,
		readline = function() {
			rIndex ++
			return rLines[rIndex - 1]
		}
}
if (undefined == print) {
	var print = console.log
}

// Useful Read functions
var int = function() {
	return parseInt(readline())
}

var ints = function() {
	return readline().split(' ')
		.map(function(x) {
			return parseInt(x)
		})
}

// The answer

var ns = ints(),
	n = ns[0],
	m = ns[1]
	mem = [],
	i = 0,
	x = 0,
	y = 0,
	pos = [],
	failed = false

if (m == 0) {
	print("YES")
} else {
	for(i = 0; i <=n; i++) {
		mem[i] = 0
	}

	for(i = 0; i < m; i++) {
		pos = ints()
		mem[pos[0]] ++
		mem[pos[1]] ++
	}

	for (x = 1; x < n && !failed; x ++)
		for (y = x + 1; y <= n && !failed; y ++)
			failed = (mem[x] != mem[y])

	if (failed)
		print("NO")
	else
		print("YES")
}

// Polyfill for NodeJS
if (undefined == readline) {
	var rLines = require('fs').readFileSync("/dev/stdin", "utf8").split("\n"),
		rIndex = 0,
		readline = function() {
			rIndex ++
			return rLines[rIndex - 1]
		}
}
if (undefined == print) {
	var print = console.log
}

// Useful Read functions
var int = function() {
	return parseInt(readline())
}

var ints = function() {
	return readline().split(' ')
		.map(function(x) {
			return parseInt(x)
		})
}

// The answer

var ns = ints(),
	n = ns[0],
	m = ns[1]
	mem = [],
	i = 0,
	x = 0,
	y = 0,
	pos = [],
	friend = function(x, y) {
		return mem[x][y]
	},
	failed = false

if (m == 0) {
	print("YES")
} else {
	for(i = 0; i <=n; i++) {
		mem[i] = []
		for(x = 0; x <=n; x++)
			mem[i][x] = false
	}

	for(i = 0; i < m; i++) {
		pos = ints()
		mem[pos[0]][pos[1]] = true
		mem[pos[1]][pos[0]] = true
	}

	for(i = 1; i <=n && !failed; i++) {
		for(x = 1; x <=n && !failed; x++) {
			for(y = 1; y <=n && !failed; y++) {
				failed = friend(i, x) && friend(x, y) && !friend(i, y)
			}
		}
	}

	if (failed)
		print("NO")
	else
		print("YES")
}

// Polyfill for NodeJS
if (undefined == readline) {
	var rLines = require('fs').readFileSync("/dev/stdin", "utf8").split("\n"),
		rIndex = 0,
		readline = function() {
			rIndex ++
			return rLines[rIndex - 1]
		}
}
if (undefined == print) {
	var print = console.log
}

// Useful Read functions
var int = function() {
	return parseInt(readline())
}

var ints = function() {
	return readline().split(' ')
		.map(function(x) {
			return parseInt(x)
		})
}

// The answer

var ns = ints(),
	n = ns[0],
	m = ns[1]
	mem = [],
	i = 0,
	x = 0,
	y = 0,
	pos = [],
	friend = function(x, y) {
		return x == y || mem[x][y]
	},
	failed = false

if (m == 0) {
	print("YES")
} else {
	for(i = 0; i <=n; i++) {
		mem[i] = []
		for(x = 0; x <=n; x++)
			mem[i][x] = false
	}

	for(i = 0; i < m; i++) {
		pos = ints()
		mem[pos[0]][pos[1]] = true
	}

	for(i = 1; i <=n && !failed; i++) {
		for(x = 1; x <=n && !failed; x++) {
			for(y = 1; y <=n && !failed; y++) {
				failed = friend(i, x) && friend(x, y) && !friend(x, y)
			}
		}
	}

	if (failed)
		print("NO")
	else
		print("YES")
}

// Polyfill for NodeJS
if (undefined == readline) {
	var rLines = require('fs').readFileSync("/dev/stdin", "utf8").split("\n"),
		rIndex = 0,
		readline = function() {
			rIndex ++
			return rLines[rIndex - 1]
		}
}
if (undefined == print) {
	var print = console.log
}

// Useful Read functions
var int = function() {
	return parseInt(readline())
}

var ints = function() {
	return readline().split(' ')
		.map(function(x) {
			return parseInt(x)
		})
}

// The answer

var ns = ints(),
	n = ns[0],
	m = ns[1]
	mem = [],
	i = 0,
	x = 0,
	y = 0,
	pos = [],
	friend = function(x, y) {
		return x < y ? (mem[x][y] !== undefined) : (mem[y][x] !== undefined)
	},
	failed = false

if (m == 0) {
	print("YES")
} else {
	for(i = 0; i <=n; i++) {
		mem[i] = {}
	}

	for(i = 0; i < m; i++) {
		pos = ints()
		if (pos[0] < pos[1]) {
			x = pos[0]
			y = pos[1]
		} else {
			x = pos[1]
			y = pos[0]
		}
		mem[x][y] = true
	}

	i = 1
	while (i <= n && !failed) {
		for (x in mem[i]) {
			for(y in mem[x]) {
				if (! friend(i, y)) {
					failed = true
					break
				}
			}
			if (failed)
				break
		}
		i ++
	}

	if (failed)
		print("NO")
	else
		print("YES")
}


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

    var n = read.number();
    var a = read.arr();
    var res = [a[0]];
    var length = 0;
    for(var i = 1; i < n; i++) {
        if(length % 2) {
            res.push(a[i]);
            length++;
        }
        else {
            if(res[length] !== a[i]) {
                res.push(a[i]);
                length++;
            }
        }
    }
    length += 1;
    if(length % 2) {
        length -=1;
        res.pop();
    }

    print(n - length);
    print(res.join(''));
}());

'use strict';

function main() {
  let n = parseInt(next());
  let s = next();
  let i = 0;

  let res = '';
  let ereased = 0;
  for(i = 0; i < n; i++) {
    if(i == n-1 || s[i+1] !== s[i]) {
      res += s[i];
    } else {
      let j = i+1;
      while(j < n && s[j] === s[i]) {
        j++;
      }
      j--;
      if((i-ereased)%2 == 0) {
        res += s[i];
        ereased += j-i;
      } else {
        res += s[i]+''+s[i];
        ereased += j-i-1;
      }
      i = j;
    }
  }

  if(res.length%2) {
    println(n-res.length+1);
    println(res.substr(0, res.length-1));
  } else {
    println(n-res.length);
    println(res.substr(0, res.length));
  }
}

//process.stdin.resume();
process.stdin.setEncoding('ascii');

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

// next: reads next value from input.
let inputCursor = 0;
let next = () => {
  return inputCursor < input.length ? input[inputCursor++] : '';
};

//print: print one or more space seperated values.
let print = (...data) => {
  for(let i = 0; i < data.length; i++) {
    process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));
  }
};

//println: print one or more space seperated values then a line feed.
let println = (...data) => {
  print(...data);
  print('\n');
};

//after the the input is read.
process.stdin.on('end', () => {
    input = input.trim().split(/[\s]+/);
    main();
});

'use strict';

function main() {
  let n = parseInt(next());
  let s = next(), res = '';
  let i = 0, j = 0, ereased = 0;
  for(i = 0; i < n; i++) {
    if(i == n-1 || s[i+1] !== s[i]) {
      res += s[i];
    } else {
      j = i+1;
      while(j < n && s[j] === s[i]) {
        j++;
      }
      j--;
      if((i-ereased)%2) {
        res += s[i]+s[i];
        ereased += j-i-1;
      } else {
        res += s[i];
        ereased += j-i;
      }
      i = j;
    }
  }

  println(n-res.length+res.length%2);
  println(res.substr(0, res.length-res.length%2));
}

//process.stdin.resume();
process.stdin.setEncoding('ascii');

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

// next: reads next value from input.
let inputCursor = 0;
let next = () => {
  return inputCursor < input.length ? input[inputCursor++] : '';
};

//print: print one or more space seperated values.
let print = (...data) => {
  for(let i = 0; i < data.length; i++) {
    process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));
  }
};

//println: print one or more space seperated values then a line feed.
let println = (...data) => {
  print(...data);
  print('\n');
};

//after the the input is read.
process.stdin.on('end', () => {
    input = input.trim().split(/[\s]+/);
    main();
});

'use strict';

function main() {
  let n = parseInt(next());
  let s = next();
  let stack = [], i = 0, res = '';
  for(i = 0; i < n; i++) {
    if((!stack.length) || s[i] != stack[stack.length-1] || stack.length % 2 == 0) {
      stack.push(s[i]);
    }
  }
  if(stack.length%2) stack.pop();
  res = stack.join('');
  println(n-res.length+'\n'+res);
}

//process.stdin.resume();
process.stdin.setEncoding('ascii');

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

// next: reads next value from input.
let inputCursor = 0;
let next = () => {
  return inputCursor < input.length ? input[inputCursor++] : '';
};

//print: print one or more space seperated values.
let print = (...data) => {
  for(let i = 0; i < data.length; i++) {
    process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));
  }
};

//println: print one or more space seperated values then a line feed.
let println = (...data) => {
  print(...data);
  print('\n');
};

//after the the input is read.
process.stdin.on('end', () => {
    input = input.trim().split(/[\s]+/);
    main();
});

'use strict';

function main() {
  let n = parseInt(next());
  let s = next();
  let i = 0;

  let res = '';
  let ereased = 0;
  for(i = 0; i < n; i++) {
    if(i == n-1 || s[i+1] !== s[i]) {
      res += s[i];
    } else {
      let j = i+1;
      while(j < n && s[j] === s[i]) {
        j++;
      }
      j--;
      if((i-ereased)%2 == 0) {
        res += s[i];
        ereased += j-i;
      } else {
        res += s[i]+''+s[i];
        ereased += j-i-1;
      }
      i = j;
    }
  }

  if(res.length%2) {
    println(n-res.length+1);
    println(s.substr(0, res.length-1));
  } else {
    println(n-res.length);
    println(s.substr(0, res.length));
  }
}

//process.stdin.resume();
process.stdin.setEncoding('ascii');

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

// next: reads next value from input.
let inputCursor = 0;
let next = () => {
  return inputCursor < input.length ? input[inputCursor++] : '';
};

//print: print one or more space seperated values.
let print = (...data) => {
  for(let i = 0; i < data.length; i++) {
    process.stdout.write(data[i] + (i < data.length - 1 ? ' ' : ''));
  }
};

//println: print one or more space seperated values then a line feed.
let println = (...data) => {
  print(...data);
  print('\n');
};

//after the the input is read.
process.stdin.on('end', () => {
    input = input.trim().split(/[\s]+/);
    main();
});


const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var calculateTrees = (cont, startRow, endRow, startCloumn, endColumn) => {
    let ans = 0;
    for (let i = startRow; i < endRow; i++)
        for (let j = startCloumn; j < endColumn; j++)
            if (cont[i][j] == 1)
                ans += cont[i][j];
    return ans;
}
var N, M, cont = [], houseX, houseY, indicator = 0, temp = [];
rl.on('line', (input) => {
    if (indicator == 0) {
        temp = input.split(' ').map(item => parseInt(item));
        N = temp[0], M = temp[1];
        indicator++;
    } else if (indicator <= N) {
        cont.push(input.split(' ').map(item => parseInt(item)));
        indicator++;
    } else {
        temp = input.split(' ').map(item => parseInt(item));
        houseX = temp[0], houseY = temp[1];
    }
}).on("close", () => {
    let ans = N * M, helper;
    for (let i = 0; i < N; i++) {
        for (let j = 0; j < M; j++) {
            if (i + houseX <= N && j + houseY <= M) {
                helper = calculateTrees(cont, i, i + houseX, j, j + houseY);
                if (ans > helper)
                    ans = helper;
            }
            if (i + houseY <= N && j + houseX <= M) {
                helper = calculateTrees(cont, i, i + houseY, j, j + houseX);
                if (ans > helper)
                    ans = helper;
            }
        }
    }
    console.log(ans);
});

'use strict'

let lll = readline().split(' ').map(v => parseInt(v))
let N = lll[0]
let M = lll[1]

let s = []
while (lll = readline()) {
  s.push(lll.split(' ').map(v => parseInt(v)))
}

let ab = s.pop()
let A = ab[0]
let B = ab[1]

let min = Infinity

for (let y = 0; y <= N - A; y++) {
  for (let x = 0; x <= M - B; x++) {
    let ts = 0
    d: for (let dy = 0; dy < A; dy++) {
      for (let dx = 0; dx < B; dx++) {
        if (s[y + dy][x + dx] == 1) ts++
        if (ts >= min) break d
      }
    }
    if (ts < min) min = ts
  }
}

for (let y = 0; y <= N - B; y++) {
  for (let x = 0; x <= M - A; x++) {
    let ts = 0
    d: for (let dy = 0; dy < B; dy++) {
      for (let dx = 0; dx < A; dx++) {
        if (s[y + dy][x + dx] == 1) ts++
        if (ts >= min) break d
      }
    }
    if (ts < min) min = ts
  }
}

print(min)

const readline = require('readline');

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

var calculateTrees = function (cont, startRow, endRow, startCol, endCol) {
    let ans = 0;
    for (let i = startRow; i < endRow; i++)
        for (let j = startCol; j < endCol; j++)
            ans += cont[i][j];

    //console.log(" startRow=%d  endRow=%d  startCol=%d  endCol=%d   ans=%d",startRow, endRow, startCol, endCol,ans);
    return ans;
}

var indicator = 0, N, M, temp, cont = [], HouseX, HouseY;
rl.on('line', (input) => {
    if (indicator == 0) {
        temp = input.split(" ").map(item => parseInt(item));
        N = temp[0];
        M = temp[1];
        indicator++;
    }
    else if (indicator <= N) {
        cont.push(input.split(" ").map(item => parseInt(item)));
        indicator++;
    }
    else {
        temp = input.split(" ").map(item => parseInt(item));
        HouseX = temp[0];
        HouseY = temp[1];
    }
}).on('close', () => {
    let ans = N * M, helper;
    for (let i = 0; i < N; i++) {
        for (let j = 0; j < M; j++) {
            if (i + HouseX <= N && j + HouseY <= M) {
                helper = calculateTrees(cont, i, i + HouseX, j, j + HouseY);
                if (ans > helper)
                    ans = helper;
            }
            if (i + HouseY <= N && j + HouseX <= M) {
                helper = calculateTrees(cont, i, i + HouseY, j, j + HouseX);
                if (ans > helper)
                    ans = helper;
            }
        }
    }
    console.log(ans);
});

var getArr = function() {
	return readline().split(' ').map(function (a) {
		return parseInt(a);
	})
};

var getTree = function(arr, x, y, a, b) {
	var res = 0;
	for (var i = 0; i < a; i++) {
		for (var j = 0; j < b; j++) {
			res += arr[x + i][y + j];
		}
	}
	return res;
};

var data = [];
var input;

input = getArr();
var m = input[0];
var n = input[1];
for (var k = 0; k < m; k++) {
	data.push(getArr());
}
input = getArr();
var a = input[0];
var b = input[1];

var min = getTree(data, 0, 0, a, b);
for (var i = 0; i < m - a + 1; i++) {
	for (var j = 0; j < n - b + 1; j++) {
		min = Math.min(min, getTree(data, i, j, a, b));
	}
}

print(min);


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]);
	};
	return tokens;
}

function main() {
	var integers = tokenizeIntegers(readline());
	var rowNum = integers[0], colNum = integers[1];
	var gapFound = {}, gaps = [];
	for (var r = 0; r < rowNum; ++r) {
		var line = trim(readline());
		var gap = line.indexOf('S') - line.indexOf('G');
		if (gap < 0) {
			print(-1);
			return;
		}
		if (!gapFound[gap]) {
			gapFound[gap] = true;
			gaps.push(gap);
		}
	}
	print(gaps.length);
}

main();

print(function(n, m){
	var a=[];
	for(var i=0; i<n; i++){
		var s=readline();
		var G=s.indexOf('G');
		var S=s.indexOf('S');
		if(S<G){
			return -1;
		}else{
			a.push(S-G);
		}
	}
	a.sort(function(a,b){return a-b;});
	var ans=1;
	for(var i=1;i<n;i++){
		if(a[i]!==a[i-1]) ans++;
	}
	return ans;
}.apply(0, readline().split(' ').map(Number)));

var nm = readline().split(' ').map(Number);
var n = nm[0];
var m = nm[1];
var mas = [];
var ans = 0;

for (var i=0; i<n; i++) {
	var s = readline();
	mas[i] = s.indexOf('S') - s.indexOf('G');
	if (mas[i] < 0) {
		print(-1);
		var ans = -1;
		break;
	}
}

if (ans == 0) {
	mas.sort( (a,b) => a-b );
	var count = 0;
	for (var i=0; i<n-1; i++) {
	if (mas[i] != mas[i+1]) count++;
	}
	print(count+1);
}

var nm = readline().split(' ').map(Number);
var n = nm[0];
var m = nm[1];
var mas = [];
var ans = 0;

for (var i=0; i<n; i++) {
	var s = readline();
	mas[i] = s.indexOf('S') - s.indexOf('G');
	if (mas[i] < 0) {
		print(-1);
		var ans = -1;
		break;
	}
}

if (ans == 0) {
	mas.sort( (a,b) => a-b );
	var count = 0;
	for (var i=0; i<n-1; i++) {
	if (s[i] != s[i+1]) count++;
	}
	print(count);
}

print(function(n, m){
	var a=[];
	for(var i=0; i<n; i++){
		var s=readline();
		var G=s.indexOf('G');
		var S=s.indexOf('S');
		if(S<G){
			return -1;
		}else{
			a.push([S-G]);
		}
	}
	a.sort(function(a,b){return a-b});
	var ans=0;
	for(var i=1;i<n;i++){
		if(a[i]!==a[i-1]) ans++;
	}
	return ans;
}.apply(0, readline().split(' ').map(Number)));


var res = eval(readline()).toString();
for(i=0; i<res.length; i++)	{
	for(j=0; j<res[i].charCodeAt(0); j++)	{
		write('+');
	}
	write(".>");
}

const input = readline();
const str = eval(input).toString();
const result = [">++++++++[<++++++>-]<"];
var last = 48;
for (var i = 0, len = str.length; i < len; i++) {
  var current = str.charCodeAt(i);
  var diff = current - last;
  result.push(diff >= 0 ? "+".repeat(diff) : "-".repeat(-diff), ".");
  last = current;
}
print(result.join(""));

var input=readline();
var operands=input.split(/[+-]/);
for(var i=0;i<operands.length;i++){
	var s='';
	for(var j=0;j<operands[i];j++)
		s+='+';
	print(s+'>');
}
var operators=input.split(/\d/);
for(var i=operators.length-2;i>0;i--){
	var s='<[<'+operators[i]+'>-]';
	print(s);
}
print('<');
print('++++++++++++++++++++++++++++++++++++++++++++++++.');

var input=readline();
var operands=input.split(/[+-]/);
for(var i=0;i<operands.length;i++){
	var s='';
	for(var j=0;j<operands[i];j++)
		s+='+';
	print(s+'>');
}
var operators=input.split(/\d/);
for(var i=operators.length-2;i>0;i--){
	var s='<[';
	for(var j=0;j<i;j++)
		s+='<';
	s+=operators[i];
	for(var j=0;j<i;j++)
		s+='>';
	s+='-]';
	print(s);
}
print('<');
print('++++++++++++++++++++++++++++++++++++++++++++++++.');

var input=readline();
var operands=input.split(/[+-]/);
for(var i=0;i<operands.length;i++){
	var s='';
	for(var j=0;j<operands[i];j++)
		s+='+';
	print(s+'>');
}
var operators=input.split(/[0-9]+/);
for(var i=operators.length-2;i>0;i--){
	var s='<[<'+operators[i]+'>-]<';
	print(s);
}
print('++++++++++++++++++++++++++++++++++++++++++++++++.');