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

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

readLine.on('close', () => {
    let result = 1
    let views = []
    const items = [...input.slice(1)]
    if (items.length > 2) {
        items.forEach((el, index) => {
            if (index !== items.length - 1) {
                const next = index + 1
                if (!views[index]) {
                    if (el !== items[next]) {
                        result++
                    }
                }
            }
            views[index] = 'true'
        })
    } else if (items.length === 2) {
        if (items[0] === items[1])
            result = 1
        else
            result = 2
    }
    console.log(result)
})

var n_imanes = readline()
var comparador = "";
var grupos = 0;
for (var i = 0; i < n_imanes; i++) {
	var polo = readline();
	if (polo != comparador) {
		comparador = polo;
		grupos++;
	}
}
print(grupos);

var arr = [], count = 1, inputs, ch = ' ';
inputs = readline();

while (inputs !== 0) {

    arr = readline();
    if (arr[0] === ch) {
        count++;
    }
    ch = arr[1];
    inputs--;
}
print(count);

var inputs = readline();
  var groupCounter = 0;
  var previousMagnet = -1;
  for (var i = 0; i < inputs; i++) {
    var line = readline();
    if (line[0] !== previousMagnet) {
      groupCounter += 1;
      previousMagnet = line[0];
    }
  }

  print(groupCounter);

var numLines = readline();
var lastLine = '';
var blocks = 0;
for(var i = 0; i < numLines; i++)
{
    var currentLine = readline();
    if(currentLine !== lastLine) blocks++;
    lastLine = currentLine;
}

print(blocks);

var n = parseInt(readline());
var gr = 0;
var prev = null;
for (var i = 0; i < n; i++){
  var inp = readline();
  if (!prev || inp[0] == prev[1]){
    gr++;
  }
  prev = inp;
}
print (gr);

var main = function(arr)
{
    var c = 1;
    for (var i = 1; i < arr.length; i++)
    {
       if (arr[i] !== arr[i - 1]) c++;
    }
    return c;
}

{
    var num = readline();
    var arr = [];
    for (var i = 1; i <= +num; i++)
    {
        var aElem = readline();
        arr.push(aElem);
    }
    if (arr.length === 0) print(0);
    else
    print(main(arr));
}

var num=parseInt(readline());
// print(num)
var arr=[];

for(var i=0;i<num;i++){
  var mag=(readline());
  arr.push(mag)

}

var count=0;
var mag_check=arr[0];

for(var j=0;j<arr.length;j++){
  if(mag_check==arr[j+1]){
    count=count;
    mag_check=arr[j+1];
  }else{
    count=count+1;
    mag_check=arr[j+1];
  }
}
print(count);

var magnetNum=parseInt(readline());
var num=[readline()];
var groupNum=1;
for(i=1;i<magnetNum;i++){
  num[i]=readline();
  if(num[i-1]!=num[i])
   groupNum++;
}

print(groupNum)

  var n = readline();
  var magnets = [];
  var c = 1;
  for(var i = 0; i < n; i++)
  {
    var x = readline();
    magnets.push(x);
  }

  for(var i = 1; i < n; i++)
  {
    if(magnets[i] != magnets[i-1])
    {
      c++;
    }
  }
  print(c);

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

for(var x = 0;x<count;x++){read[x] = readline();}

for(var i = 0;i<count;i++){
	if(i > 0){if(read[i][0] == read[i - 1][1]){calc+=1}}
}

print(calc + 1);

n = parseInt(readline()), r = 0
v = ""
while (n--) {
	u = readline()
	if (u != v)
		v = u, r++
}
print(r)

var n = parseInt(readline(), 10),
    magnet = [],
    group = 1;

for(var i=0; i<n; i++) {
    magnet.push(readline().split(''));
    if(i !== 0) {
        if(magnet[i-1][1] === magnet[i][0]) group++;
    }
}

print(group);

var nums = parseInt(readline());

var prev = null;
var block = 0; //block not gap
for (var i = 0; i < nums; i++) {
    var current = parseInt(readline());

    if (current !== prev) {
        block++;
    }

    prev = current;
}

print(block);

var print = this.print || require('lol-io').print
var write = this.write || require('lol-io').write
var readline = this.readline || require('lol-io').readline

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

var group=1;
for(var i=1;i<n;i++){
    var s=arr[i];
    var s1=arr[i-1];
   if(s1[s1.length-1]!=s[0]){

   }else{
       group++;
   }
};
print(group);

var numbersMagnetDomino = +readline();
var prevDomino = "";
var numbersDominoIsland = 0;
for (var stepDomino = 0; stepDomino<numbersMagnetDomino; stepDomino++) {
    var magnetDomino = readline();
    if (prevDomino!==magnetDomino) {
        numbersDominoIsland++;
        prevDomino = magnetDomino;
    }
}
print(numbersDominoIsland);

n = readline();
base = '00';
groups = 0;
for (i=0;i<n;i++){
	next = +readline();
	if (next != base){
		groups++;
	}
	base = next;
}
print(groups)

var n = readline();
var x ="";
var y = 0;
for(var i = 0; i<n; i++){
    var s = readline();
    if (s != x){
        x = s;
        y++;
    }
}
print(y);

var r = readline();
var s=1;
var x1 =readline();
for(var i = 0; i< r-1;i++){
    var x2 = readline();
    if (x1[1] == x2[0]){
        s++;
    }
    x1=x2;
}
print(s);

var n = readline();
var magnets = [], counter = 1;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
}
magnets.forEach((item, index, arr) => {
    if(item[1] === (arr[index+1] ? arr[index+1][0] : null)) counter++;
})
print(counter);

const readline = require('readline');

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

let numOfMagnets, magnets = [], groups = 0;

rl.on('line', n => {
  if (!numOfMagnets) { numOfMagnets = n; } else {
    magnets.push(n);
    if (magnets.length === +numOfMagnets) {
      for (let i = 0; i < magnets.length; i++) {
        if (magnets[i] !== magnets[i - 1]) groups += 1;
      }
      console.log(groups);
      rl.close();
    }
  }
});

'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() {
    let n = parseInt(readline());
    let current = '';
    let numOfGroups = 0;
    for (let i = 0 ; i < n ;i++){
        let line = readline();
        if (current != line) numOfGroups ++;
        current =line;
    }
console.log(numOfGroups);
}

function main() {
    // write code here:
    var n=Number(stdin[0]);
    var count=0;
    for(let i=1;i<=n;i++){
        if(stdin[i]!==stdin[i+1]){
            count++;
        }
    }
    console.log(count);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);

const readline = require("readline")

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

let numberOfMagnets = 0;
let groupCounter = 0;
let counter = 0;
let temp;
rl.on("line", (input) => {
    if (!numberOfMagnets) {
        numberOfMagnets = parseInt(input.split(" "));
    } else if (numberOfMagnets) {
        counter++

        if (!temp) {
            temp = input.split(" ").toString()
            groupCounter++
        }
        if (temp) {
            if (input.split(" ").toString() != temp) {
                temp = input.split(" ").toString();
                groupCounter++
            }
                if (counter === numberOfMagnets) {
                    rl.close();
                    console.log(groupCounter)
                }
        }

    }

});

// if (temp === plusMinus) {
//     groupCounter++
//     flag = true
// }
// if (temp === minusPlus) {
//     groupCounter++
//     flag = false;
// }

"use strict";

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

let inputString = "";
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const x = readline();
 const arr = [];

 for(let n=0;n<x;n++){
     arr.push(readline());
 }

  fn(arr);
}

function fn(poles) {
  let groups = 1;

  for (let i = 1; i < poles.length; i++) {
    const prevMagnet = poles[i - 1];
    const currMagnet = poles[i];

    if (currMagnet&&prevMagnet&&prevMagnet[1] == currMagnet[0]) groups++;
  }
  console.log(groups);
  return groups;
}

//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");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return 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 N = nextInt();
  var mae = next();
  var output = 1;
  for(var i = 0; i < N - 1; i++){
    var ato = next();
    if(mae != ato){
      mae = ato;
      output++;
    }
  }
  myout(output);
}

const readline = require('readline');

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

let magnetNo;
let counter = -1;
let groups = 1;
let lastChar;

rl.on('line', (input) => {
    counter++;
    if (counter === 0) {
        magnetNo = parseInt(input);
        return;
    }
    if (counter === 1) {
        lastChar = input[1];
    } else {
        let currentChar = input[0];
        groups = (currentChar === lastChar) ? groups + 1 : groups;
        lastChar = input[1];
    }

    if (counter === magnetNo) {
        rl.close();
        console.log(groups);
    }
});

const readline = require('readline');

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

let magnetNo;
let counter = -1;
let inputs = [];

rl.on('line', (input) => {
    counter++;
    if (counter === 0) {
        magnetNo = parseInt(input);
        return;
    }

    inputs.push(input);
    if (counter === magnetNo) {
        rl.close();
        console.log(solve(inputs));
    }

});

const solve = (inputs) => {
    let groups = 1;

    for (let i = 0; i < inputs.length - 1; i++) {
        let mag1 = inputs[i];
        let mag2 = inputs[i + 1];
        if (mag1[1] === mag2[0]) groups++;
    }
    return groups;
};

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

