var numGoals = readline();
var teams = [[],[]];
var goal;
for(var i = numGoals; i; i--){
	goal = readline();
	if(!teams[0].length){
		teams[0].push(goal);
	} else if(goal == teams[0][0]){
		teams[0].push(goal);
	} else{
		teams[1].push(goal);
	}
}

print(teams[0].length > teams[1].length? teams[0][0] : teams[1][0]);

const readline = require('readline');

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

/*
var indicator = 0, cont = new Map(), maxScore = 0, winner = "";

rl.on('line', (input) => {
    if (indicator == 0)
        indicator++;
    else {
        if (cont.has(input))
            cont.set(input, cont.get(input)+1);
        else
            cont.set(input, 1);

        if (maxScore < cont.get(input)) {
            maxScore = cont.get(input);
            winner = input;
        }

    }

  }).on('close',()=> {
      console.log(winner);
  //    console.log(cont);
  });
*/

var indicator = 0, team1Name = "", team2Name = "", score1 = 0, score2 = 0;

rl.on('line', (input)=> {
    if (indicator == 0)
        indicator++;
    else {
        if (input == team1Name)
            score1++;
        else if (input == team2Name)
            score2++;
        else if (team1Name == "") {
            team1Name = input;
            score1++;
        }
        else {
            team2Name = input;
            score2++;
        }
    }
}).on('close', function() {
    console.log((score1 > score2) ? team1Name : team2Name);
});

var n = +readline();
var cnt = {};
while (n--) {
	var name = readline();
	if (!cnt[name]) cnt[name] = 0;
	cnt[name]++;
}

var ans = '';
var max = 0;
for (var name in cnt)
	if (cnt[name] > max)
		max = cnt[name], ans = name;

print(ans);

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++];
}
function main() {
  let t = +readLine();
  const scores = {};
  while (t--) {
    const score = readLine();
    if (!scores[score]) scores[score] = 1;
    else scores[score]++;
  }
  const keys = Object.keys(scores);
  if (keys.length === 1) console.log(keys[0]);
  else {
    const [k1, k2] = keys;
    if (scores[k1] > scores[k2]) {
      console.log(k1);
    } else {
      console.log(k2);
    }
  }
}

const readline = require('readline');
const { SSL_OP_SSLEAY_080_CLIENT_DH_BUG } = require('constants');

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

var n,maxScore=0,myMap={},indicator=SSL_OP_SSLEAY_080_CLIENT_DH_BUG,ans="";

rl.on('line', (input) => {
    if(indicator==0){
       n= parseInt(input);
       indicator++;
    }
    else{
        if(input in myMap)
          myMap[input]++;
          else
          myMap[input]=1;
          if(maxScore<myMap[input]){
              maxScore=myMap[input];
              ans=input;

          }

    }

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

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

var n = rdn();

var t1, t2, s1 = 0, s2 = 0;

for(var i = 0; i < n; i++){
    var name = readline();
    if(!t1){
        t1 = name;
        s1++;
    }
    if(!t2 && t1 != name){
        t2 = name;
        s2++;
    }

    if(name == t1) s1++;
    if(name == t2) s2++;
}

var ans;
if(s1 > s2){
    ans = t1;
}else{
    ans = t2;
}

write(ans);

var n = +readline();
var teams={};
for (var i = 0; i < n; i++) {
	var element = readline();
	if(teams[element]){
		teams[element] +=1;
	} else {
		teams[element]=1;
	}
}
print(
	teams[Object.keys(teams)[0]] > (teams[Object.keys(teams)[1]]|| 0)
	 ? Object.getOwnPropertyNames(teams)[0]
	 : Object.getOwnPropertyNames(teams)[1]
	 );

var readline = require('readline'),
    rl = readline.createInterface(process.stdin, process.stdout);
/*
var n=0;

rl.on('line', function (line) {
var counter=0;
var teams1=[];
var Fcount=0;
var Fteam=0;
    if (arr.length == 0) {
        arr = line.split(' ').map(item => { return parseInt(item) });
        n = arr[0];

    }
    else {

        if (++counter < n) {
             teams1.push(line.split(' ').map(item => { return parseInt(item) }))
             Fteam=teams1[0];

        }
        else {
            teams1.push(line.split(' ').map(item => { return parseInt(item) }));
            }
            for(let i in teams1){
                if(teams1[i]==Fteam)
                    Fcount++;
                     else {
                        Steam=teams1[i] ;
                        Scount++;
            }
               if(Fcount>Scount)
            console.log(Fteam);
                else console.log(Steam);
            rl.close();
        }

    }

}

);
*/
var n = -1;
var dict = {};
rl.on('line', function (line) {
    if (n == -1)
        n = parseInt(line);
    else if (n > 1) {
        if (line in dict)
            dict[line]++;
        else dict[line] = 1;
        n--;

    }
    else {
        if (line in dict)
            dict[line]++;
        else dict[line] = 1;
        var ans,score=0;
        for (var key in dict ){
            var value = dict[key];
            if(score<value){
            score=value;
            ans=key;}
        }
        console.log(ans)

//  console.log(Object.keys(dict));
//console.log(Object.values(dict));
//console.log(JSON.stringify(dict));

        rl.close();
    }

});

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++];
}

const store = {};

function main() {
	let n = readLine() >> 0;

	let map = {};
	let maxTeam = { score: 0, team: '' };

	while (n--) {
		let team = readLine();
		map[team] = (map[team] || 0) + 1;

		if (map[team] > maxTeam.score) {
			maxTeam = { score: map[team], team };
		}
	}

	console.log(maxTeam.team);
}

var n = +readline();
var counter = {};
for (var i = 0; i < n; i++) {
    var name = readline();
    if (!counter[name]) {
        counter[name] = 0
    }
    counter[name] += 1
}
var command_names = Object.keys(counter);
print(command_names[Number(command_names.length == 2 && counter[command_names[1]] > counter[command_names[0]])]);

var n = +readline();
var counter = {};
var command_names = [];
for (var i = 0; i < n; i++) {
    var command_name = readline();
    if (counter[command_name]) {
        counter[command_name] += 1
    } else {
        command_names.push(command_name);
        counter[command_name] = 1
    }
}
if (command_names.length == 1 || counter[command_names[0]] > counter[command_names[1]]) {
    print(command_names[0])
} else {
    print(command_names[1])
}

var numberOfGoal = Number(readline())

var scores = {}
for (var i = 0; i < numberOfGoal; i++) {
  var goal = readline()
  var scored = scores[goal]
  if (scored == null) {
    scores[goal] = 1
  } else {
    scored += 1
    scores[goal] = scored
  }
}
var team = Object.keys(scores)

var scoreTeamOne = scores[team[0]] || 0
var scoreTeamTwo = scores[team[1]] || 0

if (scoreTeamOne > scoreTeamTwo) {
  print(team[0])
} else {
  print(team[1])
}

;(function () {

	var n = +readline();
	var k1n = '', k1s = 0;
	var k2n = '', k2s = 0;

	while (n--) {
		var s = readline();

		if (k1n === '' || k1n === s) {
			k1n = s;
			k1s++;
		} else {
			k2n = s;
			k2s++;
		}
	}

	print(k1s > k2s ? k1n : k2n);

}).call(this)

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', (inputStd) => {
    inputString += inputStd;
});
process.stdin.on('end', function () {
    inputString = inputString
        .trim()
        .split('\n')
        .map((str) => {
            return str.trim();
        });
    main();
});
function readLine() {
    return inputString[currentLine++];
}
function main() {
    let stringsArray = [];
    let n = parseInt(readLine());
    for (let i = 0; i < n; i++) {
        stringsArray.push(readLine());
    }
    let first = [];
    let second = [];
    for (let i = 0; i < n; i++) {
        let x = stringsArray[0];
        stringsArray.forEach((team) => {
            if (team === x) {
                first.push(team);
            } else {
                second.push(team);
            }
        });
    }
    if (first.length > second.length) {
        console.log(first[0]);
    } else {
        console.log(second[0]);
    }
}

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 numGoals = parseInt(readline());
	var teamGoals = {},
		teamNames = [];
	for (var lineIndex = 0; lineIndex < numGoals; ++lineIndex) {
		var teamName = trim(readline());
		if (teamGoals[teamName] === undefined) {
			teamNames.push(teamName);
			teamGoals[teamName] = 1;
		}
		else {
			teamGoals[teamName] += 1;
		}
	}
	if (teamNames.length == 1) {
		print(teamNames[0]);
	}
	else {
		print(teamNames[teamGoals[teamNames[0]] > teamGoals[teamNames[1]] ?
				0 : 1]);
	}
}

main();

'use strict'

let N = +readline()
let lll
let s = {}
while (lll = readline()) {
  s[lll] = s[lll] || 0
  s[lll]++
}

let ts = Object.keys(s)
print(!(s[ts[0]] < s[ts[1]]) ? ts[0] : ts[1])

var lineas = readline();
var equipo1 = [];
var equipo2 = [];
for (var i = 0; i < lineas; i++){
    var palabra = readline();
    if (i === 0) {
         equipo1.push(palabra);
        continue;
    }
    if (equipo1[0] == palabra) {
         equipo1.push(palabra);
    } else {
         equipo2.push(palabra);
    }
}
equipo1.length > equipo2.length ? print(equipo1[0]) : print(equipo2[0]);