let isFirstLine = true;
let noOfGroups = 0;
let prevLineCode = null;

rl.on("line", function (line) {
  if (!isFirstLine) {
    const lineCode = line == "10" ? 1 : 0;
    if (lineCode !== prevLineCode) {
      noOfGroups++;
      prevLineCode = lineCode;
    }
  } else {
    isFirstLine = false;
  }
});

rl.on("close", function () {
  console.log(noOfGroups);
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function print(s) {
  process.stdout.write(`${s}`);
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  // input
  const n = readline();
  let result = 1;
  let prev = readline();
  for (let i = 1; i < n; i++) {
    const cur = readline();
    if (cur !== prev) {
      result++;
      prev = cur;
    }
  }
  // output
  print(result);
}

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

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

  if (prev !== d) {
    prev = d;
    ans++;
  }

  c++;
});

rl.on('close', () => {
  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 inputs = readline();
    let array=[];
    let groups =0;
    for (let i=0 ;i< inputs;i++){
        array[i] = readline();
    }

    for (let i=0 ;i< array.length;i++){
       if(array[i]!== array[i+1]){
           groups++
       }
    }

    console.log(groups);

    return;
}

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

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

readLine.on('close', () => {
  let answer = 0, last = null;
  input.forEach((line, i) => {
    if (i === 0) return;

    if (last === null) {
      answer += 1;
    }

    if (last === '0' && line[0] === '0') answer += 1;
    if (last === '1' && line[0] === '1') answer += 1;
    last = line[1];
  });

  console.log(answer);
});

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 = parseInt(input.shift());
    const magnites = input;

    let islands = 1;
    for (let i = 1; i < magnites.length; i++) {
        if(magnites[i] === magnites[i - 1]) continue;
        else islands++;
    }

    console.log(islands);
});

'use strict';

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

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    // if(Array.isArray(inputString)) inputString = inputString.join('\n');
    inputString += inputStdin;
    // inputString = inputString.trim().split('\n').map(string => {
    //     return string.trim();
    // });

    // main();
});

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

    main();
});

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

function readAsInt(){
  return parseInt(readline());
}

function readAsIntList(){
  return readline().trim().split(' ').filter(i => i).map(i => parseInt(i));
}

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

function main() {
  let n = readAsInt();
  let lastpole = null;
  let total = 0;
  for(let i = 1; i <= n; i++ ){
    let pole = readAsInt() === 10;
    total += i > 1 ? (pole === lastpole ? 0 : 1) : 1;
    lastpole = pole;
  }
  console.log(total);
}

/**
 * @author Sunwarul
 * Software Developer
*/

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStd => {
    inputString += inputStd;
});
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(str => {
        return str.trim();
    });
    main();
});

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

function main() {
	const n = +(readLine());
	let sum = 1;
	const magnets = [];
	for(let i = 0; i < n ; i++) {
		magnets[i] = readLine();
	}

	for(let i = 0; i < n - 1; i++) {
		if(magnets[i] !== magnets[i+1]) {
			++sum;
		}
	}

	console.log(sum);
}

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

/******** Main function*************/

function isLowerCase(str) {
  return str == str.toLowerCase() && str != str.toUpperCase();
}

function main() {
  var n = +readLine();
  var arr = [];
  for (var j = 0; j < n; j++) {
    var m = +readLine();
    arr.push(m);
  }

  var count = 1;

  for (var i = 0; i < n - 1; i++) {
    if (arr[i] != arr[i + 1]) {
      count++;
    }
  }
  console.log(count);
}

// Determine the number of groups that the magnets formed.

let fs = require("fs");

let txt = fs.readFileSync(0, "utf-8").split("\r\n").filter(data => {
    return data.length > 0;
});
for (let i = 0; i < txt.length; i ++) {
    if(!isNaN(txt[i]*1)){
        let tab=[];
        for (let i1 = i+1; i1 < i+1+txt[i]*1; i1++) {
            tab.push(txt[i1]);

        }
        doit(tab);
        i+=txt[i]*1;
    }
}

function doit(tab) {
  let groups=1;
    tab.forEach((data,index)=>{
        if(tab[index+1]){
        if(data[1]==tab[index+1][0])++groups;
        }
    });
    console.log(groups);

}

// Sample code to perform I/O:

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

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

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

function main(input) {
    let output = nameLookUp(input);
    process.stdout.write(output);       // Writing output to STDOUT
}

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

// Write your code here
function nameLookUp(str) {
    let inputs = str.trim().split('\n');
    let magnetArr = inputs.slice(1);
    let count = 1;
    let groups = parseInt(magnetArr[0].trim(), 2);

    for (let i = 1; i < magnetArr.length; i++) {
        let group = parseInt(magnetArr[i].trim(), 2);
        if (group !== groups) {

            groups = parseInt(magnetArr[i].trim(), 2);
            count++;
        }
    }
    return count.toString();
}

var readline = require("readline")
var rl = readline.createInterface(process.stdin,process.stdout);
var n;
var l=0;
var magnets = [];
var groups = 1;
rl.question('',function(data){
      n = parseInt(data);
      //rl.prompt()
      rl.on("line",function(mag){
            magnets.push(mag.toString().trim())
            l++;
            if(l == n){
                  rl.close();
            }
      });
})
rl.on('close',function(){
      for (let i = 0; i < n-1; i++) {
            //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));
            if (magnets[i].charAt(1)==magnets[i+1].charAt(0)){
                  groups++;
            }
      }
      if(groups > 0){
            console.log(groups);
      } else {
            console.log(groups+1);
      }
})

const readline = require("readline");

const rl = readline.createInterface({
  input: process.stdin,
});
let counter = 0;
let isFirstLine = true;
let previousMagnet = null;
rl.on("line", function (magnet) {
  if (isFirstLine) {
    isFirstLine = false;
    return;
  }
  if (magnet !== previousMagnet) {
    counter++;
    previousMagnet = magnet;
  }
});

rl.on("close", function () {
  console.log(counter);
});

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

const input = [];
readLine.on('line', line => input.push(line));
const magnets = () => {
    let ar = [];
    let count = 0;
    let q = +input.shift();
    for (const x of input) {
        for (const y of x) {
            ar.push(+y);
        }
    };

    for (let i = 1; i < ar.length; i++) {
        if (ar[i] === ar[i-1]) {
            count++;
        }
    }
    console.log(count+1);

};

readLine.on('close', magnets);

'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    let a = readLine();
    let ans = 1;
    for (var i = 0; i < n - 1; i++) {
        let b = readLine();
        if (a != b) {
            ans++;
            a = b;
        }
    }
    console.log(ans);
}

var n=+readline();
var ans=0;
var prev='';
while(n--){
	var now = readline();
	if(now!=prev){
		prev=now;
		ans++;
	}
}
print(ans);

var n = +readline(), m = [], counter = 0;
for(i = 0; i < n; i++){
	m.push(readline());
}

for(i = 0; i < n-1; i++){
	if(m[i][1] != m[i+1][0]){
		continue;
	}
	else{
		counter++;
	}
}
write(counter+1);

var x= parseInt(readline())-1;

var now = readline();
var grps=0;

var prev;

while(x--){
  var prev= now;
  var now=readline();
  if(now[0] === prev[1]){
    grps++;
  }
}

print(++grps);

var n = +readline();
var res = + (n > 0);
var last = 'x';

while (n) {
    var str = readline();
    if (str[0] === last) res++;
    last = str[1];
    n --;
}

print(res);

var m = 1;
var input=[];
var n = parseInt(readline());
input[0] = readline();
for(var i=1 ; i<n ;i++){
    input[1]=readline();
    if(input[0].charAt(1) == input[1].charAt(0)){
        m++;
    }
    input[0]=input[1];

}
print(m);

var m = 1;
var x, y;
var n = parseInt(readline());
x = readline();
for(var i=1 ; i<n ;i++){
    y=readline();
    if(x.charAt(1) == y.charAt(0)){
        m++;
    }
    x=y;

}
print(m);

var m = 0;
var x="";
var y;
var n = parseInt(readline());

for(var i=0 ; i<n ;i++){
    y=readline();
    if(x != y){
        x=y
        m++;
    }
}
print(m);

var m = 1;
var x, y;
var n = parseInt(readline());
x = readline();
for(var i=1 ; i<n ;i++){
    y=readline();
    if(x.localeCompare(y) !== 0){
        m++;
    }
    x=y;
}
print(m);

check = "00";
counter = 0;
num = Number(readline())
for (i = 0 ; i<num;i++){
    var x = readline();
    if (x!= check){counter++;check = x;}
}
print(counter)

function main(){
    var n = +readline();
    var prev;
    var res = 1;
    for(var i = 0; i < n; ++i){
        var num = readline();
        if(!prev){
            prev = num;
            continue;
        }
        if(prev !== num) ++res;
        prev = num;
    }

    print(res);
}

main();

var n = readline();
var Magnet_type = " ";
var counter = 0;
 for(var i = 0; i < n; i++){
   var read = readline();
   if(Magnet_type != read){
     Magnet_type = read;
     counter++
   }
 }
 print(counter);

var n = parseInt(readline());
var str = readline();
var sum = 0;
for(var i = 1; i < n; ++i)
{
    var temp = readline();
    if(temp != str){sum ++;}
    str = temp;
}
print(sum+1);

var n = readline();

var counter = 1;

var firstMagnit = readline();

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

    var secondeMagnit = readline();

    if (firstMagnit != secondeMagnit) {
        counter += 1;
    }

    firstMagnit = secondeMagnit;

}

print(counter);

var n = readline();

var magnits = [];

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

var counter = 1;

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

    if (magnits[i][1] === magnits[i + 1][0]) {
        counter += 1;
    }

}

print(counter);

var n = readline();

var magnits = [];

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

var counter = 1;

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

    if (magnits[i] != magnits[i + 1]) {
        counter += 1;
    }

}

print(counter);

  var inputs = readline();
  var groupCounter = 0;
  var previousMagnet = -1;
  for (var i = 0; i < inputs; i++) {
    var line = readline();
    if (line[0] !== previousMagnet) {
      groupCounter += 1;
      previousMagnet = line[0];
    }
  }

  print(groupCounter);

var line1 = readline();

var groupCount = 0, magent, prevMagnet = readline();
for(var i = 1; i < line1; i++) {
    magnet = readline();

    if(magnet != prevMagnet) {
        groupCount++;
    }
    prevMagnet = magnet;
}
print(groupCount + 1);

var noOfMagnets=Number(readline());
var counter=0;
var firstValue;
var secondValue;

for(var i =0 ; i< noOfMagnets ; i++ )
{
    firstValue=Number(readline());
   if(firstValue != secondValue){
       counter=counter+1;
       secondValue = firstValue;
   }

}

print(counter);

var input = parseInt(readline());
var count = 0;
var prev;
while(input>0){
    var ins = readline();
    if(!prev || prev != ins){
        count++;
        prev = ins;
    }
    input--;
}
print(count);

;(function () {
	var n = +readline();
	var t = readline();
	var r;
	var x = 1;

	for (var i = 1; i < n; i++) {
		r = readline();
		if (t[1] == r[0]){
			x++;
			t = r;
		}
	}

	print(x);
}).call(this);

var size = readline(),
	counter = 0,
	hasChanged = false,
	lastMagnet = undefined;

for(var index = 0; index < size; index ++){
	var currentMagnet = readline();
	if( lastMagnet !== currentMagnet ){
		//has to be change
		counter ++;
		lastMagnet = currentMagnet;
	}
}

print(counter);

var res = sol(readline());
print(res);

function sol(line) {

    var input = line.split(" ");

    var n = input[0];

    var prev = "";
    var group = 0;

    while(n > 0){
        var magnet = readline();

        if(prev != magnet){
            prev = magnet;
            group++;
        }

        n--;
    }

    return group;
}

var n = Number(readline());
var count = 0;
var prevStr = '';
for(var i = 0; i < n; i++) {
    var str = readline();
    if (str !== prevStr) {
        count++;
    }
    prevStr = str;
}
print(count);

var toInt = x => parseInt(x);
var toInput = () => readline();
var result = 1;
var toGroups = (a, b) => {
    result+= (a!==b);
    return b;
};
new Array(parseInt(readline())).fill('')
    .map(toInput).reduce(toGroups);

print(result);

'use strict';
let n = parseInt(readline()),
    array = new Array(n);

for (let i = 0; i < n; i++) {
    array[i] = readline();
}

write(array.join('').split('00').join(' ').split('11').join(' ').split(' ').length);

n = readline();
var ans = 0,
    u = "";
for (var i = 0; i < n; i++) {
    x = readline();
    if (x != u) {
        u = x;
        ans++;
    }
}
print(ans)

var n = readline(),
        p = readline(),
        count = 1;
for (var i = 1; i < n; i++) {
        var k = readline();
        if (k != p) count++;
        p = k;
}
print(count);

var n = readline();
var temp = 0;
var res = 0;
	for (var i=0; i<+n; i++){
		var str = readline();
		if (str!=temp) res++;
		temp = str;
	}
	print(res);

var limit = parseInt(readline())
var previous = readline()
limit--
var count = 1
while(limit > 0){
    var current = readline()
    if(current != previous){
        count++
    }

    previous = current
    limit--
}

print(count)

var line = readline();
var input = [];
var result = 0;
for(var i = 0; i < line; i++) {
   input[i] = readline();
}

for(var i = 1; i < input.length; i++) {
    if(input[i] != input[i-1]){
        result ++;
    }
}
print(result + 1);

var n = readline()
var q = "", z = 0
for (var i = 0; i < n; i++) {
	var s = readline()
	if (s != q) {
		q = s
		z++
	}
}
print(z)

var n = Number(readline());

var magn = [];
var islands = 0, k = 0;
for (var i=0; i< n; i++) {
    var s = readline();
    magn.push(s);
}

for (var j = 0; j < magn.length; j++) {
    if (magn[j] === magn[j+1]) {
        k++;
        continue;
    }
    else {
        islands++;
        k = 0;
    }
}
print(islands)

var n_imanes = readline();
var comparador = "";
var grupos = 0;
for (var i = 0; i < n_imanes; i++) {
	var polo = readline();
	if (polo != comparador) {
		comparador = polo;
		grupos++;
	}
}
print(grupos);

var n_imanes = readline()
var comparador = "";
var grupos = 0;
for (var i = 0; i < n_imanes; i++) {
	var polo = readline();
	if (polo != comparador) {
		comparador = polo;
		grupos++;
	}
}
print(grupos);

'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() {
    let n = parseInt(readline());
    let current = '';
    let numOfGroups = 0;
    for (let i = 0 ; i < n ;i++){
        let line = readline();
        if (current === line) numOfGroups ++;
        current =line;
    }
console.log(numOfGroups);
}

function main() {
    // write code here:
    var n=Number(stdin[0]);
    var count=0;
    for(let i=1;i<=n;i++){
        if(stdin[i]===stdin[i+1]){
            count++;
        }
    }
    console.log(count);
}

const readline = require('readline');
const rl = readline.createInterface({input: process.stdin});
var stdin = [];
rl.on('line', function (line) {
    stdin.push(line);
});
rl.on('close', main);

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

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

readLine.on('close', () => {
    let result = 0
    let views = []
    const items = [...input.slice(1)]
    if (items.length > 2) {
        items.forEach((el, index) => {
            if (index > 0) {
                const prev = index - 1
                const next = index + 1
                if (!views[index]) {
                    if (el !== items[prev]) {
                        views[prev] = 'true'
                        result++
                    } else if (el !== items[next]) {
                        views[next] = 'true'
                        result++
                    }
                }
            }
            views[index] = 'true'
        })
    } else if (items.length === 2) {
        result = 2
    } else {
        result = 1
    }
    console.log(result)
})

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

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

readLine.on('close', () => {
    let result = 0
    let views = []
    const items = [...input.slice(1)]
    if (items.length > 2) {
        items.forEach((el, index) => {
            if (index > 0) {
                const prev = index - 1
                const next = index + 1
                if (!views[index]) {
                    if (el !== items[prev]) {
                        views[prev] = 'true'
                        result++
                    }
                    if (el !== items[next]) {
                        views[next] = 'true'
                        result++
                    }
                }
            }
            views[index] = 'true'
        })
    } else if (items.length === 2) {
        if (items[0] === items[1])
            result = 1
        else
            result = 2
    } else {
        result = 1
    }
    console.log(result)
})

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

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

readLine.on('close', () => {
    let result = 0
    let views = []
    const items = [...input.slice(1)]
    if (items.length > 2) {
        items.forEach((el, index) => {
            if (index > 0) {
                const prev = index - 1
                const next = index + 1
                if (!views[index]) {
                    if (el !== items[prev]) {
                        views[prev] = 'true'
                        result++
                    } else if (el !== items[next]) {
                        views[next] = 'true'
                        result++
                    }
                }
            }
            views[index] = 'true'
        })
    } else if (items.length === 2) {
        if (items[0] === items[1])
            result = 1
        else
            result = 2
    } else {
        result = 1
    }
    console.log(result)
})

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

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

readLine.on('close', () => {
    let result = 0
    let views = []
    const items = [...input.slice(1)]
    if (items.length > 1) {
        items.forEach((el, index) => {
            if (index > 0) {
                const prev = index - 1
                const next = index + 1
                if (!views[index]) {
                    if (el !== items[prev]) {
                        views[prev] = 'true'
                        result++
                    } else if (el !== items[next]) {
                        views[next] = 'true'
                        result++
                    }
                }
            }
            views[index] = 'true'
        })
    } else {
        result = 1
    }
    console.log(result)
})

const readline = require("readline")

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

let numberOfMagnets = 0;
let plusMinus = "01";
let minusPlus = "10";
let groupCounter = 0;
let flag = false;
let counter = 0;
rl.on("line", (input) => {
    if (!numberOfMagnets) {
        numberOfMagnets = parseInt(input.split(" "));

        //console.log(typeof(numberOfMagnets),numberOfMagnets)
    }
    if (numberOfMagnets) {
        counter++;
        let temp = input.split(" ").toString();
        if (temp === plusMinus && flag === false) {
            groupCounter++
            flag = true
        }
        if (temp === minusPlus && flag === true) {
            groupCounter++
            flag = false;
        }

        if (counter > numberOfMagnets) {
            rl.close();
            console.log(groupCounter)
        }
    }

});