var tokenizer;
var index = 0;

function next(){
    while(tokenizer == null || index == tokenizer.length){
        tokenizer = readline().split(" ");
        index = 0;
    }
    var res = tokenizer[index++];
    return res;
}

function nextInt(){
    return parseInt(next());
}

function nextFloat(){
    return parseFloat(next());
}

function solve(){
    var n = nextInt();
    var a = {};
    for(var i = 0; i < n; ++i){
        var s = next();
        if(s in a){
            a[s]++;
        } else {
            a[s] = 1;
        }
    }
    var min = 0;
    var winner;
    for(var team in a){
        if(a[team] > min){
            winner = team;
            min = a[team];
        }
    }
    print(winner);
}
solve();

var n = readline();
a = readline();
var res1 = 1;
var res2 = 0;
for(i = 1; i < n; i++){
    s = readline();
    if(a != s){
        b = s;
         res2++;
    }
    else{
        res1++;
    }
}
print((res1 > res2)? a : b);

var n = readline();
teama = readline();
var one = 1;
var two = 0;
	for (var i=1; i<+n; i++){
		temp = readline();
		if (temp!=teama)	{
			teamb = temp;
			two++;
		}
		else one++;
	}
print((one>two)? teama:teamb)

var number = +readline();
var name;
var teamNames = [];
var winner;
var k;
var max = 0;

while (number--) {
	name = readline();
	teamNames.push(name);
}
if (teamNames.length === 1){
    winner = teamNames[0];
}
teamNames.sort();
for (var i = 0; i<teamNames.length; ++i) {
		k = 1;
		for (var j = i + 1; j<teamNames.length; ++j)  {
			if (teamNames[i] === teamNames[j]) {
				++k;
			}
			if (k > max) {
				max = k,
				winner = teamNames[i];
			}
		}
}
print(winner);

var n = parseInt(readline());
var hash = {};
var max = 0;
var winner = "";
for (var i = 0; i < n; i++) {
	var team = readline();
	if (hash[team]) {
		hash[team]++;
	} else {
		hash[team] = 1;
	}
}

for (var key in hash) {
	if (hash.hasOwnProperty(key)) {
		if (hash[key] > max) {
			max = hash[key];
			winner = key;
		}
	}
}

print(winner);

const readline = require('readline');

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

var indicator = 0, cont = new Map(), maxScore = 0, winner = "";

rl.on('line', (input) => {
    if (indicator == 0)
        indicator++;
    else {
        if (cont.has(input))
            cont.set(input, cont.get(input)+1);
        else
            cont.set(input, 1);

        if (maxScore < cont.get(input)) {
            maxScore = cont.get(input);
            winner = input;
        }

    }

  }).on('close',()=> {
      console.log(winner);
    //  console.log(cont);
  });

var nums = parseInt(readline());

var obj = {};

while (nums--){
    var winner = readline();

    if (!(winner in obj)) {
        obj[winner] = 1;
    } else {
        obj[winner]++;
    }
}

var teams = Object.keys(obj);
if (teams.length === 1 || obj[teams[0]] > obj[teams[1]]) {
    print(teams[0])
} else {
    print(teams[1]);
}

var nums = parseInt(readline());

var obj = {};

for (var i = 0; i < nums; i++) {
    var winner = readline();

    if (!(winner in obj)) {
        obj[winner] = 1;
    } else {
        obj[winner]++;
    }
}

var teams = Object.keys(obj);
if (teams.length === 1 || obj[teams[0]] > obj[teams[1]]) {
    print(teams[0])
} else {
    print(teams[1]);
}

//var input = "5\nA\nABA\nABA\nA\nA";
//var index = 0;
//
//function readline(){
//    var data = input.split('\n');
//    if(index < data.length)
//        return data[index++];
//}
//
//function print(output){
//    console.log(output);
//}

function main(){
    var n = readline();
    var commands = {};
    var arr = [];
    for(var i = 0; i < n; i++){
        var str = readline();
        if(arr.indexOf(str) == -1)
            arr.push(str);
        if(!(str in commands))
            commands[str] = 1;
        else
            commands[str]++;
    }
    if(arr.length == 1)
        print(arr[0]);
    else if(commands[arr[0]] > commands[arr[1]])
        print(arr[0]);
    else
        print(arr[1]);
}
main();

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

var n = rdn();

var t1, t2, s1 = 0, s2 = 0;

for(var i = 0; i < n; i++){
    var name = readline();
    if(!t1){
        t1 = name;
        s1++;
    }
    if(!t2){
        t2 = name;
        s2++
    }

    if(name == t1) s1++;
    if(name == t2) s2++;
}

var ans;
if(s1 > s2){
    ans = t1;
}else{
    ans = t2;
}

write(ans);

var n = +readline();
var teams={};
for (var i = 0; i < n; i++) {
	var element = readline();
	if(teams[element]){
		teams[element] +=1;
	} else {
		teams[element]=1;
	}
}
print(
	teams[Object.keys(teams)[0]] > teams[Object.keys(teams)[1]]|| 0
	 ? Object.getOwnPropertyNames(teams)[0]
	 : Object.getOwnPropertyNames(teams)[1]
	 );

;(function () {

	var n = +readline();
	var k1n = '', k1s = 0;
	var k2n = '', k2s = 0;

	while (n--) {
		var s = readline();

		if (k1n === '' && k1n === s) {
			k1n = s;
			k1s++;
		} else {
			k2n = s;
			k2s++;
		}
	}

	print(k1s > k2s ? k1n : k2n);

}).call(this)

var n = Number(readline());
teama = readline();
var one = 0;
var two = 0;
	for (var i=0; i<n; i++){
		temp = readline();
		if (temp!=teama)	{
			var teamb = temp;
			two++;
		}
		else one++;
	}
print((one>two)? teama:teamb)

n = Number(readline());
teama = readline();
teamb="";
one = 0;
two = 0;
res = 0;
	for (var i=0; i<n; i++){
		temp = readline();
		if (temp!=teama)	{
			teamb = temp;
			two++;
		}
		else one++;
	}
print(one>two? teama:teamb)

var n = Number(readline());
teama = readline();
var teamb;
var one = 0;
var two = 0;
	for (var i=0; i<n; i++){
		temp = readline();
		if (temp!=teama)	{
			teamb = temp;
			two++;
		}
		else one++;
	}
print((one>two)? teama:teamb)

var n = Number(readline());
teama = readline();
var one = 1;
var two = 0;
	for (var i=0; i<n; i++){
		temp = readline();
		if (temp!=teama)	{
			var teamb = temp;
			two++;
		}
		else one++;
	}
print((one>two)? teama:teamb)

'use strict';
var football43A = function() {
var number = +readline();
var name;
var teamNames = [];
var winner;
var k;
var max = 0;

while (number--) {
	name = readline();
	teamNames.push(name);
}
teamNames.sort();
for (var i = 0; i<teamNames.length; ++i) {
		k = 1;
		for (var j = i + 1; j<teamNames.length; ++j)  {
			if (teamNames[i] === teamNames[j]) {
				++k;
			}
			if (k > max) {
				max = k,
				winner = teamNames[i];
			}
		}
}
return winner;
}
football43A();

'use strict';
var football43A = function() {
var number = +readline();
var name;
var teamNames = [];
var winner;
var k;
var max = 0;

while (number--) {
	name = readline();
	teamNames.push(name);
}
teamNames.sort();
for (var i = 0; i<teamNames.length; ++i) {
		k = 1;
		for (var j = i + 1; j<teamNames.length; ++j)  {
			if (teamNames[i] === teamNames[j]) {
				++k;
			}
			if (k > max) {
				max = k,
				winner = teamNames[i];
			}
		}
}
print(winner);
}
football43A();

'use strict';
var number = +readline();
var name;
var teamNames = [];
var winner;
var k;
var max = 0;

while (number--) {
	name = readline();
	teamNames.push(name);
}
teamNames.sort();
for (var i = 0; i<teamNames.length; ++i) {
		k = 1;
		for (var j = i + 1; j<teamNames.length; ++j)  {
			if (teamNames[i] === teamNames[j]) {
				++k;
			}
			if (k > max) {
				max = k,
				winner = teamNames[i];
			}
		}
}
print(winner);

var nums = parseInt(readline());

var obj = {};

for (var i = 0; i < nums; i++) {
    var winner = readline();

    if (!(winner in obj)) {
        obj[winner] = 1;
    } else {
        obj[winner]++;
    }
}

var teams = Object.keys(obj);
if (obj[teams[0]] > obj[teams[1]]) {
    print(teams[0])
} else {
    print(teams[1]);
}

//var input = "5\nA\nABA\nABA\nA\nA";
//var index = 0;
//
//function readline(){
//    var data = input.split('\n');
//    if(index < data.length)
//        return data[index++];
//}
//
//function print(output){
//    console.log(output);
//}