const readline = require("readline")

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

let numberOfMagnets = 0;
let plusMinus = "01";
let minusPlus = "10";
let groupCounter = 0;
let flag = true;
let counter = 0;
rl.on("line", (input) => {
    if (!numberOfMagnets) {
        numberOfMagnets = parseInt(input.split(" "));
        //console.log(typeof(numberOfMagnets),numberOfMagnets)
    } else if (numberOfMagnets) {
        counter++;
        let temp = input.split(" ").toString();
        switch (temp) {
            case minusPlus:
                if(flag === true)
                groupCounter++ , flag= false;
                break;
            case plusMinus :
                if(flag === false)
                groupCounter++ , flag= true;

                break;
            default:
                break;
        }

        if (counter === numberOfMagnets) {
            console.log(counter, "\n")
            rl.close();
            console.log(groupCounter)
        }
    }

});

// if (temp === plusMinus) {
    //     groupCounter++
    //     flag = true
    // }
    // if (temp === minusPlus) {
    //     groupCounter++
    //     flag = false;
    // }

const readline = require("readline")

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

let numberOfMagnets = 0;
let plusMinus = "01";
let minusPlus = "10";
let groupCounter = 0;
let flag = false;
let counter = 0;
rl.on("line", (input) => {
    if (!numberOfMagnets) {
        numberOfMagnets = parseInt(input.split(" "));
        rl.pause();
        //console.log(typeof(numberOfMagnets),numberOfMagnets)
    }
    if (numberOfMagnets) {
        rl.resume();
        counter++;
        let temp = input.split(" ").toString();
        if (temp === plusMinus && flag === false) {
            groupCounter++
            flag = true
        }
        if (temp === minusPlus && flag === true) {
            groupCounter++
            flag = false;
        }

        if (counter > numberOfMagnets) {
            rl.close();
            console.log(groupCounter)
        }
    }

});

const readline = require("readline")

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

let numberOfMagnets = 0;
let plusMinus = "01";
let minusPlus = "10";
let groupCounter = 0;
let flag = true;
let counter = 0;
rl.on("line", (input) => {
    if (!numberOfMagnets) {
        numberOfMagnets = parseInt(input.split(" "));
        //console.log(typeof(numberOfMagnets),numberOfMagnets)
    } else if (numberOfMagnets) {
        counter++;
        let temp = input.split(" ").toString();
        switch (temp) {
            case minusPlus:
                if(flag === true)
                groupCounter++ , flag= false;
                break;
            case plusMinus :
                if(flag === false)
                groupCounter++ , flag= true;

                break;
            default:
                break;
        }

        if (counter === numberOfMagnets) {
            //console.log(counter, "\n")
            rl.close();
            console.log(groupCounter)
        }
    }

});

// if (temp === plusMinus) {
    //     groupCounter++
    //     flag = true
    // }
    // if (temp === minusPlus) {
    //     groupCounter++
    //     flag = false;
    // }

const readline = require('readline');

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

let magnetNo;
let counter = 0;
let lastChar = '';
let groups = 1;

rl.on('line', (input) => {
    if (counter === 0) {
        magnetNo = parseInt(input);
        counter++;
        return;
    }
    if (counter === magnetNo) {
        rl.close();
        console.log(groups);
        return;
    }
    counter++;
    let currentChar = input[0];
    groups = (lastChar === '' || lastChar !== currentChar) ? groups : groups + 1;
    lastChar = input[1];

});

const solve = () => {

};

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

/******** Main function*************/

function isLowerCase(str) {
  return str == str.toLowerCase() && str != str.toUpperCase();
}

function main() {
  var n = +readLine();
  var arr = [];
  for (var i = 0; i < n; i++) {
    var m = +readLine();
    arr.push(m);
  }

  var newArr = [];
  var count = 0;

  for (var j = 0; j < n; j++) {
    if (arr[j] == arr[j + 1]) {
      count++;
    } else {
      newArr.push(count);
      count = 0;
    }
  }

  var max = Math.max(...newArr) + 1;
  console.log(max);
}

// either it only contains uppercase letters;
// or all letters except for the first one are uppercase.

var readline = require("readline")
var rl = readline.createInterface(process.stdin,process.stdout);
var n;
var l=0;
var magnets = [];
var groups = 0;
rl.question('',function(data){
      n = parseInt(data);
      //rl.prompt()
      rl.on("line",function(mag){
            magnets.push(mag.toString().trim())
            l++;
            if(l == n){
                  rl.close();
            }
      });
})
rl.on('close',function(){
      for (let i = 0; i < n-1; i++) {
            //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));
            if (magnets[i].charAt(1)!=magnets[i+1].charAt(0)){
                  groups++;
            }
      }
      if(groups > 0){
            console.log(groups);
      } else {
            console.log(groups+1);
      }
})

var readline = require("readline")
var rl = readline.createInterface(process.stdin,process.stdout);
var n;
var l=0;
var magnets = [];
var groups = 0;
rl.question('',function(data){
      n = parseInt(data);
      //rl.prompt()
      rl.on("line",function(mag){
            magnets.push(mag.toString().trim())
            l++;
            if(l == n){
                  rl.close();
            }
      });
})
rl.on('close',function(){
      for (let i = 0; i < n-1; i++) {
            //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));
            if (magnets[i].charAt(1)!=magnets[i+1].charAt(0)){
                  groups++;
            }
      }
      console.log(groups);
})

var readline = require("readline")
var rl = readline.createInterface(process.stdin,process.stdout);
var n;
var l=0;
var magnets = [];
var groups = 0;
rl.question('',function(data){
      n = parseInt(data);
      rl.prompt()
      rl.on("line",function(mag){
            magnets.push(mag.toString().trim())
            l++;
            if(l == n){
                  rl.close();
            }
      });
})
rl.on('close',function(){
      for (let i = 0; i < n-1; i++) {
            //console.log (magnets[i].charAt(1),magnets[i+1].charAt(0));
            if (magnets[i].charAt(1)!=magnets[i+1].charAt(0)){
                  groups++;
            }
      }
      console.log(groups);
})

'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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    let a = readLine();
    let ans = 1;
    for (var i = 0; i < n; i++) {
        let b = readLine();
        if (a != b) {
            b = a;
            ans++;
        }
    }
    console.log(ans);
}

var n = +readline();
var res = 0;
var last = 'x';

while (n) {
    var str = readline();
    if (str[0] === last) res++;
    last = str[1];
    n --;
}

var n = +readline();
var res = 0;
var last = 'x';

while (n) {
    var str = readline();
    if (str[0] === last) res++;
    last = str[1];
    n --;
}

print(res);

var m = 0;
var x="";
var y;
var n = parseInt(readline());

for(var i=0 ; i<n ;i++){
    y=readline();
    print('i='+i+" x="+x +" y="+y+" m="+m);
    if(x != y){
        x=y
        m++;
    }
    print('i='+i+" x="+x +" y="+y+" m="+m);
}
print(m);

var noOfMagnets=Number(readline());
var counter=0;
var firstValue;
var secondValue;

for(var i =0 ; i< noOfMagnets ; i++ )
{
   if(firstValue != secondValue){
       counter=counter+1;
       secondValue = firstValue;
   }

}

print(counter);

var input = parseInt(readline());
var count = 0;
var prev;
while(input>0){
    var ins = readline();
    if(!prev) prev = ins;
    else if(prev != ins)count++;
    input--;
}
print(count);

var input = parseInt(readline());
var count = 0;
var prev;
while(input>0){
    var ins = readline();
    if(!prev) prev = ins;
    else if(prev != ins){
        count++;
        prev = ins;
    }
    input--;
}
print(count);

var size = readline(),
	counter = 0,
	hasChanged = false,
	lastMagnet = readline();

for(var index = 1; index < size; index ++){
	var currentMagnet = readline();
	if( lastMagnet === currentMagnet ){
		//has to be change
		counter ++;
		lastMagnet = currentMagnet.split("").reverse().join("");
	}
}

print(counter);

/*var size = readline(),
	counter = 1,
	hasChanged = false,
	lastMagnet = readline();

for(var index = 1; index < size; index ++){
	var currentMagnet = readline();
	if( lastMagnet === currentMagnet ){
		//has to be change
		counter ++;
		lastMagnet = currentMagnet;
	}
}

print(counter);*/

print(readline()/2)

/*var size = readline(),
	counter = 1,
	hasChanged = false,
	lastMagnet = readline();

for(var index = 1; index < size; index ++){
	var currentMagnet = readline();
	if( lastMagnet === currentMagnet ){
		//has to be change
		counter ++;
		lastMagnet = currentMagnet;
	}
}

print(counter);*/

print(Math.ceil(readline()/2))

var size = readline(),
	counter = 0,
	hasChanged = false,
	lastMagnet = undefined;

for(var index = 0; index < size; index ++){
	var currentMagnet = readline();
	if( lastMagnet === currentMagnet ){
		//has to be change
		counter ++;
		lastMagnet = currentMagnet;
	}
}

print(counter);

var n = Number(readline());
var count = 1;
for(var i = 0; i < n; i++) {
    var str = readline();
    if (i!==0 && str[i] !== str[i-1]) {
        count++;
    }
}
print(count);

var n = readline();
var temp = 0;
var res = 1;
	for (var i=0; i<+n; i++){
		var str = readline();
		if (str!=temp) res++;
		temp = str;
	}
	print(res);

var arr = [], count = 0, inputs, ch = ' ';
inputs = readline();

while (inputs !== 0) {

    arr = readline();
    if (arr[0] === ch) {
        count++;
    }
    ch = arr[1];
    inputs--;
}
print(count);

var numLines = readline();
var lastLine = '';
var blocks = 0;
for(var i = 0; i < numLines; i++)
{
    var currentLine = readline();
    if(currentLine !== lastLine) blocks++
}

print(blocks);

var main = function(arr)
{
    var c = 0;
    for (var i = 1; i < arr.length; i++)
    {
       if (arr[i] !== arr[i - 1]) c++;
    }
    return c;
}

{
    var input1 = readline(), arr = [];
    for (var i = 1; i <= +input1; i++)
    {
        var aElem = readline();
        arr.push(aElem);
    }
    print(main(arr))
}

var main = function(arr)
{
    var c = 0;
    for (var i = 1; i < arr.length; i++)
    {
       if (arr[i] !== arr[i - 1]) c++;
    }
    return c;
}

{
    var inopt = readline();
    var input1 = readline(), arr = [];
    for (var i = 1; i <= +input1; i++)
    {
        var aElem = readline();
        arr.push(aElem);
    }
    print(main(arr))
}

var main = function(arr)
{
    var c = 1;
    for (var i = 1; i < arr.length; i++)
    {
       if (arr[i] !== arr[i - 1]) c++;
    }
    return c;
}

{
    var inopt = readline();
    var input1 = readline(), arr = [];
    for (var i = 1; i <= +input1; i++)
    {
        var aElem = readline();
        arr.push(aElem);
    }
    print(main(arr))
}

var num=parseInt(readline());
// print(num)
var arr=[];

for(var i=0;i<num;i++){
  var mag=(readline());
  arr.push(mag)

}

print(arr);
var count=0;
var mag_check=arr[0];

for(var j=0;j<arr.length;j++){
  if(mag_check==arr[j+1]){
    count=count;
    mag_check=arr[j+1];
  }else{
    count=count+1;
    mag_check=arr[j+1];
  }
}
print(count);

n = readline().split('').map(function(item) {
    return parseInt(item);
});
base = '00';
groups = 0;
for (i=0;i<n;i++){
	next = readline();
	if (next != base){
		groups++;
	}
	base = next;
}
print(groups)

n = readline().split('').map(Number);
base = '00';
groups = 0;
for (i=0;i<n;i++){
	next = readline();
	if (next != base){
		groups++;
	}
	base = next;
}
print(groups)

n = +readline().split('').map(Number);
base = '00';
groups = 0;
for (i=0;i<n;i++){
	next = +readline();
	if (next != base){
		groups++;
	}
	base = next;
}
print(groups)

n = readline().split('').map(function(item) {
    return parseInt(item, 10);
});
base = '00';
groups = 0;
for (i=0;i<n;i++){
	next = readline();
	if (next != base){
		groups++;
	}
	base = next;
}
print(groups)

const main = () => {
  const n = readline();
  const arr = [];
  var total = 1;

  for (i of Array(Number(n))
    .fill()
    .map((a, b) => parseInt(b))) {
    arr.push(readline());
  }

  for (i of Array(Number(n - 1))
    .fill()
    .map((a, b) => parseInt(b))) {
    if (arr[i] != arr[i + 1]) {
      total++
    }
  }

  print(total);
};

var r = readline();
var s=0;
var x1 =readline();
for(var i = 0; i< r-1;i++){
    var x2 = readline();
    if (x1[1] == x2[0]){
        s++;
    }
    x1=x2;
}
print(s);

var r = readline();
var s=0;
var x1 =readline();
for(var i = 0; i< r-1;i++){
    var x2 = readline();
    if (x1[1] == x2[0]){
        s++;
    }
}
print(s);

var r = readline();
var s=0;
var x1 =readline();
for(var i = 0; i< r-1;i++){
    var x2 = readline();
    if (x1[1] == x2[0]) {
        s++;
    }
}
print(s);

var n = readline();
var magnets = [], counter = 0;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
    print(typeof magnets[0])
}
magnets.forEach((item, index, arr) => {
    if(item[1] === arr[index+1]) counter++;
})
print(counter);

var n = readline();
var magnets = [], counter = 1;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
}
magnets.forEach((item, index, arr) => {
    if(item[1] === arr[index+1] ? arr[index+1][0] : null) counter++;
})
print(counter);

var n = readline();
var magnets = [], counter = 0;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
}
magnets.forEach((item, index, arr) => {
    if(item[1] === arr[index+1]) counter++;
})
print(counter);

var n = readline();
var magnets = [], counter = 0;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
}
magnets.forEach((item, index, arr) => {
    if(item[1] === arr[index+1] ? arr[index+1][0] : null) counter++;
})
print(counter);

var n = readline();
var magnets = [], counter = 0;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
    print(magnets)
}
magnets.forEach((item, index, arr) => {
    if(item[1] === arr[index+1]) counter++;
})
print(counter);

var n = readline();
var magnets = [], counter = 0;
for(var i = 0; i < n; i++){
    var magnet = readline();
    magnets.push(magnet);
}
magnets.forEach((item, index, arr) => {
    if(item[1] === (arr[index+1] ? arr[index+1][0] : null)) counter++;
})
print(counter);

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

for(var x = 0;x<count;x++){read[x] = readline();}

for(var i = 0;i<count;i++){
	if(i > 0){if(read[i][0] == read[i - 1][1]){calc+=1}}
}

if(calc != 0){calc += 1};print(calc);

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

for(var x = 0;x<count;x++){read[x] = readline();}

for(var i = 0;i<count;i++){
	if(i > 0){if(read[i][1] == read[i - 1][1]){calc+=1}}
}

print(calc);

var nums = parseInt(readline());

var prev = null;
var block = 0; //block not gap
for (var i = 0; i < nums.length; i++) {
    var current = parseInt(readline());

    if (current !== prev) {
        block++;
    }

    prev = current;
}

print(block);


var getVals = function () { return readline().split(' '); };

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

//131b
var n = parseInt(readline());
var data = getNums();
var hash = {};
var res = 0;

for(var i = 1; i <= 10; i++) {
    hash[i] = 0;
    hash["-" + i] = 0;
}
hash[0] = 0;

for(var i = 0; i < n; i++) {
    hash[data[i]]++;
}

for(var i = 1; i <= 10; i++) {
    res += hash[i] * hash[-i];
}

if (hash[0] > 1) {
    for(var i = 1; i < hash[0]; i++) {
        res += i;
    }
}

print(res);

;(function () {

	print((function (n) {
		var ret = 0, m = {};
		readline().split(' ').map(function (e, i) {
			e = Number(e);
			m[e] = m[e] ? m[e] + 1 : 1;
		});

		for (var key in m) {
			if (key < 0) {
				if (!m[-key]) break;
				ret += m[key] * m[-key];
			} else if (key == 0 && m[key] > 1) {
				ret += m[key] * (m[key] - 1) / 2;
			}
		}

		return ret;
	}).apply(0, [+readline()]));

}).call(this);


const solve = arr=>{
    arr.reverse();
     let x = 1;
     let ans = 0;
     while(x<arr.length-1){
          if(arr[1]===arr[x+1]){
               x++;
          }
          else{
               ans++;
               x*=2;
          }
     }
     console.log(ans);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = [...readline().trim().split(" ").map(cur=>parseInt(cur)),0]
       solve(arr);
  }
}
main();

const fs = require('fs');
const input = fs.readFileSync(0, 'utf8').trim().split('\n');
let currentline = 0;
function readline(){
    return input[currentline++];
}

var T = readline();
for(var q=1;q<=T;q++) {
            var g = readline();
            var a = readline().split(" ").map(w => parseInt(w))
            var n = a.length-1;
            var ref = a[n]
            var ans = 0;
            for(var i=n-1;i>=0;i--) {
            	if(a[i]==ref) continue;
            	var j = i;
            	var len = n-i;
            	var lim = Math.max(0, (i-len)+1);
            	var cnt = 0;
            	while(j >= lim) {
            		if(a[j] !== ref) {
            			cnt++;
            		}
            		j--
            	}
            	if(cnt > 0) {
            		ans++;
            	}
            	i=j+1;
            }
            console.log(ans)
}

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = readline().split(' ').map(x=>parseInt(x));

        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(steps);

        }
        zombiesF(m)
    }
}

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});