function main(){
    var n = readline();
    var commands = {};
    var arr = [];
    for(var i = 0; i < n; i++){
        var str = readline();
        if(arr.indexOf(str) == -1)
            arr.push(str);
        if(!(str in commands))
            commands[str] = 1;
        else
            commands[str]++;
    }
    if(commands[arr[0]] > commands[arr[1]])
        print(arr[0]);
    else
        print(arr[1]);
}
main();


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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var s = nextCharArray();
		var N = s.length;
		var a = 0;
		var b = 0;
		for(var j = 0; j < N; j++){
			if(s[j] == "A"){
				a++;
				continue;
			}
			if(s[j] == "B"){
				b++;
				if(a > 0){
					a--;
					b--;
				}
			}
		}
		output[i] = b % 2 + a;
	}
	myout(myconv(output, 9));
}

var tc = parseInt(readline());
for (; tc--;){
    var str = readline();
    var ar = [];
    for (var i = 0; i < str.length; i++) {
      ar.push(str[i]);
      if (ar.length > 1) {
          var Last = ar[ar.length - 2] + ar[ar.length - 1];

          while (Last === "AB" || Last === "BB") {
          ar.pop(); ar.pop();
          Last = ar[ar.length - 2] + ar[ar.length - 1];
        }
      }
    }
    print(ar.length);
}

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;
    return;
  }

  data.push(line);

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

});

function goToSolution(data) {
  data.forEach(srt => {

    let stack = [];
    for(let i = 0; i < srt.length; i++) {
      stack.push(srt[i]);
      if(stack.length > 1) {
        let stackLast = stack[stack.length - 2] + stack[stack.length - 1];
        while(stackLast === "AB" || stackLast === "BB") {
          stack.pop();
          stack.pop();
          stackLast = stack[stack.length - 2] + stack[stack.length - 1];
        }
      }
    }
    console.log(stack.length)

  })
}

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 str = readLine();
    const stack = [];

    for (let i = 0; i < str.length; i++) {
      const char = str[i];
      if (stack[stack.length - 1] + char === "AB" || stack[stack.length - 1] + char === "BB") {
        stack.pop();
      } else {
        stack.push(char);
      }
    }
    console.log(stack.length);
  }
}

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

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

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

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

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

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

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

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

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

  let t = +$()
  while (t--) {
    let s = $()
    let n = s.length;
    let sa = Arr(n, i => 0)
    let sb = Arr(n, i => 0)
    if (s[0] == 'A') { sa[0] = 1; sb[0] = 1e6 }
    else { sb[0] = 1; sa[0] = 1e6 }
    For(1, n - 1, i => {
      if (s[i] == 'A') {
        sa[i] = sa[i - 1] + 1;
        sb[i] = sb[i - 1] + 1;
      } else {
        // if (s[i-1] == 'B') {
        //   sa[i]
        // }
        sb[i] = sb[i - 1] - 1;
        if (sb[i] < 0) sb[i] = 1;
        sa[i] = sa[i - 1] - 1;
        if (sa[i] < 0) { sa[i] = 1e6; sb[i] = 1; }
      }
    })
    // log(sa)
    // log(sb)
    log(min(sa[n - 1], sb[n - 1]))
  }
}

const input = [];

function splbsi(line) {
  return line.split(" ").map((x) => parseInt(x));
}

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

readLine.on("line", (line) => {
  input.push(line);
});

readLine.on("close", () => {
  for (let i = 1; i < input.length; i += 1) {
    const str = input[i];

    let countA = 0,
      countB = 0;
    let answer = 0;
    for (const char of [...str]) {
      if (char === "A") {
        countA += 1;
      } else if (countA > 0) {
        answer += 1;
        countA -= 1;
      } else {
        countB += 1;
      }
    }

    console.log(countA + (countB % 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 => string.trim());

    main();
});

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

function main() {
    const numCases = readLine();
    for (let i = 0; i < numCases; i++) {
        let input = readLine();
        let toBeRemoved = 0;
        let beginningB = 0;
        let overhangA = 0;
        for (let k = 0; k < input.length; k++) {
            const letter = input[k];
            if (letter === 'A') {
                overhangA++;
            }
            else if (letter === 'B' && overhangA > 0) {
                overhangA--;
                toBeRemoved += 2;
            } else {
                beginningB++;
            }
        }
        console.log(overhangA + (beginningB % 2 === 0 ? 0 : 1));
    }
}

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

    ABBB();
});

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 ABBB(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let s = readline().split('');
        let st = [];
        let i = 0;
        while(i < s.length){
            if(s[i] === 'A'){
                st.push(s[i]);
                i++;
            }else{
                if(st[st.length-1] === 'A'){
                    st.pop();
                    i++;
                }else{
                    st.push(s[i]);
                    i++;
                }
            }
        }

        let countA = 0;
        let countB = 0;
        if(st.length > 0){
            while(st.length > 0){
                if(st.pop() === 'A')
                    countA++;
                else
                    countB++;
            }
        }
        console.log(countA + countB % 2);
    }
}

const input = [];

function splbsi(line) {
  return line.split(" ").map((x) => parseInt(x));
}

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

readLine.on("line", (line) => {
  input.push(line);
});

readLine.on("close", () => {
  for (let i = 1; i < input.length; i += 1) {
    const str = input[i];

    // AABBBABBBB
    const stack = [];
    let answer = 0,
      countB = 0;
    let countA = [...str].reduce((count, char) => {
      if (char === "A") count += 1;
      return count;
    }, 0);
    for (const char of [...str]) {
      if (char === "A") {
        stack.push("A");
        countB = 0;
      } else {

        if (stack.length > 0) {
          stack.pop();
          answer += 2;
          countA -= 1;
        } else {
          countB += 1;

          if (countB % 2 === 0) {
            answer += 2;
            countB -= 2;
          }
        }
      }
    }

    if (countA === 0) {
      const res = str.length - answer;
      console.log(res % 2);
    } else console.log(str.length - answer);
  }
});


'use strict';
/*
let input = `
5
1 1 5 1 1
`.trim().split('\n');
function readline() {
	return input.shift();
}
function print(message) {
	console.log(message);
}*/

//code
var n = Number(readline());
var inputArr = readline().split(' ').map(Number);
var modifiedSum = 0;
for (var i = 0; i < n; i++) {
	modifiedSum += inputArr[i] - 1;
	print((modifiedSum%2 === 0) ? 2 : 1);
}

/*
    The idea to solve this problem is basically we count the needed movement
    to complete the game in each test. Complete means no players can move anymore.

    Since peter move initially, so in order to win, the movement needed to complete
    the game must be odd.
*/

var n = parseInt(readline());
var cycles = readline().split(' ').map(Number);
var move = 0;

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

    move += cycles[i] - 1; // the movement needed to reduce cycle value into 1, note that the rule to breakdown is 1 <= p < x, so the movement needed will always follow this pattern (for any x value)
    if(move % 2)
        print(1);
    else
        print(2);
}

var n = readline();
var arr = readline().split(' ').map(Number);

var cycle = 0;
 for(var i = 0; i < n; i++){
  cycle += arr[i] - 1;
  if( cycle %2 == 0 ) {

    print(2);
  } else {

    print(1);
  }
 }

/*
    The idea to solve this problem is basically we count the needed movement
    to complete the game in each test. Complete means no players can move anymore.

    Since peter move initially, so in order to win, the movement needed to complete
    the game must be even.
*/

var n = parseInt(readline());
var cycles = readline().split(' ').map(Number);
var move = 0;

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

    move += cycles[i] - 1; // the movement needed to reduce cycle value into 1, note that the rule to breakdown is 1 <= p < x, so the movement needed will always follow this pattern (for any x value)
    if(move % 2)
        print(1);
    else
        print(2);
}


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 n = rn();
		const p = rna();

		const ansl = [], ansr = [];

		for (let i = 0, cur = 1e6; i < n; i++) {
			if (p[i] < cur) {
				ansl.push(p[i]);
				cur = p[i];
			} else {
				ansr.push(p[i]);
			}
		}

		console.log(ansl.reverse().join(' '), ansr.join(' '));
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        let n = Number(readline()), p = readline().split(" ");
        let ans = p[0], head = ans;
        p = p.slice(1);

        for(const num of p) {
            if(parseInt(num) < parseInt(head)) {
                ans = num + " " + ans;
                head = num;
            }else {
                ans += " " + num;
            }
        }
        console.log(ans);
    }
}

"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++];
}
class node {
  constructor(val) {
    this.val = val;
    this.next = null;
  }
}
class dequeue {
  constructor() {
    this.head = null;
    this.tail = null;
  }
  front(val) {
    if (!this.head) return (this.head = this.tail = new node(val));
    let newNode = new node(val);
    newNode.next = this.head;
    return (this.head = newNode);
  }
  back(val) {
    if (!this.tail) return (this.head = this.tail = new node(val));
    let newNode = new node(val);
    this.tail.next = newNode;
    return (this.tail = newNode);
  }
  print() {
    let res = "",
      p = this.head;
    while (p) {
      res += p.val + " ";
      p = p.next;
    }
    console.log(res);
  }
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    if (arr[0] === 1) console.log(arr.join(" "));
    else {
      let res = new dequeue(),
        min = arr[0];
      for (let i = 0; i < n; i++) {
        if (min > arr[i]) {
          res.front(arr[i]);
          min = arr[i];
        } else res.back(arr[i]);
      }
      res.print();
    }
  }
};
solve();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