process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0]);
  let i = 1;
  while (t--) {
    let n = parseInt(lines[i++]);
    let arr = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    arr.reverse();
    let x = 0;
    let count = 0;
    while (x < n) {
      if (arr[x] === arr[0]) {
        x++;
      } else {
        x *= 2;
        count++;
      }
    }
    console.log(count);
  }
});

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = readline().split(' ').map(x=>parseInt(x));

        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(m);

        }
        zombiesF(m)
    }
}

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = readline().split(' ');
        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(m);

        }
        zombiesF(m)
    }
}

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = parseInt(readline());
        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(n);

        }
        zombiesF(m)
    }
}

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = parseInt(readline());
        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(m);

        }
        zombiesF(m)
    }
}

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = parseInt(readline());
        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(steps, n, m ,'hello');

        }
        zombiesF(m)
    }
}

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

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

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    let input = parseInt(readline());
    while(input--){
        let n = parseInt(readline()), m = parseInt(readline());
        function zombiesF(arr){
            let zombies = arr[arr.length-1],zc =1, steps = 0;

            while(zc<arr.length){

                if(arr[arr.length-1-zc] == zombies){
                    zc++;
                    continue;
                }

                steps++;
                zc*=2

            }

            print(steps)

        }
        zombiesF(m)
    }
}

const solve = arr=>{
     let cnt = 0;
     const binaryserach = (start,end)=>{
          if(end-start===1) return arr[start];
          let mid = Math.floor((start+end)/2);
          let check = binaryserach(mid,end);
          for(let i=start;i<mid;i++){
               if(arr[i]!==check){
                    cnt++;
                    break;
               }
          }
          return check;
     }
     binaryserach(1,arr.length);
     console.log(cnt);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = [0,...readline().trim().split(" ").map(cur=>parseInt(cur))]
       solve(arr);
  }
}
main();

const solve = arr=>{
     let cnt = 0;
     const binaryserach = (start,end)=>{
          if(end-start===1) return arr[start];
          let mid = Math.floor((start+end)/2);
          let check = binaryserach(mid,end);
          for(let i=start;i<=mid;i++){
               if(arr[i]!==check){
                    cnt++;
                    break;
               }
          }
          return check;
     }
     binaryserach(0,arr.length);
     console.log(cnt);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr);
  }
}
main();

const solve = arr=>{
    let cnt = 0;
     const binaryserach = (start,end)=>{
          if(end===start) return arr[end];
          let mid = Math.floor((start+end)/2);
          let check = binaryserach(mid+1,end);
          for(let i=start;i<=mid;i++){
               if(arr[i]!==check){
                    cnt++;
                    break;
               }
          }
          return check;
     }
     binaryserach(0,arr.length-1);
     console.log(cnt);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr);
  }
}
main();

const solve = arr=>{
     let cnt = 0;
     const binaryserach = (start,end)=>{
          if(end-start===1) return arr[start];
          let mid = Math.floor((start+end)/2);
          let check = binaryserach(mid,end);
          for(let i=start;i<mid;i++){
               if(arr[i]!==check){
                    cnt++;
                    break;
               }
          }
          return check;
     }
     binaryserach(0,arr.length);
     console.log(cnt);
}
function main() {
  const fs = require("fs");
  const input = fs.readFileSync(0, "utf8").trim().split("\n");
  let line = 0;
  function readline() {
    return input[line++];
  }
  let t = parseInt(readline());
  for(let i=0;i<t;i++){
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       solve(arr);
  }
}
main();

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});

process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0]);
  let i = 1;
  while (t--) {
    let n = parseInt(lines[i++]);
    let arr = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    let max = 0;
    let l, k;
    for (let j = 0; j < n; j++) {
      let stretch = 0;
      for (let p = j; p < n; p++) {
        if (arr[j] !== arr[p]) {
          break;
        }
        stretch++;
      }
      if (stretch > max) {
        max = stretch;
        l = j;
        k = stretch;
      }
    }
    let count = 0;
    let pos = l + k;
    while (pos < n) {
      pos = pos + k;
      k = k * 2;
      count++;
    }
    k = n - l;
    for (let pos = l; pos > 0; pos -= k) {
      k = k * 2;
      count++;
    }
    console.log(count);
  }
});

let input = "";
process.stdin.on("data", (chunk) => {
  input += chunk;
});

process.stdin.on("end", () => {
  let lines = input.trim().split("\n");
  let t = parseInt(lines[0]);
  let i = 1;
  while (t--) {
    let n = parseInt(lines[i++]);
    let arr = lines[i++]
      .trim()
      .split(" ")
      .map((element) => parseInt(element));
    let max = 0;
    let l, k;
    for (let i = 0; i < n; i++) {
      let stretch = 0;
      for (let j = i; j < n; j++) {
        if (arr[i] !== arr[j]) {
          break;
        }
        stretch++;
      }
      if (stretch > max) {
        max = stretch;
        l = i;
        k = stretch;
      }
    }
    let m = l + k - 1;
    let count = 0;
    while (l > 0) {
      l = Math.max(l - k, 0);
      k = m - l + 1;
      count++;
    }
    while (m < n - 1) {
      m = m + k;
      k = m - l + 1;
      count++;
    }
    console.log(count);
  }
});


//JavaScript-C24.2.0 (SpiderMonkey)

var str = readline();
var arr = [];
var mySentence = [];
var mySentenceCopy = [];

for(var i=0; i<str.length;i++) {
    mySentence.push(str[i]);
}

function isPuncOrSpace(character) {
    return character==',' || character=='.' || character=='?' || character=='!' || character==' ';
}

var i=0;
while(i<mySentence.length) {

    if(isPuncOrSpace(mySentence[i])) {
        var count = 0;
        while(isPuncOrSpace(mySentence[count+i])) {
            count++;
        }
        var spacePuns = mySentence.slice(i,count+i);
        if(spacePuns.indexOf('.')!=-1) {
             mySentenceCopy.push('.');
             mySentenceCopy.push(' ');
        }
        else if(spacePuns.indexOf(',')!=-1) {
             mySentenceCopy.push(',');
             mySentenceCopy.push(' ');
        }
        else if(spacePuns.indexOf('!')!=-1) {
             mySentenceCopy.push('!');
             mySentenceCopy.push(' ');
        }
        else if(spacePuns.indexOf('?')!=-1) {
             mySentenceCopy.push('?');
             mySentenceCopy.push(' ');
        }
        else
             mySentenceCopy.push(' ');
        i = count+i;
    }
    else  {
      mySentenceCopy.push(mySentence[i]);
      i++;
    }
}
var mes = "";

for(var i=0; i<mySentenceCopy.length; i++) {
    mes+=mySentenceCopy[i];
}
print(mes)

str = readline();
str = str.replace(/  +/g, ' ');
str = str.replace(/ ([,!?.])/g, '$1 ');
str = str.replace(/([,!?.])/g, '$1 ');
str = str.replace(/  +/g, ' ');
write(str)

//JavaScript-C24.2.0 (SpiderMonkey)

var str = readline();
var arr = [];
var mySentence = [];

for(var i=0; i<str.length;i++) {
    mySentence.push(str[i]);
}

var mySentenceCopy = mySentence.slice();

function isPuncOrSpace(character) {
    return character==',' || character=='.' || character=='?' || character=='!' || character==' ';
}

for(var i=0; i<str.length; i++) {
    if(isPuncOrSpace(str[i]))
        arr.push('p');
    else
        arr.push('l');
}

var i=0;
while(i<mySentence.length) {

    if(arr[i]=='p') {
        var count = 0;
        while(arr[count+i]=='p') {
            count++;
        }
        var spacePuns = mySentence.slice(i,count+i);
        if(spacePuns.indexOf('.')!=-1)
             mySentenceCopy.splice(i,count,'. ');
        else if(spacePuns.indexOf(',')!=-1)
             mySentenceCopy.splice(i,count,', ');
        else if(spacePuns.indexOf('!')!=-1)
             mySentenceCopy.splice(i,count,', ');
        else if(spacePuns.indexOf('?')!=-1)
             mySentenceCopy.splice(i,count,'? ');
        else
             mySentenceCopy.splice(i,count,' ');

        i = count+i;
    }
    else
      i++;
}
var mes = "";

for(var i=0; i<mySentenceCopy.length; i++) {
    mes+=mySentenceCopy[i];
}
print(mes)

str = readline();
str = str.replace(/  +/g, ' ');
str = str.replace(/ ,/g, ', ');
str = str.replace(/,/g, ', ');
str = str.replace(/  +/g, ' ');
write(str)


var t = readline();
while(t--) {
    var a = readline().split(" ").map(function(num) {
        return parseInt(num)
    });
    print((23 - a[0]) * 60 + (60 - a[1]));
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const t = readInt(arr)

  for(let j = 0; j < t; j++) {
    const [h, m] = readInts(arr, j)
    const ans = (24 - h) * 60 - m
    wr(ans)
  }
})

function wr(...x) {
  console.log(...x)
}

function sort(a, inc = true) {
  if(inc) a.sort((a, b) => a - b)
  else a.sort((a, b) => b - a)
}

function readInt(a, i) {
  if(i === undefined) return parseInt(a.shift())
  else return parseInt(a[i])
}
function readInts(a, i) {
  if(i === undefined) return arr.shift().split(' ').map(a => parseInt(a))
  else return arr[i].split(' ').map(a => parseInt(a))
}

//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');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
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 tmp = nextIntArray();
  	output[i] = 1440 - (tmp[0] * 60 + tmp[1]);
  }
  myout(myconv(output, 9));
}

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

let c = 0;

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

  const [h, m] = d.split(" ").map(Number);
  let ans = 0;
  let r = m === 0 ? 0 : 1;

  ans += m === 0 ? 0 : 60 - m;
  ans += (24 - r - h) * 60;

  console.log(ans);
  c++;
});

'use strict';

const fs = require('fs');

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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let t = parseInt(readLine(), 10);
    let i, h, m;

    for(i=1; i<=t; i++) {
        let inputs = readLine();
        inputs = inputs.split(' ');
        h = parseInt(inputs[0], 10);
        m = parseInt(inputs[1], 10);

        let totalMin = (23-h)*60 + 60-m;
        console.log(totalMin);
    }
}

var n=Number(readline());
for(var i=0;i<n;i++){
	var h=readline().split(" ");
	print(((23-Number(h[0]))*60)+(60-Number(h[1])));
}
//balda solve hoyna kno
//bal chal problem amar

var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)
var write = this.write || require('lol-io').write; //write --> creates output.txt with output
var readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt

var t, time, ans;

t = Number(readline());

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

    time = readline().replace(/\r$/, '').split(' ').map(Number);
    ans = 24 * 60;
    ans -= time[0] * 60 + time[1];

    print(ans);
}

var day = 1440;
var t = 0;
t = parseInt(readline());
for (var i=0;i<t;i++) {
var currentHour = 0;
var currentMin = 0;
var num = readline().split(" ").map(x => parseInt(x));
currentHour = num[0];
currentMin = num[1];
var CurrentTime = parseInt(currentHour) * 60 + parseInt(currentMin);
print(parseInt(day)-parseInt(CurrentTime));
}

var cant = readline();

for (var i=0; i < cant; i++) {
    var numbers = readline().split(" ").map(function(x) { return parseInt(x); });
    var hours = numbers[0];
    var minutes = numbers[1];
    var toRet = 0;
    if(hours >= 0 ){
        toRet = (23-hours)*60;
    }
    if(minutes >= 0)
        toRet += 60-minutes;
    print(toRet);
}

'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 readALine() {
    return inputString[currentLine++];
}

function printALine(str) {
    console.log(str);
}

function stringArrayToNumbers(str) {
    var array = str.split(" ");
    var result = [];
    for( var i = 0; i < array.length; i++ ) {
        result.push( parseInt(array[i]) );
    }
    return result;
}

// ======================================================
// A. Minutes Before the New Year
// https://codeforces.com/problemset/problem/1283/A
// ======================================================

// hours = number of hours left
// min = number of minutes left.
function doIt( hours, min ) {

    var result = 0;

    var result1 = 60 - min;
    var result2 = 0;

    if( 1 + hours < 24 ) {
        result2 = (24 - (1 + hours)) * 60;
    }

    return result1 + result2;

}

function main() {

    var numOfTests = readALine();
    for( var i = 0; i < numOfTests; i++ ) {

        var string1 = readALine();
        var arr1 = stringArrayToNumbers(string1);

        var result = doIt( arr1[0], arr1[1] );

        printALine(result);

    }

}

const data = readline().split(" ").map(x => parseInt(x));
const t = data[0];
var timeArray=[];
for (var i=0; i<t; i++) {
    var time = readline().split(" ").map(x => parseInt(x));
    var minutes = time[0] * 60 + time[1];
    print(1440 - minutes);
}

var n = parseInt(readline());
while(n--){
  var z = readline();
  var t = z.split(' ').map(e => parseInt(e));
  print((23-t[0])*60+60-t[1]);
}

'use strict'

const problem = (h, m) => 1440 - h*60 - m;
let q = +readline();
while(q--) print(problem(...readline().split(' ').map(Number)))

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var hhmm = readline().split(' ').map(Number);
    var hh = hhmm[0];
    var mm = hhmm[1];
    print((23 - hh) * 60 + 60 - mm)
  }
}
main()

  var t = Number(readline());

  while (t--) {
    var input = readline().split(' ').map(function(x) {
        return parseInt(x);
      });
    var h = input[0];
    var m = input[1];
    var result = 1440 - (h * 60 + Number(m));
    print(result);
  }

"use strict";

let inputNumber = +readline();
let dates = [];
let output = [];

for (let i = 0; i < inputNumber; i++) {
	dates[i] = readline();
	dates[i] = dates[i].split(" ").map(function(item){ return +item; });
	let hours = dates[i][0];
	let mins = dates[i][1];
	output[i] = (24 - hours) * -60 + mins;
}

for (let i = 0; i < inputNumber; i++) {
	print(-output[i]);
}

'use strict';

const fs = require('fs');

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.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main(inputString);
});

function main(inputString) {
    let index = 0;
    let tests = inputString[index++];

    for (let i = 0; i < tests; ++i) {
        let curTime = inputString[index++].split(' ');
        console.log(minsRemained(curTime))
    }
}

function minsRemained(curTime) {
    return parseInt((24 - curTime[0] - 1)*60) + parseInt(60 - curTime[1]);
}

  var t = readline();
  while (t--) {
    var h = readline();
    var m = readline();
    var result = 1440 - (h * 60 + Number(m));
    print(result);
  }

  var t = Number(readline());
  while (t--) {
    var h = Number(readline());
    var m = Number(readline());
    var result = 1440 - (h * 60 + Number(m));
    print(result);
  }

var n=Number(readline());
for(var i=0;i<n;i++){
	var h,m=readline().split(" ");
	print(((23-h)*60)+(60-m));
}
//balda solve hoyna kno
//bal chal problem amar

var n=Number(readline());
for(var i=0;i<n;i++){
	var h,m=readline().split(" ");
	print((23-Number(h)*60)+(60-Number(m)));
}
//balda solve hoyna kno
//bal chal problem amar

var day = 1440;
var t = readline();
for (var i=0;i<t;i++) {
var currentHour = parseInt(readline());
var currentMin = parseInt(readline());
CurrentTime = (currentHour) * 60 + (currentMin);
print(day-CurrentTime);
}

const data = readline().split(" ").map(x => parseInt(x));
const t = data[0];
var timeArray=[];
for (var i=0; i<t; i++) {
    var time = readline().split(" ").map(x => parseInt(x));
    const minutes = time[0] * 60 + time[1];
    timeArray.push(1440 - minutes);
}
print(timeArray);

const data = readline().split(" ").map(x => parseInt(x));
const t = data[0];
var timeArray=[];
for (var i=0; i<t; i++) {
    var time = readline().split(" ").map(x => parseInt(x));
    var minutes = time[0] * 60 + time[1];
    timeArray.push(1440 - minutes);
}
print(timeArray);


function solve() {
    read();
   var [n, m] = readArray(Number);
   var arr = [];
   for (var i = 0; i < m; i++) {
      var [x, w] = readArray(Number);
      arr.push({
         x,
         w,
         i: i + 1
      });
   }
   arr.sort(f1);
   arr = arr.slice(0, 2 * n);
   arr.sort(f2);
   var sum = 0;
   var ans = [];
   for (var i = 0; i < n; i++) {
      sum += arr[i].w;
      ans.push([arr[i].i]);
   }
   for (var i = 0; i < n; i++) {
      sum += arr[2 * n - i - 1].w;
      ans[i].push(arr[2 * n - i - 1].i);
   }
   write(sum);
   for (var i = 0; i < n; i++) {
      write(ans[i].join(' '));
   }
   write('');
}

function f1(a, b) {
    return a.w - b.w;
}
function f2(a, b) {
    return a.x - b.x;
}

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

try {
    initInput(start);
} catch (e) {
    console.log(e);
}

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

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

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

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, m] = rna();
		let points = [];
		for (let i = 0; i < m; i++) {
			const [x, w] = rna();
			points.push({pos: x, wt: w, id: i+1})
		}

		points.sort((x, y) => x.wt - y.wt);
		points = points.slice(0, 2*n);
		points.sort((x, y) => x.pos - y.pos);

		let sum = 0;
		for (let i = 0; i < 2*n; i++) sum += points[i].wt;
		console.log(sum);

		for (let i = 0; i < n; i++) {
			console.log(points[i].id, points[2*n-i-1].id);
		}
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, m] = rna();
		let points = [];
		for (let i = 0; i < m; i++) {
			const [x, w] = rna();
			points.push([x, w, i+1]);
		}

		points.sort((x, y) => x[1] - y[1]);
		points = points.slice(0, 2*n);

		points.sort((x, y) => x[0] - y[0]);

		let sum = 0;
		for (let i = 0; i < 2*n; i++) sum += points[i][1];
		console.log(sum);

		for (let i = 0; i < n; i++) {
			console.log(points[i][2], points[2*n-i-1][2]);
		}
	}
}