class LinkedList {
    constructor(value) {
      this.head = {
        value: value,
        next: null
      };
      this.tail = this.head;
      this.length = 1;
    }
    append(value) {
      const newNode = {
        value: value,
        next: null
      }
      if(!this.head.value) {
          this.head.value = value;
          return;
      }
      this.tail.next = newNode;
      this.tail = newNode;
      this.length++;
      return this;
    }
    prepend(value) {
      const newNode = {
        value: value,
        next: null
      }
      if(!this.head.value) {
        this.head.value = value;
        return;
      }
      newNode.next = this.head;
      this.head = newNode;
      this.length++;
      return this;
    }
    printList() {
      const array = [];
      let currentNode = this.head;
      while(currentNode !== null){
          array.push(currentNode.value)
          currentNode = currentNode.next
      }
      return array;
    }
  }

function main() {
   const t = parseInt(readline());
   for (let i = 0; i < t; i++){
        const n = parseInt(readline());
        const list = new LinkedList();
        readline().split(' ').map((str) => {
            const item = parseInt(str);
            if(!list.head || item <= list.head.value){
                list.prepend(item);
            }else{
                list.append(item);
            }
        });
        console.log(list.printList().join(' '))
   }

}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline()), p = readline().split(" ");
        let str = p.shift(), ans = str;

        for(const num of p) {
            if(num + str[0] < str.slice(0, num.length + 1)) {
                str = num + str
                ans = num + " " + ans;
            }else {
                str += num;
                ans += " " + num;
            }
        }
        console.log(ans);
        }
    }

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline()), p = readline().split(" ");
        let head = p[0];
        for(let i = 1; i < n; i++) {
            if(p[i] < head) {
                head = p[i];
                p.splice(i, 1);
                p.unshift(head);
            }
        }
        console.log(p.join(" "));
        }
    }

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline()), p = readline().split(" ");
        let str = p.shift();
        for(const num of p) {
            if(num < str[0]) str = num + str;
            else str += num;
        }
        console.log(str);
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline());
        let p = readline().split(" "), min = Number(p.join("")), myArrs = [[p.shift()]];
        for(const num of p) {
            const myNewArrs = [];
            for(const arr of myArrs) {
                if(arr.length == n) {
                    let str = arr.join("");
                    min = Math.min(Number(str + num), Number(num + str), min);
                }
                myNewArrs.push(arr.concat([num]));
                myNewArrs.push([num].concat(arr));
            }
            myArrs = myNewArrs;
        }
        console.log(String(min).split("").join(" "));
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline());
        let p = readline().split(" "), min = Number(p.join("")), myArrs = [p.shift()];
        for(const num of p) {
            const myNewArrs = [];
            for(const arr of myArrs) {
                if(arr.length == n) {
                    let str = arr.join("");
                    min = Math.min(Number(str + num), Number(num + str), min);
                }
                myNewArrs.push(arr.concat([num]));
                myNewArrs.push([num].concat(arr));
            }
            myArrs = myNewArrs;
        }
        console.log(String(min).split("").join(" "));
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = Number(readline());
    for(let i = 0; i < t; i++) {
        const n = Number(readline()), p = readline().split(" "), arr = [p[0]];
        let min = Number(p.join(""));
        function permutations(p, index, arr, n) {
            for(let option = 0; option < 2; option++) {
                if(index == n) {
                    min = Math.min(min, Number(arr.join("")));
                    return;
                }
                if(option == 0) {
                    permutations(p, index + 1, [p[index]].concat(arr), n);
                }
                if(option == 1) {
                    permutations(p, index + 1, arr.concat([p[index]]), n);
                }
            }
            return
        }
        permutations(p, 1, arr, n);
        console.log(min);

    }
}

"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++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let min = Infinity,
      ind = 0;
    for (let i = 1; i < n; i++) {
      if (arr[i] < min) {
        ind = i;
        min = arr[i];
      }
    }
    if (arr[0] > min) {
      let res = [];
      res.push(arr[ind]);
      for (let i = 0; i < n; i++) {
        if (ind !== i) res.push(arr[i]);
      }
      console.log(res.join(" "));
    } else console.log(arr.join(" "));
  }
};
solve();

"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++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let min = Infinity,
      ind = 0;
    for (let i = 1; i < n; i++) {
      if (arr[i] < min) {
        ind = i;
        min = arr[i];
      }
    }
    if (arr[0] > min) {
      [arr[0], arr[ind]] = [arr[ind], arr[0]];
    }
    console.log(arr.join(" "));
  }
};
solve();

"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++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    for (let i = 0; i < n - 1; i++) {
      if (arr[0] > arr[i + 1]) {
        let k = i + 1,
          j = i + 1;
        while (j < n) {
          if (arr[k] > arr[j]) k = j;
          j++;
        }
        [arr[i], arr[k]] = [arr[k], arr[i]];
        break;
      }
    }
    console.log(arr.join(" "));
  }
};
solve();

"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++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    for (let i = 0; i < n - 1; i++) {
      if (arr[i] > arr[i + 1]) {
        let k = i + 1,
          j = i + 1;
        while (j < n) {
          if (arr[k] > arr[j]) k = j;
          j++;
        }
        [arr[i], arr[k]] = [arr[k], arr[i]];
        break;
      }
    }
    console.log(arr.join(" "));
  }
};
solve();


//NYTransport.js
"use strict"
const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin
});
var count=0,
    arr=[],
    arr2=[],
    x,y,i;
rl.question('', (nb) => {
  rl.on('line', (TC) => {
    arr = nb.split(' ');
    arr2 = TC.split(' ');
    y = Number(arr[1]); //dest
    i=0;
    while(i<y){
      i = i+Number(arr2[i]);
      if(i === y-1){
        console.log("YES");
        rl.close();
        break;
      }else if(i > y-1){
        console.log("NO");
        rl.close();
        break;
      }
    }
  });
});

var input = readline().split(" ").map((x) => parseInt(x));
var location = readline().split(" ").map((x) => parseInt(x));
var position = input[1];
var counter = 1;
var found = false;

if(position > location.length) {
    print("YES");
} else {
    while(counter < location.length) {
        counter = counter + location[counter - 1];

        if(counter === position) {
            print("YES");
            found = true;
            break;
        }
    }

    if(!found) {
        print("NO");
    }
}

(function() {
    var values = readline().split(" ").map(Number);
    var n = values[0] - 1;
    var k = values[1];
    var arr = readline().split(" ").map(Number);
    var save = 1;

    for (var i = 1; i <= arr.length && save <= n; i++) {
        save = arr[save - 1] + save;
        if (save === k) {
            print("YES");
            return;
        }
    }

    print("NO");
})();

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = false;
var i = 0;
while (i<t) {
    i = a[i] + i;
    if (i + 1 === t) {
        canWe = true;
        break;
    }
}
print(canWe ? "YES" : "NO");

function main() {
    let n = parseInt(read()),
        t = parseInt(read());

    let arr = [];
    for (let i = 0; i < n - 1; i++) {
        let x = parseInt(read());
        arr.push(x);
    }

    let p = 0;
    while (p < t - 1) {
        p += arr[p];
    }
    if (p === t - 1) {
        writeline("YES");
    } else {
        writeline("NO");
    }

    return 0;
}

var input = "";
var read;
var writeline = (x) => process.stdout.write(x + "\n");
var write = (x) => process.stdout.write(x);

process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", (chunk) => input += chunk);
process.stdin.on("end", () => {
    input = input.split(/\s+/);
    read = () => input.shift();
    process.exit(main() || 0);
});

var input1 = readline().split(" "), input2 = readline().split(" ");
var n = +input1[0], t = +input1[1] - 1, cells = [];
for(i = 0; i < n-1; i++){
	cells.push(i + +input2[i]);
}
cells.push(0);

if(cells.indexOf(t) + 1){
	for(i = 0; ; ){
		i = cells[i];
		if(i == t){
			write("YES");
			break;
		}
		else if( i > t){
			write("NO");
			break;
		}
	}
}
else{
	write("NO");
}

nt = readline().split(' ').map(Number); n=nt[0]; t=nt[1]; x=1;
a = readline().split(' ').map(Number);
while(x<t) { x += a[x-1] }
write(x === t ? 'YES' : 'NO');

function readNumbersArray () {
	return readline().split(' ').map(Number);
}

var array = readNumbersArray(),
	size = array[0],
	target = array[1],
	a = readNumbersArray(),
	position = 1;

while (position < target && position < size) {
	position += a[position - 1];
}

print(position === target ? 'YES' : 'NO');

var s = readline().split(" ");
var n = Number(s[0]), t = Number(s[1])-1;
s = readline().split(" ");
var i = 0;
var weCan = false;
while(i<n) {
    if (i == t) {
        weCan = true;
        break;
    }
    i+=Number(s[i]);
}
if (weCan) {
    print('YES');
}
else {
    print('NO');
}

var line = readline().split(' '), n = +line[0], t = +line[1];
var arr = readline().split(' ');
var str, b = false, res, next = 1, now = 0;

while(next < n) {
    next = next + (+arr[next - 1]);
    if (next == t) {
        b = true;
        break;
    }
}

if (b)
    print("YES");
else
    print("NO");

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

(function() {
  let array_1 = readline().getNumArray(),
    n = array_1[0],
    t = array_1[1],
    array_2 = readline().getNumArray();

  for (let i = 1; i <= t; i+=array_2[i - 1]) {
    if (i === t) {
      write('YES');
      return;
    }
  }
write('NO');
})();

// 500A - New Year Transportation
// http://codeforces.com/problemset/problem/500/A

process.stdin.resume();
process.stdin.setEncoding("utf8");

// var getline;
var input = "";
var read;
var writeline = (x) => process.stdout.write(x + "\n");
var write = (x) => process.stdout.write(x);

process.stdin.on("data", (chunk) => input += chunk);
process.stdin.on("end", () => {
    // input = input.split(/\r?\n/);
    // getline = () => input.shift();
    input = input.split(/\s+/);
    read = () => input.shift();
    process.exit(main() || 0);
});

function main() {
    let n = parseInt(read()),
        t = parseInt(read());

    let arr = [];
    for (let i = 0; i < n - 1; i++) {
        let x = parseInt(read());
        arr.push(x);
    }

    let p = 0;
    while (p < t - 1) {
        p += arr[p];
    }
    if (p === t - 1) {
        writeline("YES");
    } else {
        writeline("NO");
    }

    return 0;
}

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const [n, t] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  let now = 1; if (t === now) { console.log('YES'); return; }
  for (let i = 0; i < nums.length;) {
    now = nums[i] + (i+1);
    if (t === now) {
      console.log('YES'); return;
    }
    i += nums[i];
  }

  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++];
}

function main() {
	let [n, t] = readLine()
		.split(' ')
		.map(x => parseInt(x));

	const a = readLine()
		.split(' ')
		.map(x => parseInt(x));

	const graphHash = {};

	for (let i = 1; i <= n - 1; ++i) {
		graphHash[i] = i + a[i - 1];
	}

	const stack = [1];
	let found = false;

	while (stack.length > 0) {
		let u = stack.pop();

		if (graphHash[u] !== undefined) {
			if (graphHash[u] == t) {
				found = true;
				break;
			} else {
				stack.push(graphHash[u]);
			}
		}
	}

	found ? console.log('YES') : console.log('NO');
}

let fs=require("fs");
let txt=fs.readFileSync(0,"utf-8").split(/[\r\n]/).filter(data=>data.length);
for (let i = 0; i < txt.length; i+=2) {
    let info=txt[i].split(" ")[1]*1;
    doit(info,txt[i+1].split(" ").filter(data=>data.length>0).map(data=>data*1));

}

function doit(target,arr){
    let current=1;
    while (true) {
        if(current-1>=arr.length){
            console.log("NO");
            return;
        }
        current=current+arr[current-1];
        if(current==target){
            console.log("YES");
            return;
        }else if(current>target){
            console.log("NO");
            return;
        }
    }

}

var numbers = readline().split(" ").map(function(x) { return parseInt(x); });

n = numbers[0];
t = numbers[1] - 1;

var numbers = readline().split(" ").map(function(x) { return parseInt(x); });

ans = "NO"
cur = 0
while(cur < t){
    cur += numbers[cur]
    if(cur == t){
        ans = "YES"
    }
}

print(ans)

var s = readline().split(" ");
var str =  readline().split(" ");
var f = 1;
		for (var i=0; i<+s[0]; i++){
			if (f==+s[1]){
				f = 1;
				break;}
				f+=+str[f-1]
		}
f==1? print("YES"):print("NO");

var p = readline().split(" ").map(function(x) { return parseInt(x); })[1] - 1;
var ar = readline().split(" ").map(function(x) { return parseInt(x); });
var pos = 0, found;
while(true){
  if (pos == p) {
    found = 'YES';
    break;
  } else if (pos > p){
    found = 'NO';
    break;
  }
  pos = pos + ar[pos];
}
print (found);

// var n = 4;
// var t = 4;

// var world = [2, 2, 1];

var nt = readline().split(' ');
var n = Number(nt[0]);
var t = Number(nt[1]);

var world = readline().split(' ').map(Number);
var res = 'NO';
var i = 0;

while (i <= n - 1) {
	var portal = i + 1;

	if (i + 1 == t) {
		res = 'YES';
	}

	i = portal + world[i] - 1;
}

//console.log(res);
print(res);

var params = readline().split(" ").map(value => +value);
var n = params[0], t = params[1];
var portals = readline().split(" ").map(value => +value);

var i = 0, flag = false;
while(i < n - 1) {
	if (portals[i] + i + 1 === t) {
		flag = true;
		break;
	}

	i += portals[i];
}

print(flag ? "YES" : "NO");

function sa(n,t,data){

        var current = 1;
        while(current <= t){
            if(current == t){
                return "YES";
            }
            current = current + data[current -1];
        }

        return "NO"
    }

    var f = readline().split(" ").map(Number);
    var n = f[0];
    var t = f[1];
    var data = readline().split(" ").map(Number);

    print(sa(n,t,data));

var input = readline().split(' ').map(value => +value);
var n = input[0];
var t = input[1];
var a = readline().split(' ').map(value => +value);

var p = 1;

while (p < t) {
    p += a[p - 1];
}

write(p === t ? 'YES' : 'NO');

(function() {
    var input = readline().split(' ');
    var n = parseInt(input[0]);
    var t = parseInt(input[1]);
    var e = readline().split(' ');
    var cur = 1;
    while (cur < n) {
        if (cur == t) {
            break;
        }
        cur = cur + parseInt(e[cur - 1]);
    }
    if (cur == t) {
        write('YES');
    } else {
        write('NO');
    }
})()

var input = readline().split(' ').map(Number), n = input[0], t = input[1];
var a = readline().split(' ').map(Number);
var queue = [];
var flag = false;
queue.push(0);
while (queue.length) {
    var pos = queue.pop();
    if (a[pos] + pos + 1 == t) { write('YES'); flag = true; break; }
    else if (a[pos] > 0) queue.push(a[pos] + pos);
    a[pos] = -1;
}
if (!flag) write('NO');

function main()    {
    var cellCount, movedToIndex = readline().split(/\s/gi).map(Number);
    cellCount = movedToIndex[0], movedToIndex = movedToIndex[1];

    var lineList = [0].concat(readline().split(/\s/gi)),
        cellList = [], index = 1,
        result = 'YES';

    while(true)    {
        if(index == movedToIndex)    break;
        if(index > movedToIndex)    {
            result = 'NO';
            break;
        }
        var fromCell = index,
            toCell = fromCell + parseInt(lineList[fromCell]);

        index = toCell;
    };

    print(result);
};
main();

function main() {
	var n, t;
	var line = readline().split(" ").map(Number);
	n = line[0]; t = line[1] - 1;
	var value = readline().split(" ").map(Number);
	value.push(0);

	var cur = 0;
	while (cur != t && value[cur] !== 0) {
		cur += value[cur];
	}

	if (cur == t)
		print("YES");
	else
		print("NO");
}

main();

var r = readline().split(' ');
var n = +r[0];
var t = +r[1];
var a = readline().split(' ');
var result = 'NO';
for (var i = 1; i <= t; ) {
    if (i == t) {
        result = 'YES';
        break;
    } else {
        i += +a[i - 1];
    }
}
print(result);

// 500A - New Year Transportation
// http://codeforces.com/problemset/problem/500/A

process.stdin.resume();
process.stdin.setEncoding("utf8");

// var getline;
var input = "";
var read;
var writeline = (x) => process.stdout.write(x + "\n");
var write = (x) => process.stdout.write(x);

process.stdin.on("data", (chunk) => input += chunk);
process.stdin.on("end", () => {
    // input = input.split(/\r?\n/);
    // getline = () => input.shift();
    input = input.split(/\s+/);
    read = () => input.shift();
    process.exit(main() || 0);
});

function main() {
    let n = parseInt(read()),
        t = parseInt(read());

    let arr = [];
    for (let i = 0; i < n - 1; i++) {
        let x = parseInt(read());
        arr.push(x);
    }

    let vis = new Array(n).fill(0);
    vis[0] = 1;
    for (let i = 0; i < n - 1; i++) {
        let j = i + arr[i];
        vis[j] = 1;
    }

    // dfs(0, vis);
    if (vis[t - 1] === 1) {
        writeline("YES");
    } else {
        writeline("NO");
    }

    return 0;
}

// 500A - New Year Transportation
// http://codeforces.com/problemset/problem/500/A

process.stdin.resume();
process.stdin.setEncoding("utf8");

// var getline;
var input = "";
var read;
var writeline = (x) => process.stdout.write(x + "\n");
var write = (x) => process.stdout.write(x);

process.stdin.on("data", (chunk) => input += chunk);
process.stdin.on("end", () => {
    // input = input.split(/\r?\n/);
    // getline = () => input.shift();
    input = input.split(/\s+/);
    read = () => input.shift();
    process.exit(main() || 0);
});

function main() {
    let n = parseInt(read()),
        t = parseInt(read());

    let arr = [];
    for (let i = 0; i < n - 1; i++) {
        let x = parseInt(read());
        arr.push(x);
    }

    let vis = new Array(n).fill(0);
    vis[0] = 1;
    for (let i = 0; i < n - 1; i++) {
        let j = i + arr[i];
        vis[j] = 1;
    }

    // dfs(0, vis);
    if (vis[t - 1]) {
        writeline("YES");
    } else {
        writeline("NO");
    }

    return 0;
}