function solve() {
    read();
   const [n, m] = readArray(Number);
   let arr = [];
   for (let i = 0; i < m; i++) {
      const [x, w] = readArray(Number);
      arr.push({
         x,
         w,
         i: i + 1
      });
   }
   arr.sort((a, b) => a.w - b.w);
   arr = arr.slice(0, 2 * n);
   arr.sort((a, b) => a.x - b.x);
   let sum = 0;
   const ans = [];
   for (let i = 0; i < n; i++) {
      sum += arr[i].w;
      ans.push([arr[i].i]);
   }
   for (let i = 0; i < n; i++) {
      sum += arr[2 * n - i - 1].w;
      ans[i].push(arr[2 * n - i - 1].i);
   }
   write(sum);
   for (let i = 0; i < n; i++) {
      write(ans[i].join(' '));
   }
   write('');
}

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

try {
    initInput(start);
} catch (e) {
    console.log(e);
}

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

function solve() {
   read();
   const [n, m] = readArray(Number);
   let arr = [];
   for (let i = 0; i < m; i++) {
      const [x, w] = readArray(Number);
      arr.push({
         x,
         w,
         i: i + 1
      });
   }
   arr.sort((a, b) => a.w - b.w);
   arr = arr.slice(0, 2 * n);
   arr.sort((a, b) => a.x - b.x);
   let sum = 0;
   const ans = [];
   for (let i = 0; i < n; i++) {
      sum += arr[i].w;
      ans.push([arr[i].i]);
   }
   for (let i = 0; i < n; i++) {
      sum += arr[2 * n - i - 1].w;
      ans[i].push(arr[2 * n - i - 1].i);
   }
   write(sum);
   for (let i = 0; i < n; i++) {
      write(ans[i].join(' '));
   }
   write('');
}

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

function pDivCount(n) {
   let ans = 0;
   let i = 1;
   while(n > 1) {
      i++;
      while(n % i === 0) {
         ans++;
         n = Math.floor(n / i);
      }
   }
   return ans;
}

function gcd(a, b) {
   if (a === 0) {
      return b;
   }
   return gcd(b % a, a);
}

function lcm(a, b) {
   return Math.floor(a / gcd(a, b)) * b;
}

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

function readArray(mapF) {
   var res = read().split(' ');
   if (mapF) {
      res = res.map(mapF);
   }
   return res;
}

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

   var inTextName;
   var outTextName;
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }
   MEMORY = fs.readFileSync(inTextName ? require('path').join(__dirname, inTextName) : 0, 'utf8').split('\r\n');
}
init();

function write(value) {
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   if (isNode) {
      return MEMORY;
   }
   var res = [];
   var x;
   while (x = read()) {
      res.push(x);
   }
   return res;
}

const readline = require('readline')

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

function solve(n, m, arr) {
    arr = arr
        // .sort((a, b) => a[0] - b[0])
        .map(([x, w], i) => ({ x, w, i: i + 1}))
        .sort((a, b) => a.w - b.w)
    let ans = 0
    const xs = Array(2 * n)
    for (let i = 0; i < 2 * n; i++) {
        ans += arr[i].w
        xs[i] = arr[i]
    }
    xs.sort((a, b) => a.x - b.x)
    const pairs = Array(n)
    for (let i = 0; i < n; i++) {
        pairs[i] = xs[i].i + ' ' + xs[2 * n - 1 - i].i
    }
    return ans + '\n' + pairs.join('\n')
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    readline();
    let [n, m] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = [];
    for (let i = 0; i < m; i++) {
      arr.push(
        readline()
          .trim()
          .split(" ")
          .map((cur) => parseInt(cur))
      );
    }
    for (let i = 0; i < m; i++) {
      let obj = { val: arr[i][0], w: arr[i][1], ind: i };
      arr[i] = obj;
    }
    arr.sort((a,b)=>a.w - b.w);
    let narr = [],total = 0;
    for(let i=0;i<n*2;i++) {
      narr.push(arr[i]);
      total+=arr[i].w;
    }
    narr.sort((a,b)=>a.val - b.val);
    console.log(total);
    let i=0,j = n*2 - 1;
    while(i<n) console.log(`${narr[i++].ind + 1} ${narr[j--].ind + 1}`);

  }
};
solve();

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

module.exports = E;

const ra = ()=>readline().split(' ').map(a=>+a)

const EPS = 1e-6;

const calc = (n, m, arr)=>{
  arr = arr.map((a, i)=>({w: a[1], x: a[0], i})).sort((a, b)=>a.w-b.w)
  //console.log(n, m, arr)
  let slice = arr.slice(0, 2*n);
  slice.sort((a, b)=>a.x-b.x);
  let ans_arr = [];
  let ans_sum = 0;
  for (let i=0; i<n; i++){
    let beg = slice[i];
    let end = slice[n*2-i-1];
    ans_arr.push((beg.i+1)+' '+(end.i+1));
    ans_sum += beg.w + end.w
  }
  print(ans_sum);
  print(ans_arr.join('\n'));
  print('');

};

function main() {
    let T = +readline()
    while (T--){
      readline()
      let [n, m] = ra();
      let arr = [];
      for (let i=0; i<m; i++)
        arr.push(ra());
      calc(n, m, arr);
    }
}

E.calc = calc;

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

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

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, m] = rna();
		const points = [];
		for (let i = 0; i < m; i++) {
			const [x, w] = rna();
			points.push([w, i+1]);
		}

		points.sort((x, y) => x[0] - y[0]);

		let sum = 0;
		for (let i = 0; i < 2*n; i++) sum += points[i][0];
		console.log(sum);

		for (let i = 0; i < n; i++) {
			console.log(points[i][1], points[2*n-i-1][1]);
		}
	}
}

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

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

function main () {
	let T = rn();
	while (T--) {
		rl();
		const [n, m] = rna();
		const points = [];
		for (let i = 0; i < m; i++) {
			const [x, w] = rna();
			points.push([x, w]);
		}

		points.sort((x, y) => x[1] - y[1]);

		let sum = 0;
		for (let i = 0; i < 2*n; i++) sum += points[i][0];
		console.log(sum);

		for (let i = 0; i < n; i++) {
			console.log(points[i][0], points[2*n-i-1][0]);
		}
	}
}

const readline = require('readline')

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

function solve(n, m, arr) {
    arr = arr
        // .sort((a, b) => a[0] - b[0])
        .map(([x, w], i) => ({ x, w, i: i + 1}))
        .sort((a, b) => a.w - b.w)
    let ans = 0
    const xs = Array(2 * n)
    for (let i = 0; i < 2 * n; i++) {
        ans += arr[i].w
        xs[i] = arr[i].i
    }
    xs.sort((a, b) => a - b)
    const pairs = Array(n)
    for (let i = 0; i < n; i++) {
        pairs[i] = xs[i] + ' ' + xs[2 * n - 1 - i]
    }
    return ans + '\n' + pairs.join('\n')
}

const readline = require('readline')

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

function solve(n, m, arr) {
    arr = arr
        .sort((a, b) => a[0] - b[0])
        .map(([x, w], i) => ({ x, w, i: i + 1}))
        .sort((a, b) => a.w - b.w)
    let ans = 0
    const xs = Array(2 * n)
    for (let i = 0; i < 2 * n; i++) {
        ans += arr[i].w
        xs[i] = arr[i].i
    }
    xs.sort((a, b) => a - b)
    const pairs = Array(n)
    for (let i = 0; i < n; i++) {
        pairs[i] = xs[i] + ' ' + xs[2 * n - 1 - i]
    }
    return ans + '\n' + pairs.join('\n')
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    readline();
    let [n, m] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = [];
    for (let i = 0; i < m; i++) {
      arr.push(
        readline()
          .trim()
          .split(" ")
          .map((cur) => parseInt(cur))
      );
    }
    for (let i = 0; i < m; i++) {
      let obj = { val: arr[i][0], w: arr[i][1], ind: i };
      arr[i] = obj;
    }
    arr.sort((a, b) => a.val - b.val);
    const r = (start, i, j) => {
      let s1 = 0,
        s = [],
        cnt = 0;
      while (i <= start) {
        if (cnt < n) s1 += arr[i].w;
        else {
          let obj = { w: s1, s: j, e: i - 1 };
          s.push(obj);
          if (i < start) s1 = s1 - arr[j].w + arr[i].w;
          j++;
        }
        i++;
        cnt++;
      }
      return s;
    };
    let s1 = r(m - n, 0, 0);
    let s2 = r(m, n, n);
    let minarr = [];
    let min = s2.length - 1;
    for (let i = s2.length - 1; i >= 0; i--) {
      if (s2[min].w >= s2[i].w) min = i;
      minarr[i] = min;
    }
    let minx = Infinity,
      obj1 = {};
    for (let i = 0; i < s1.length; i++) {
      let k = s1[i].w + s2[minarr[i]].w;
      if (k < minx) {
        obj1 = { v1: s1[i], v2: s2[minarr[i]] };
        minx = k;
      }
    }
    console.log(obj1.v1.w + obj1.v2.w);
    let st1 = obj1.v1.s,
      st2 = obj1.v2.e,
      i = 0;
    while (i < n) {
      console.log(`${arr[st1].ind + 1} ${arr[st2].ind + 1}`);
      st1++;
      st2--;
      i++;
    }
  }
};
solve();