// 500A - New Year Transportation
// http://codeforces.com/problemset/problem/500/A

process.stdin.resume();
process.stdin.setEncoding("utf8");

// var getline;
var input = "";
var read;
var writeline = (x) => process.stdout.write(x + "\n");
var write = (x) => process.stdout.write(x);

process.stdin.on("data", (chunk) => input += chunk);
process.stdin.on("end", () => {
    // input = input.split(/\r?\n/);
    // getline = () => input.shift();
    input = input.split(/\s+/);
    read = () => input.shift();
    process.exit(main() || 0);
});

function main() {
    let n = parseInt(read()),
        t = parseInt(read());

    let g = [...Array(n)].map(x => Array().fill([]));
    let arr = [];
    for (let i = 0; i < n - 1; i++) {
        let x = parseInt(read());
        arr.push(x);
        g[i].push(i + x);
    }

    function dfs(s, vis) {
        vis[s] = 1;
        for (const v of g[s]) {
            if (!vis[v]) {
                dfs(v, vis);
            }
        }
    }

    let vis = new Array(n).fill(0);
    vis[0] = 1;
    for (let i = 0; i < n-1; i++) {
        let j = i + arr[i];
        vis[j] = 1;
    }

    // dfs(0, vis);
    if (vis[t - 1]) {
        writeline("YES");
    } else {
        writeline("NO");
    }

    return 0;
}

//NYTransport.js
"use strict"
const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin
});
var count=0,
    arr=[],
    arr2=[],
    x,y,i;
rl.question('', (nb) => {
  rl.on('line', (TC) => {
    arr = nb.split(' ');
    arr2 = TC.split(' ');
    y = Number(arr[1]); //dest
    for(i = 0; i < y; i++){
      i = i+Number(arr2[i]);
      if(i+1 === y){
        console.log("YES");
        rl.close();
        break;
      }else if(i+1 > y){
        console.log("NO");
        rl.close();
        break;
      }
    }
  });
});

//NYTransport.js
"use strict"
const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin
});
var count=0,
    arr=[],
    arr2=[],
    x,y,i;
rl.question('', (nb) => {
  rl.on('line', (TC) => {
    arr = nb.split(' ');
    arr2 = TC.split(' ');
    y = Number(arr[1]); //dest
    for(i = 0; i < y; i++){
      i = i+Number(arr2[i]);
      if(i === y-1){
        console.log("YES");
        rl.close();
        break;
      }else if(i > y-1){
        console.log("NO");
        rl.close();
        break;
      }
    }
  });
});

//NYTransport.js
"use strict"
const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin
});
var count=0,
    arr=[],
    arr2=[],
    x,y,i;
rl.question('', (nb) => {
  rl.on('line', (TC) => {
    arr = nb.split(' ');
    arr2 = TC.split(' ');
    y = Number(arr[1]); //dest
    for(i = 0; i < y; i++){
      i = i+Number(arr2[i]);
      console.log(i)
      if(i+1 === y){
        console.log("YES");
        rl.close();
        break;
      }else if(i+1 > y){
        console.log("NO");
        rl.close();
        break;
      }
    }
  });
});

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const [n, t] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  let now = 1; if (t === now) { console.log('YES'); return; }
  for (let i = 0; i < nums.length; i += 1) {
    now += nums[i] + (i+1);
    if (t === now) {
      console.log('YES'); return;
    }
  }

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

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

const input = [];
readLine.on('line', line => input.push(line));

readLine.on('close', () => {
  const [n, t] = input[0].split(' ').map(x => parseInt(x));
  const nums = input[1].split(' ').map(x => parseInt(x));

  let now = 1; if (t === now) { console.log('YES'); return; }
  for (let i = 0; i < nums.length; i += 1) {
    now = nums[i] + (i+1);
    if (t === now) {
      console.log('YES'); return;
    }
  }

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

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

(function() {
  let array_1 = readline().getNumArray(),
    n = array_1[0],
    t = array_1[1] - 1,
    array_2 = readline().getNumArray();

  for (let i = 0; i <= t; i++) {
    const a = array_2[i] ;
    if (a + i === t) {
      write('Yes');
      return;
    }
  }
write('No');
})();

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

(function() {
  let array_1 = readline().getNumArray(),
    n = array_1[0],
    t = array_1[1],
    array_2 = readline().getNumArray();

  for (let i = 0; i < t - 1; i++) {
    const a = array_2[i] ;
    if (a + 1 === array_2[t - 1]) {
      write('Yes');
      return;
    }
  }
write('No');
})();

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

(function() {
  let array_1 = readline().getNumArray(),
    n = array_1[0],
    t = array_1[1] - 1,
    array_2 = readline().getNumArray(),
    nextHome = 0;

  for (let i = 0; i <= t; i++) {
    const a = array_2[i] ;
    nextHome = a + i;
    if (nextHome === t) {
      write('Yes');
      return;
    }
  }
write('No');
})();

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

(function() {
  let array_1 = readline().getNumArray(),
    n = array_1[0],
    t = array_1[1],
    array_2 = readline().getNumArray();

  for (let i = 1; i <= t; i+=array_2[i - 1] + i) {
    if (i === t) {
      write('Yes');
      return;
    }
  }
write('No');
})();

'use strict'
String.prototype.getNumArray = function () {
  return String(this).split(' ').map(function (value) {
    return parseInt(value);
  });
};

(function() {
  let array_1 = readline().getNumArray(),
    n = array_1[0],
    t = array_1[1],
    array_2 = readline().getNumArray();

  for (let i = 0; i < t - 1; i++) {
    const a = array_2[i] ;
    if (a + i === t - 1) {
      write('Yes');
      return;
    }
  }
write('No');
})();

var s = readline().split(" ");//readline();
var str = readline().split(" ");
var res = 0;
var f = 0;
		for (var i=0; i<+s[0]-1; i++){
			if (+str[i]+i+1==+s[1]){
				f = 1;
				break;}
		}
f==1? print("YES"):print("NO");

var s = readline().split(" ");//readline().split(" ");//readline();
var str =  readline().split(" ");
var f = 1;
		for (var i=0; i<+s[0]-1; i++){

			if (f==+s[1]){
				f = 1;
				break;}
					f+=+str[f-1]
		}
f==1? print("YES"):print("NO");

// var n = 8;
// var t = 8;

// var world = [1, 2, 1, 2, 1, 1, 1];

var nt = readline().split(' ');
var n = Number(nt[0]);
var t = Number(nt[1]);

var world = readline().split(' ').map(Number);
var res = 'NO';
var i = 0;

while (i < n - 1) {
	var portal = i + 1;

	if (i + 1 == t) {
		res = 'YES';
	}

	i = portal + world[i] - 1;
}

// console.log(res);
print(res);

var t = readline().split(" ").map(value => +value)[1];
print(
	(readline().split(" ").map((value, index) => +value + index + 1).indexOf(t) === -1) ?
	"NO" : "YES");

var t = readline().split(" ").map(value => +value)[1];
print((readline().split(" ").some((value, index) => +value + index + 1 === t)) ? "YES" : "NO");

var input = readline().split(" ").map((x) => parseInt(x));
var location = readline().split(" ").map((x) => parseInt(x));
var position = input[1];
var counter = 1;
var found = false;

while(counter < location.length) {
    if(counter === position) {
        print("YES");
        found = true;
        break;
    } else {
        counter = counter + location[counter - 1];
    }
}

if(!found) {
    print("NO");
}

var input = readline().split(" ").map((x) => parseInt(x));
var location = readline().split(" ").map((x) => parseInt(x));
var position = input[1];
var counter = 1;
var found = false;

while(counter < location.length) {
    counter = counter + location[counter - 1];

    if(counter === position) {
        print("YES");
        found = true;
        break;
    }
}

if(!found) {
    print("NO");
}

(function() {
    var values = readline().split(" ").map(Number);
    var n = values[0] - 1;
    var k = values[1];
    var arr = readline().split(" ").map(Number);
    var save = 1;

    for (var i = 1; i < arr.length && save <= n; i++) {
        save = arr[save - 1] + save;
        if (save === k) {
            print("YES");
            return;
        }
    }

    print("NO");
})();

(function() {
    var values = readline().split(" ").map(Number);
    var n = values[0] - 1;
    var k = values[1];
    var arr = readline().split(" ").map(Number);
    var save = 1;

    for (var i = 1; i < arr.length && save < n; i++) {
        save = arr[save - 1] + save;
        if (save === k) {
            print("YES");
            return;
        }
    }

    print("NO");
})();

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = true;
for (var i=1; i<t; i++) {
    i = a[i] + i;
    if (a[i] + i > t) {
        canWe = false;
        break;
    }
}
print(canWe ? "YES" : "NO");

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = false;
var i = 0;
while (i<t) {
    i = a[i] + i + 1;
    if (i === t) {
        canWe = true;
        break;
    }
}
print(canWe ? "YES" : "NO");

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = true;
for (var i=0; i<t; i++) {
        if (a[i] + i + 1 > t) {
        canWe = false;
        break;
    }
    i = a[i] + i;
    if (i === t) {
        canWe = true;
        break;
    }
}
print(canWe ? "YES" : "NO");

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = true;
for (var i=0; i<t; i++) {
        if (a[i] + i + 1 > t) {
        canWe = false;
        break;
    }
    i = a[i] + i;
}
print(canWe ? "YES" : "NO");

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = true;
for (var i=0; i<=t; i++) {
    i = a[i] + i;
    if (a[i] + i > t) {
        canWe = false;
        break;
    }
}
print(canWe ? "NO" : "YES");

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = true;
for (var i=0; i<=t; i++) {
    i = a[i] + i;
    if (a[i] + i > t) {
        canWe = false;
        break;
    }
}
print(canWe ? "YES" : "NO");

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = true;
for (var i=1; i<t; i++) {
        if (a[i] + i > t) {
        canWe = false;
        break;
    }
    i = a[i] + i;
}
print(canWe ? "YES" : "NO");

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = true;
var i = 0;
while (i<t) {
        if (a[i] + i + 1 > t) {
        canWe = false;
        break;
    }
    i = a[i] + i + 1;
    if (i === t) {
        canWe = true;
        break;
    }
}
print(canWe ? "YES" : "NO");

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = true;
var i = 0;
while (i<t) {
        if (a[i] + i + 1 > t) {
        canWe = false;
        break;
    }
    i = a[i] + i;
    if (i === t) {
        canWe = true;
        break;
    }
}
print(canWe ? "YES" : "NO");

const data = readline().split(" ").map(x => parseInt(x));
const a = readline().split(" ").map(x => parseInt(x));
const n = data[0];
const t = data[1];
var canWe = true;
for (var i=0; i<t; i++) {
        if (a[i] + i + 1 > t) {
        canWe = false;
        break;
    }
    i = a[i] + i + 1;
}
print(canWe ? "YES" : "NO");


var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();

    var k;
    if(len % 2 === 0) {
        k = len / 2;
    }else {
        k = (len - 1) / 2;
    }

    var char = str[k];
    while(str[k] == char && k > -1){
        count++;
        k--;
    }

    if(len % 2 === 0) {
        k = len / 2;
    }else {
        k = (len - 1) / 2;
    }

    while(str[k + 1] == char && k < len){
        count++;
        k++;
    }
    print(count);
}

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

let currentLine = 0;
let inputString = "";

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

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

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

function solve() {
  const n = readLine();
  const string = readLine();
  let isFoundAnswer = false;

  if (n % 2 === 0) {
    for (let x = n / 2 - 1; x >= 0; x--) {
      if (string[x] != string[x - 1]) {
        console.log((n / 2 - x) * 2);
        isFoundAnswer = true;
        break;
      }
    }
  } else {
    for (let x = Math.floor(n / 2); x >= 0; x--) {
      if (string[x] != string[x - 1]) {
        console.log((n / 2 - x) * 2);
        isFoundAnswer = true;
        break;
      }
    }
  }

  if (isFoundAnswer === false) {
    console.log(n);
  }
}

function main() {
  let T = readLine();
  while (T--) {
    solve();
  }
}

T = readline()
while (T--) {
   n = +readline()
   a = readline().split('')

   repeat = 0
   half = 0
   half = Math.floor(n/2)

   for(i = half; i< n-1; i++){
      if(a[i] ===a[i+1])
         repeat++
      else
         break
   }

   if(n%2 != 0)
      ans = 1 + 2*repeat
   else
      ans = 2 * (1+ repeat)
   print( ans)
}

'use strict';

var readline = require('readline');

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

var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);

function solve(n, s) {
  let res = 1,
      t = Math.floor((n - 1) / 2);
  for (let i = t + 1; i < n; i++) {
    if (s[i] === s[t]) res++;else break;
  }
  for (let i = t - 1; i >= 0; i--) {
    if (s[i] === s[t]) res++;else break;
  }
  return res;
}

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

const rl = readline__default["default"].createInterface({
  input: process.stdin,
  output: process.stdout
});
void async function () {
  const inputs = [];
  let i = 0;
  for await (const line of rl) {
    inputs.push(line.trim());
  }
  function read() {
    return inputs[i++];
  }
  await main(read);
}();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

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

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

    const isPalindrome = str => str === str.split('').reverse().join('');

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let s = readline();

        let mid = Math.floor(n / 2);
        if (!isPalindrome(s.substring(0, mid) + s.substring(mid + 1))) {
            output(0);
        }
        let m = s[mid];
        let left = mid - 1;
        let right = mid + 1;

        let total = 1;

        const isOk = index => index >=0 && index < n && s[index] === m;

        while (isOk(left)) {
            left--;
            total++;
        }

        while (isOk(right)) {
            right++;
            total++;
        }

        output(total);
    }
}

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

let currentLine = 0;
let inputString = "";

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

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

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

function solve() {
  const n = readLine();
  const string = readLine();
  let isFoundAnswer = false;

  if (n % 2 === 0) {
    for (let x = 1; x < n; x++) {
      if (string[x] !== string[x - 1]) {
        console.log(n / 2 - x + 1);
        isFoundAnswer = true;
        break;
      }
    }
    if (!isFoundAnswer) {
      console.log(n);
    }
  } else {
    for (let x = 1; x < n; x++) {
      if (string[x] !== string[x - 1]) {
        console.log(Math.round(n - x) - 1);
        isFoundAnswer = true;
        break;
      }
    }
    if (!isFoundAnswer) {
      console.log(n);
    }
  }
}

function main() {
  let T = readLine();
  while (T--) {
    solve();
  }
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();

    var k = Math.round(len / 2);
    var char = str[k];
    while(str[k] == char || k > -1){
        count++;
        k--;
    }
    k = Math.round(len / 2) + 1;
    while(str[k] == char || k < len){
        count++;
        k++;
    }
    print(count);
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();

    var k = Math.floor(len / 2);
    var char = str[k];
    while(str[k] == char){
        count++;
        if(k == len - 1){
            break;
        }
        k--;
    }
    while(str[k] == char){
        count++;
        if(k == len - 1){
            break;
        }
        k++;
    }
    print(count);
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();

    var k = Math.floor(len / 2);
    var char = str[k];
    while(str[k] == char){
        count++;
        if(k = len - 1){
            break;
        }
        k--;
    }
    while(str[k] == char){
        count++;
        if(k = len - 1){
            break;
        }
        k++;
    }
    print(count);
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();

    var k = Math.floor(len / 2);
    var char = str[k];
    while(str[k] == char){
        count++;
        if(k == len - 1){
            break;
        }
        k--;
    }
    while(str[k] == char){
        count++;
        if(k == len - 1){
            break;
        }
        k++;
    }
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();

    for(var k = 0; k < len; k++){
        var newStr = "";
        var newStrRev = "";

        var atrArr = str.split("").splice(k, 1);

        for(var j = 0; j < len - 1; j++){
            newStr += atrArr[j];
            newStrRev += atrArr[len - 2 - j];
        }
        if(newStr == newStrRev) count++;
    }
    print(count);
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();

    for(var k = 0; k < len; k++){
        var newStr = "";
        var newStrRev = "";

        str.split("").splice(k, 1);

        for(var j = 0; j < len - 1; j++){
            newStr += str[j];
            newStrRev += str[len - 2 - j];
        }
        if(newStr == newStrRev) count++;
    }
    print(count);
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();
    var newStr = "";
    var newStrRev = "";
    for(var k = 0; k < len; k++){
        str.split("").splice(k, 1);

        for(var j = 0; j < len - 1; j++){
            newStr += str[j];
            newStrRev += str[len - 2 - j];
        }
        if(newStr == newStrRev) count++;
    }
    print(count);
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();

    var strNew = "";
    var strNewReversed = "";
    var temp = "";

    for(var k = 0; k < len; k++){
        strNew = str.split("").splice(k, 1).join("");
        var ispoll = true;
        for(var j = 0; j < strNew.length; j++){
            if(strNew[j] === strNew[strNew.length - j]) ispoll = false;
        }
        if(ispoll) {
            count++;
        }
    }
    print(count);
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();

    var strNew = "";
    var strNewReversed = "";
    var temp = "";

    for(var k = 0; k < len; k++){
        temp = str.split("").splice(k, 1);
        strNewReversed = temp.reverse().join("");
        strNew = temp.join("");
        if(strNew === strNewReversed) {
            count++;
        }
    }
    print(count);
}

var num = parseInt(readline(), 10);

for(var i = 0; i < num; i++){
    var count = 0;
    var len = parseInt(readline(), 10);
    var str = readline();
    var strNew = "";
    var strNewReversed = "";
    var temp = "";
    for(var k = 0; k < str.length; k++){
        temp = str.split("").splice(k, 1).join("");
        strNewReversed = str.split("").splice(k, 1).reverse().join("");
        strNew = str.split("").splice(k, 1).join("");
        if(strNew === strNewReversed) count++;
    }
    print(count);
}

T = readline()
while (T--) {
   n = +readline()
   a = readline().split('')

   repeat = 0
   half = 0
   half = Math.ceil(n/2)

   for(i = half; i< n-1; i++){
      if(a[i] ===a[i+1])
         repeat++
      else
         break
   }

   if(n%2 != 0)
      ans = 1 + 2*repeat
   else
      ans = 2 * (1+ repeat)

   print( ans)
}


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

let inputString = '';
let currentLine = 0;

process.stdin.on('data', input => inputString += input);
process.stdin.on('end', () => {
    inputString = inputString.trim().split('\n').map(string => string.trim());
    main();
});

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

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

function readElements(parse = parseInt, separator = ' ') {
    return readLine().split(separator).map(input => parse ? parse(input) : input);
}

function main() {
    let zeros = 0;
    let ones = 0;
    const [_, queries] = readElements();
    const list = readLine().split(' ').map(input => {
        input = parseInt(input);
        if (input === 1) {
            ones++;
        } else {
            zeros++;
        }

        return input;
    });

    for (let q = 0; q < queries; q++) {
        const [type, value] = readElements();
        let index = value - 1;

        if(type === 2) {
            print((value <= ones) ? "1" : "0");
        } else {
            list[index] = 1 - list[index];
            if (list[index] === 1) {
                ones++;
                zeros--;
            } else{
                zeros++;
                ones--;
            }
        }
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});
var mod = 1000000000 + 7

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

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

function main() {
    // var x = parseInt(readline())
    // var x = new Array(n)
    var [n, q] = readline().split(' ').map((x, iii) => {
        return x
    })
    var length1 = 0

    var a = readline().split(' ').map((x, iii) => {
        if (parseInt(x) === 1) length1++
        return parseInt(x)
    })

    for (let i = 0; i < q; i++) {
        var [x, k] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        if (x === 1) {
            if (a[k - 1] === 1) length1--
            if (a[k - 1] === 0) length1++
            a[k - 1] = 1 - a[k - 1]
            continue
        }
        if (k > length1) console.log(0)
        else console.log(1)
    }
}

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', line => {
    var [n, k] = input[0].split(" ").map((i) => {
        return Number(i);
    })
    var arr = input[1].split(" ").map((i) => {
        return Number(i);
    });
    var count = 0;
    for (var i = 0; i < arr.length; i++) {
        if (arr[i] === 1) {
            count++;
        }
    }
    for (var i = 2; i < input.length; i++) {
        var [type, value] = input[i].split(" ").map((i) => {
            return Number(i);
        });
        if (type === 1) {
            var index = value - 1;
            arr[index] = 1 - arr[index];
            if (arr[index] === 0) {
                count--;
            } else {
                count++;
            }
        } else {
            if (value > count) {
                console.log(0);
            } else {
                console.log(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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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 N = nextInt();
	var Q = nextInt();
	var list = nextIntArray(N);
	var map = [0, 0];
	for(var i = 0; i < N; i++){
		map[list[i]]++;
	}
	for(var i = 0; i < Q; i++){
		var t = nextInt();
		var x = nextInt();
		if(t == 1){
			x--;
			map[list[x]]--;
			list[x] = 1 - list[x];
			map[list[x]]++;
		}else{
			if(map[1] >= x){
				myout(1);
			}else{
				myout(0);
			}
		}
	}
}

function readStringArray() {
  return readline().split(" ");
}
function readNumArray() {
  return readStringArray().map(Number);
}

function main() {
  var nq = readNumArray();
  var n = nq[0];
  var q = nq[1];
  var arr = readNumArray();
  var ones = 0;
  for (var i = 0; i < n; i++) {
    if (arr[i] === 1) {
      ones++;
    }
  }
  for (var i = 0; i < q; i++) {
    var tx = readNumArray();
    var t = tx[0];
    var x = tx[1];
    if (t === 1) {
      arr[x-1] = 1 - arr[x-1];
      if (arr[x-1]) {
        ones++
      } else {
        ones--;
      }
    }
    if (t === 2) {
      if (x <= ones) {
        print('1')
      } else {
        print('0')
      }
    }
  }
}

main();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});
var mod = 1000000000 + 7

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

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

function main() {
    // var x = parseInt(readline())
    // var x = new Array(n)
    var [n, q] = readline().split(' ').map((x, iii) => {
        return x
    })
    var length1 = 0

    var a = readline().split(' ').map((x, iii) => {
        if (parseInt(x) === 1) length1++
        return parseInt(x)
    })

    for (let i = 0; i < q; i++) {
        var [x, k] = readline().split(' ').map((x, iii) => {
            return parseInt(x)
        })
        if (x === 1) {
            if(a[k-1] ===1) length1--
            a[k - 1] = 1 - a[k - 1]
            continue
        }
        if(k>length1) console.log(0)
        else console.log(1)
    }
}


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

rl.on('line', (d) => {
  if (c === 0) {
    [n, m] = d.split(' ').map(Number);
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);

  for (let i = 0; i < arr.length; i += 2) {
    if (arr[i] === 1 || arr[i + 1] === 1) {
      ans++;
    }
  }

  c++;
});

rl.on('close', () => {
  console.log(ans);
});

let input = [];

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

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

RL.on('close', () => {
    let {0:n, 1:m} = {...input[0].split(' ')};
    n = parseInt(n); m = parseInt(m);

    let answer = 0;
    for(let i = 0; i < n; i++){
        const data = []; input[i+1].split(' ').forEach(j => data.push(parseInt(j)));
        for(j = 0; j < m*2; j+=2){
            if(data[j] === 1 || data[j+1] === 1)
                answer++;
            //console.log(`data[j] = ${data[j]}; data[j+1] = ${data[j+1]}`);
        }
    }

    console.log(answer);
});

function imp()
{
    var oneline = readline();
    var elements = oneline.split(" ");
    var n = parseInt(elements[0]);
    var m = parseInt(elements[1]);
    var count = 0;
    for(var i=1;i<=n;i++)
    {
        oneline  = readline();
        elements = oneline.split(" ");
        for(var j=0;j<2*m;j=j+2)
            if(elements[j] == '1' || elements[j+1] == '1')
                count++;
    }
    print(count);
}
imp();

var inputs = readline().split(' '),
	n = parseInt(inputs[0]),
	m = parseInt(inputs[1]),
	windows = [],
	res = 0;

for (var i = 0; i < n; i++) {
	inputs = readline().split(' ');
	windows = windows.concat(inputs);
}

for (var i = 0; i < windows.length; i+=2) {
	if (windows[i] == '1' || windows[i+1] == '1') ++res;
}

print(res);

var solve = function(a, n, m) {
    var ans = 0;
    for(var i=0;i<n;i++) {
        for(var j=0;j<m;j++) {
            if(a[i][2*j] == 1 || a[i][2*j+1] == 1) {
                ans ++;
            }
        }
    }
    return ans;
};
var x = readline().split(' ');
var n = parseInt(x[0]);
var m = parseInt(x[1]);
var a = [];
for(var i=0;i<n;i++) {
    x = readline().split(' ');
    var b = [];
    for(var j=0;j<x.length;j++) {
        b[j] = parseInt(x[j]);
    }
    a.push(b);
}
var ans = solve(a, n, m);
print(ans);

var line = readline().split(' ');
var kol = 0;

while(line[0] > 0) {
    var x = readline().split(' ');
    for(var i=1; i<line[1]*2; i+=2 ) {
            if(parseInt(x[i]) || parseInt(x[i-1])) {
                //write(x[i] + ' ' + i + '\n');
                kol ++;
            }
    }

    //write(kol)
    line[0] --;
}
write(kol)

var x = readline().split(' ');
var n = parseInt(x[0]);
var m = parseInt(x[1]);

var ans = 0;
for(var i=0;i<n;++i) {
    x = readline().split(' ');
    for(var j=0;j<m; ++j) {
        if (x[j*2]=='1' || x[j*2+1]=='1') ++ans;
    }
}
print(ans);

function imp()
{
    var oneline = readline();
    var elements = oneline.split(" ");
    var n = parseInt(elements[0]);
    var m = parseInt(elements[1]);
    var count = 0;
    for(var i=1;i<=n;i++)
    {
        oneline  = readline();
        elements = oneline.split(" ");
        for(var j=0;j<m;j=j+2)
            if(elements[j] == '1' || elements[j+1] == '1')
                count++;
    }
    print(count);
}
imp();

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

rl.on('line', (d) => {
  if (c === 0) {
    [n, m] = d.split(' ').map(Number);
    c++;
    return;
  }

  const arr = d.split(' ').map(Number);
  let idx = 0;

  while (idx < m) {
    for (let i = idx * m; i < (idx + 1) * m; i++) {
      if (arr[i] === 1) {
        ans++;
        break;
      }
    }

    idx++;
  }

  c++;
});

rl.on('close', () => {
  console.log(ans);
});

function imp()
{
    var oneline = readline();
    var elements = oneline.split(" ");
    var n = elements[0];
    var m = elements[1];
    var count = 0;
    for(var i=1;i<=n;i++)
    {
        oneline  = readline();
        elements = oneline.split(" ");
        for(var j=0;j<m;j=j+2)
            if(elements[j] == 1 || elements[j+1]==1)
                count++;
    }
    print(count);
}
imp();

function imp()
{
    var firstline = readline();
    var elements = firstline.split(" ");
    var n = elements[0];
    var m = elements[1];
    var count = 0;
    for(var i=1;i<=n;i++)
    {
        var oneline  = readline();
        var ele = oneline.split(" ");
        for(var j=0;j<m;j=j+2)
            if(ele[j] == 1 || ele[j+1]==1)
                count++;
    }
    print(count);
}
imp();