Vasiliy lives at point (a, b) of the coordinate plane. He is hurrying up to work so he wants to get out of his house as soon as possible. New app suggested n available Beru-taxi nearby. The i-th taxi is located at point (xi, yi) and moves with a speed vi. Consider that each of n drivers will move directly to Vasiliy and with a maximum possible speed. Compute the minimum time when Vasiliy will get in any of Beru-taxi cars.

The first line of the input contains two integers a and b ( - 100 ≤ a, b ≤ 100) — coordinates of Vasiliy's home. The second line contains a single integer n (1 ≤ n ≤ 1000) — the number of available Beru-taxi cars nearby.  The i-th of the following n lines contains three integers xi, yi and vi ( - 100 ≤ xi, yi ≤ 100, 1 ≤ vi ≤ 100) — the coordinates of the i-th car and its speed. It's allowed that several cars are located at the same point. Also, cars may be located at exactly the same point where Vasiliy lives.

Print a single real value — the minimum time Vasiliy needs to get in any of the Beru-taxi cars. You answer will be considered correct if its absolute or relative error does not exceed 10 - 6.  Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

NoteIn the first sample, first taxi will get to Vasiliy in time 2, and second will do this in time 1, therefore 1 is the answer.In the second sample, cars 2 and 3 will arrive simultaneously.

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

const distance = (x1, x2, y1, y2) => {
  return Math.abs(Math.sqrt((x1 - y1)**2 + (x2 - y2) ** 2));
}

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

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

  const [x, y, v] = d.split(' ').map(Number);
  ans = Math.min(ans, distance(a, b, x, y) / v);

  c++;
});

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

var input = readline().split(" "), a = +input[0], b = +input[1];
var n = +readline();

var minT = Infinity;
for(var i = 0; i < n; i++){
    var data = readline().split(" ").map(Number);
    var x = data[0], y = data[1], v = data[2];
    var s = Math.sqrt( Math.pow( (a-x), 2 ) + Math.pow( (b-y), 2 ) );
    minT = Math.min(minT, s/v);
}

write(minT);

var input = readline().split(' ').map(Number);
var a = input[0], b = input[1];
var n = +readline();
var res = Infinity;
for (var i = 0; i < n; i++) {
    input = readline().split(' ').map(Number);
    var x = input[0], y = input[1], v = input[2];
    res = Math.min(Math.sqrt(Math.pow(a-x, 2) + Math.pow(b-y, 2)) / v, res)
}
print(res);

var input = readline().split(' ').map(Number);
var a = input[0], b = input[1];
var n = Number(readline());
var res = 10000000;
for (var i = 0; i < n; i++) {
    input = readline().split(' ').map(Number);
    var x = input[0], y = input[1], v = input[2];
    res = Math.min(Math.sqrt(Math.pow(a-x, 2) + Math.pow(b-y, 2)) / v, res)
}
print(res);

'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var tArr = [];

var _readline$split$map = readline().split(' ').map(Number);

var _readline$split$map2 = _slicedToArray(_readline$split$map, 2);

var a = _readline$split$map2[0];
var b = _readline$split$map2[1];

var n = Number(readline());
for (var i = 0; i < n; i++) {
  var _readline$split$map3 = readline().split(' ').map(Number);

  var _readline$split$map4 = _slicedToArray(_readline$split$map3, 3);

  var x = _readline$split$map4[0];
  var y = _readline$split$map4[1];
  var v = _readline$split$map4[2];

  tArr.push(Math.sqrt(Math.pow(x - a, 2) + Math.pow(y - b, 2)) / v);
}
print(Math.min.apply(Math, tArr));

'use strict';

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _readline$split$map = readline().split(' ').map(Number);

var _readline$split$map2 = _slicedToArray(_readline$split$map, 2);

var a = _readline$split$map2[0];
var b = _readline$split$map2[1];

var n = Number(readline());
var minTime = 100000;
for (var i = 0; i < n; i++) {
	var _readline$split$map3 = readline().split(' ').map(Number);

	var _readline$split$map4 = _slicedToArray(_readline$split$map3, 3);

	var x = _readline$split$map4[0];
	var y = _readline$split$map4[1];
	var v = _readline$split$map4[2];

	var dist = Math.sqrt((x - a) * (x - a) + (y - b) * (y - b));
	var time = dist / v;
	if (minTime > time) {
		minTime = time;
	}
}
print(minTime);

var input = readline().split(" ").map(i => +i);
var a = input[0];
var b = input[1];
var n = +readline();
var minTime;

var distance = function(x1, y1, x2, y2) {
    return Math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
};

for (var i = 0; i < n; ++i) {
    input = readline().split(" ").map(i => +i);
    var xi = input[0];
    var yi = input[1];
    var vi = input[2];
    var time = distance(xi, yi, a, b) / vi;
    if ( typeof minTime === "undefined" || time < minTime) {
        minTime = time;
    }
}

print(minTime);

var input = readline().split(" ").map(i => +i);
var a = input[0];
var b = input[1];
var n = +readline();
var minTime;

var distance = function(x1, y1, x2, y2) {
    return Math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
};

for (var i = 0; i < n; ++i) {
    input = readline().split(" ").map(i => +i);
    var xi = input[0];
    var yi = input[1];
    var vi = input[2];
    var time = distance(xi, yi, a, b) / vi;
    if ( !minTime || time < minTime) {
        minTime = time;
    }
}

print(minTime);


You are given a set of $$$n$$$ segments on the axis $$$Ox$$$, each segment has integer endpoints between $$$1$$$ and $$$m$$$ inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le m$$$) — coordinates of the left and of the right endpoints. Consider all integer points between $$$1$$$ and $$$m$$$ inclusive. Your task is to print all such points that don't belong to any segment. The point $$$x$$$ belongs to the segment $$$[l; r]$$$ if and only if $$$l \le x \le r$$$.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100$$$) — the number of segments and the upper bound for coordinates. The next $$$n$$$ lines contain two integers each $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le m$$$) — the endpoints of the $$$i$$$-th segment. Segments may intersect, overlap or even coincide with each other. Note, it is possible that $$$l_i=r_i$$$, i.e. a segment can degenerate to a point.

In the first line print one integer $$$k$$$ — the number of points that don't belong to any segment. In the second line print exactly $$$k$$$ integers in any order — the points that don't belong to any segment. All points you print should be distinct. If there are no such points at all, print a single integer $$$0$$$ in the first line and either leave the second line empty or do not print it at all.

NoteIn the first example the point $$$1$$$ belongs to the second segment, the point $$$2$$$ belongs to the first and the second segments and the point $$$5$$$ belongs to the third segment. The points $$$3$$$ and $$$4$$$ do not belong to any segment.In the second example all the points from $$$1$$$ to $$$7$$$ belong to the first segment.

var a = readline().split(' ');
var arr = [],result = [];
for(var i = 0;i <a[0]; i++){
    arr.push(readline().split(' '));
}
for(var i = 1; i <= a[1]; i++){
    var k = 0;
    for(var j = 0; j<a[0] ;j++){
        if(i<arr[j][0] || i>arr[j][1]){
            k++;
        }
    }
    if(k == a[0]) result.push(i);
}
print(result.length);
result.forEach(function(v){
    print( v + ' ');
});

var input = readline();
var items = input.split(' ');

var lines = items[0];
var top1 = items[1];

var inputs = [];
var y = [];
for (var i = 1; i <= lines; i++ ){
    inputs = readline().split(' ');

    for (var j = +inputs[0]; j <= +inputs[1]; j++ ) {
        if (y.indexOf(j) === -1) {
            y.push(j);
        }
    }
}

print(top1 - y.length);

for (var i = 1; i <= top1; i++) {
    if (y.indexOf(i) === -1) {
        write(i + ' ');
    }
}

function calculateProb(str1, str2) {
    var ob = {};
    var rez = [];
    var last = '';

    for (var k = 1; k <= str2; k++) {
        var flg = true;

        for (var i = 0; i < str1.length; i++) {
            if (!(k < parseInt(str1[i][0]) || k > parseInt(str1[i][1]))) {
                flg = false;
            }
        }

        if (flg) rez.push(k);
    }

    print(rez.length);
    print(rez.join(" "));
}

var s = [];
var s1 = readline().split(' ');

var num = parseInt(s1[0]);
var num2 = parseInt(s1[1]);

for (var i = 0; i < num; i++) {
    s.push(readline().split(' '));
}

calculateProb(s, num2);

var g = readline().split(" ");
var m = Number(g[1]);
var n = Number(g[0]);

var print_dots = [];

var input_dots = [];

for(i=0;i<n;i++){
    input_dots.push(readline());

}

for(dott=1;dott<=m;dott++){
    var dott_flag = true;
    for(i=0;i<n;i++){
        var k = input_dots[i].split(" ");
        var l = Number(k[0]);
        var r = Number(k[1]);
        if(dott >= l && dott <= r){
            dott_flag =false;
            break;
         }
    }

   if(dott_flag)
    print_dots.push(dott);
}

print(print_dots.length);
print(print_dots.join(" "));

function main() {
  const is = new Scanner();
  const [n, m] = is.nextArray(Number);
  const line = new Array(m).fill(true);
  let u, v;
  for (let i = 0; i < n; i += 1) {
    [u, v] = is.nextArray(Number);
    u -= 1; v -= 1;
    while (u <= v) {
      line[u] = false;
      u += 1;
    }
  }

  const segments = [];
  line.forEach((item, index) => {
    if (item) {
      segments.push(index + 1);
    }
  });

  console.log(segments.length);
  if (segments.length) {
    console.log(segments.join(' '));
  }
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    return this.lines[this.index++]; // eslint-disable-line
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn) {
    const array = this.nextLine().split(' ');
    return fn === String ? array : array.map(fn);
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

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, ''))
  main(arr)
})

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

function main(input) {
  let ptr = 0
  const [n,m] = readInts(input, ptr++)
  const arr = new Array(n)
  for(let i = 0; i < n; i++) {
    arr[i] = readInts(input, ptr++)
  }

  arr.sort((a, b) => {
    if(a[0] === b[0]) return a[1] - b[1]
    else return a[0] - b[0]
  })
  let ans = []
  let last = 0
  // console.log(arr)
  arr.forEach(e => {
    if(last < e[0]) {
      let t = last + 1
      while(t < e[0]) {
        ans.push(t)
        t++
      }
    }
    if(last < e[1]) last = e[1]
  })
  if(last < m) {
    let t = last + 1
    while(t <= m) {
      ans.push(t)
      t++
    }
  }

  wr(ans.length)
  if(ans.length !== 0) wr(ans.join(' '))
  else console.log()
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var M = one[1];
	var used = new Array(M + 1).fill(0);
	for(var i = 0; i < N; i++){
		var tmp = nextIntArray();
		for(var j = tmp[0]; j <= tmp[1]; j++){
			used[j]++;
		}
	}
	var output = [];
	for(var i = 1; i <= M; i++){
		if(used[i] == 0){
			output.push(i);
		}
	}
	myout(output.length);
	myout(myconv(output, 8));
}

function main() {
    [n, m] = readInts()
    st = new Set()
    for (i=1; i<=m; i++) st.add(i)
    for (i=0; i<n; i++){
        [l, r] = readInts()
        for (j=l; j<=r; j++) st.delete(j)
    }
    print(st.size)
    print(Array.from(st).join(' '))
}

const TESTCASES = false
/* NodeJS Footer by @satyamcse and @shivam1420*/
var readline = require('readline');
process.stdin.setEncoding('utf-8');
var rl = readline.createInterface({input: process.stdin, output: process.stdout});
var inp = "";
rl.on('line' , v => inp += v+"\n");
rl.on('close', () => {
    inp = inp.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))
    if (TESTCASES){
        const cnt = readInt()
        for (let i = 0; i<cnt; i++){
            main()
        }
    } else {main()}
});
function sort(a, inc = true) {
    if(inc) a.sort((a, b) => a - b)
    else a.sort((a, b) => b - a)
}
var ptr = 0
function print(...x) {console.log(...x)}
function readInt() {return +inp[ptr++]}
function readLine() {return inp[ptr++]}
function readInts() {return inp[ptr++].split(' ').map(a => +a)}

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

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

  let [l, r] = d.split(' ').map(Number);

  while (l <= r) {
    segment[l] = 0;
    l++;
  }

  c++;
});

rl.on('close', () => {
  let k = segment.reduce((a, x) => a + x, 0);
  const ans = [];
  console.log(k - 1);

  if (k) {
    for (let i = 1; i < segment.length; i++) {
      if (segment[i] === 1) {
        ans.push(i);
      }
    }
  }

  console.log(ans.join(' '));
});

let input = [];

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

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

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

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

        for(let j = pair[0]; j <= pair[1]; j++){
            answer[j-1] = 1;
        }
    }

    let cnt = 0;
    let answer_string = '';
    for(let i = 0; i < m; i++){
        if(answer[i] == 0){
            answer_string += `${i+1} `; cnt++;
        }

    }
    console.log(cnt);
    if (cnt > 0)
        console.log(answer_string);
});

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

function out(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;
}
function main() {
    let n1= stringArrayToNumbers(inp())
    let n, m, i, j, l, r;

    n = n1[0];
    m = n1[1];
    var arr= []
    for (i = 1; i<=m; i++)
    {
        arr.push(0)
    }
    for(i=1; i<=n; i++) {
        let inputs = inp();
        inputs = inputs.split(' ');
        l = parseInt(inputs[0], 10);
        r = parseInt(inputs[1], 10);
        for (j=l-1; j<r; j++){
            arr[j]=1
        }
    }
    var ans = []
    for(i=0; i<m; i++){
        if (arr[i]==0){
            ans.push(i+1)
        }
    }
    out(ans.length);
    var ans1 = '';
    for (i=0; i<ans.length; i++){
        ans1 += ans[i]+' '
    }
    out(ans1)

}

var a = readline().split(' ');
var arr = [],result = [];
for(var i = 0;i <a[0]; i++){
    arr.push(readline().split(' '));
}
for(var i = 1; i <= a[1]; i++){
    var k = 0;
    for(var j = 0; j<a[0] ;j++){
        if(i<arr[j][0] && i<arr[j][1]){
            k++;
        }
    }
    if(k == a[0]) result.push(i);
}
print(result.length);
result.forEach(function(v){
    print(v+ ' ');
})

var a = readline().split(' ');
var arr = [],result = [];
for(var i = 0;i <a[0]; i++){
    arr.push(readline().split(' '));
}
for(var i = 1; i <= a[1]; i++){
    var k = 0;
    for(var j = 0; j<a[0] ;j++){
        if(i<arr[j][0] && i>arr[j][1]){
            k++;
        }
    }
    if(k == a[0]) result.push(i);
}
print(result.length);
result.forEach(function(v){
    print( v + ' ');
});

function main() {
  const is = new Scanner();
  const [n, m] = is.nextArray(Number);
  const line = new Array(m).fill(true);
  let u, v;
  for (let i = 0; i < n; i += 1) {
    [u, v] = is.nextArray(Number);
    u -= 1; v -= 1;
    while (u <= v) {
      line[u] = false;
      u += 1;
    }
  }

  const segments = [];
  line.forEach((item, index) => {
    if (item) {
      segments.push(index);
    }
  });

  console.log(segments.length);
  if (segments.length) {
    console.log(segments.join(' '));
  }
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    return this.lines[this.index++]; // eslint-disable-line
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn) {
    const array = this.nextLine().split(' ');
    return fn === String ? array : array.map(fn);
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

function main() {
  const is = new Scanner();
  const [n, m] = is.nextArray(Number);
  const line = new Array(m + 2).fill(true);
  let u, v;
  for (let i = 0; i < n; i += 1) {
    [u, v] = is.nextArray(Number);
    while (u <= v) {
      line[u] = false;
      u += 1;
    }
  }

  const segments = [];
  let flag = false;
  let numSegments = 0;
  line[m + 1] = false;
  for (let i = 1; i < line.length; i += 1) {
    switch (true) { // eslint-disable-line
      case line[i]:
        if (!flag) {
          flag = true;
          u = i;
        }
        if (i <= m)
          numSegments += 1;
        break;
      case flag:
        v = i - 1;
        flag = false;
        segments.push([u, v]);
        break;
    }
  }

  console.log(numSegments);
  if (segments.length) {
    segments.forEach((item) => {
      console.log(item[0], item[1]);
    });
  }
}

/*
 *  Api Scanner
 */
class Scanner {
  constructor() {
    this.index = 0;
    this.lines = stdinInput.trim().split('\n'); // eslint-disable-line
  }

  nextLine() {
    return this.lines[this.index++]; // eslint-disable-line
  }

  nextInt() {
    return parseInt(this.nextLine(), 10);
  }

  nextDouble() {
    return parseFloat(this.nextLine());
  }

  nextArray(fn) {
    const array = this.nextLine().split(' ');
    return fn === String ? array : array.map(fn);
  }

  hasNext() {
    return this.index < this.lines.length;
  }
}

let stdinInput = '';
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => { stdinInput += input; });
process.stdin.on('end', () => { main(); });

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, ''))
  main(arr)
})

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

function main(input) {
  let ptr = 0
  const [n,m] = readInts(input, ptr++)
  const arr = new Array(n)
  for(let i = 0; i < n; i++) {
    arr[i] = readInts(input, ptr++)
  }

  arr.sort((a, b) => {
    if(a[0] === b[0]) return a[1] - b[1]
    else return a[0] - b[0]
  })
  let ans = []
  let last = 0
  arr.forEach(e => {
    if(last < e[0]) {
      let t = last + 1
      while(t < e[0]) {
        ans.push(t)
        t++
      }
    }
    if(last < e[1]) last = e[1]
  })

  wr(ans.length)
  if(ans.length !== 0) wr(ans.join(' '))
}

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, ''))
  main(arr)
})

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

function main(input) {
  let ptr = 0
  const [n,m] = readInts(input, ptr++)
  const arr = new Array(n)
  for(let i = 0; i < n; i++) {
    arr[i] = readInts(input, ptr++)
  }

  arr.sort((a, b) => {
    if(a[0] === b[0]) return a[1] - b[1]
    else return a[0] - b[0]
  })
  let ans = []
  let last = 0
  arr.forEach(e => {
    if(last < e[0]) {
      let t = last + 1
      while(t < e[0]) {
        ans.push(t)
        t++
      }
    }
    last = e[1]
  })

  wr(ans.length)
  if(ans.length !== 0) wr(ans.join(' '))
}


Lord Omkar would like to have a tree with $$$n$$$ nodes ($$$3 \le n \le 10^5$$$) and has asked his disciples to construct the tree. However, Lord Omkar has created $$$m$$$ ($$$\mathbf{1 \le m < n}$$$) restrictions to ensure that the tree will be as heavenly as possible. A tree with $$$n$$$ nodes is an connected undirected graph with $$$n$$$ nodes and $$$n-1$$$ edges. Note that for any two nodes, there is exactly one simple path between them, where a simple path is a path between two nodes that does not contain any node more than once.Here is an example of a tree:   A restriction consists of $$$3$$$ pairwise distinct integers, $$$a$$$, $$$b$$$, and $$$c$$$ ($$$1 \le a,b,c \le n$$$). It signifies that node $$$b$$$ cannot lie on the simple path between node $$$a$$$ and node $$$c$$$. Can you help Lord Omkar and become his most trusted disciple? You will need to find heavenly trees for multiple sets of restrictions. It can be shown that a heavenly tree will always exist for any set of restrictions under the given constraints.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^4$$$). Description of the test cases follows. The first line of each test case contains two integers, $$$n$$$ and $$$m$$$ ($$$3 \leq n \leq 10^5$$$, $$$\mathbf{1 \leq m < n}$$$), representing the size of the tree and the number of restrictions. The $$$i$$$-th of the next $$$m$$$ lines contains three integers $$$a_i$$$, $$$b_i$$$, $$$c_i$$$ ($$$1 \le a_i, b_i, c_i \le n$$$, $$$a$$$, $$$b$$$, $$$c$$$ are distinct), signifying that node $$$b_i$$$ cannot lie on the simple path between nodes $$$a_i$$$ and $$$c_i$$$.  It is guaranteed that the sum of $$$n$$$ across all test cases will not exceed $$$10^5$$$.

For each test case, output $$$n-1$$$ lines representing the $$$n-1$$$ edges in the tree. On each line, output two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \neq v$$$) signifying that there is an edge between nodes $$$u$$$ and $$$v$$$. Given edges have to form a tree that satisfies Omkar's restrictions.

NoteThe output of the first sample case corresponds to the following tree:    For the first restriction, the simple path between $$$1$$$ and $$$3$$$ is $$$1, 3$$$, which doesn't contain $$$2$$$. The simple path between $$$3$$$ and $$$5$$$ is $$$3, 5$$$, which doesn't contain $$$4$$$. The simple path between $$$5$$$ and $$$7$$$ is $$$5, 3, 1, 2, 7$$$, which doesn't contain $$$6$$$. The simple path between $$$6$$$ and $$$4$$$ is $$$6, 7, 2, 1, 3, 4$$$, which doesn't contain $$$5$$$. Thus, this tree meets all of the restrictions.The output of the second sample case corresponds to the following tree:

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let node = [];
    for (let i = 0; i < k; i++) {
      node.push(
        readline()
          .trim()
          .split(" ")
          .map((cur) => parseInt(cur))
      );
    }
    let res,
      obj = {};
    for (let i = 0; i < k; i++) obj[node[i][1]] = 1;
    for (let i = 1; i <= n; i++) {
      if (!obj[i]) {
        res = i;
        break;
      }
    }
    for (let i = 1; i <= n; i++) {
      if (i !== res) {
        console.log(`${res} ${i}`);
      }
    }
  }
};
solve();

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--) {
		const [n, m] = rna();

		const used = [];
		for (let i = 0; i < m; i++) {
			const [a, b, c] = rna();
			used[b] = 1;
		}

		let root;
		for (let i = 1; i <= n; i++) if (!used[i]) root = i;

		for (let i = 1; i <= n; i++) if (i != root) console.log(i, root);
	}
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let node = [];
    for (let i = 0; i < k; i++) {
      node.push(
        readline()
          .trim()
          .split(" ")
          .map((cur) => parseInt(cur))
      );
    }
    let res = [],
      obj = {};
    const push = (n1, n2) => {
      if (!obj[n1]) {
        res.push(n1);
        obj[n1] = 1;
      }
      if (!obj[n2]) {
        res.push(n2);
        obj[n2] = 1;
      }
    };
    for (let i = 0; i < k; i++) {
      push(node[i][0], node[i][2]);
    }
    for (let i = 0; i < k; i++) {
      if (!obj[node[i][1]]) res.push(node[i][1]);
    }
    for (let i = 0; i < n - 1; i++) {
      console.log(res[i] + " " + res[i + 1]);
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let node = [];
    for (let i = 0; i < k; i++) {
      node.push(
        readline()
          .trim()
          .split(" ")
          .map((cur) => parseInt(cur))
      );
    }
    let res = [],
      obj = {},
      start = node[0][0];
    obj[node[0][0]] = 1;
    obj[node[0][2]] = 1;
    res.push([node[0][0], node[0][2]]);
    for (let i = 1; i < k; i++) {
      if (!obj[node[i][0]] || !obj[node[i][2]]) {
        res.push([node[i][0], node[i][2]]);
        if (!obj[node[i][0]] && !obj[node[i][2]]) {
          res.push([node[i][0], node[i - 1][2]]);
        }
        obj[node[i][0]] = 1;
        obj[node[i][2]] = 1;
      }
    }
    for (let i = 0; i < k; i++) {
      if (!obj[node[i][1]]) {
        res.push([start, node[i][1]]);
        obj[node[i][1]] = 1;
      }
    }
    for (let i = 0; i < res.length; i++) {
      console.log(res[i].join(" "));
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let node = [];
    for (let i = 0; i < k; i++) {
      node.push(
        readline()
          .trim()
          .split(" ")
          .map((cur) => parseInt(cur))
      );
    }
    let res = [],
      obj = {},
      start = node[0][0];
    obj[node[0][0]] = 1;
    obj[node[0][2]] = 1;
    res.push([node[0][0], node[0][2]]);
    for (let i = 1; i < k; i++) {
      if (!obj[node[i][0]] || !obj[node[i][2]]) {
        res.push([node[i][0], node[i][2]]);
        if (!obj[node[i][0]] && !obj[node[i][2]]) {
          if (!obj[node[i][0]]) res.push([node[i][0], node[i - 1][0]]);
          else res.push([node[i][2], node[i - 1][2]]);
        }
        obj[node[i][0]] = 1;
        obj[node[i][2]] = 1;
      }
    }
    for (let i = 0; i < k; i++) {
      if (!obj[node[i][1]]) {
        res.push([start, node[i][1]]);
        obj[node[i][1]] = 1;
      }
    }
    for (let i = 0; i < res.length; i++) {
      console.log(res[i].join(" "));
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let node = [];
    for (let i = 0; i < k; i++) {
      node.push(
        readline()
          .trim()
          .split(" ")
          .map((cur) => parseInt(cur))
      );
    }
    let res = [],
      obj = {},
      start = node[0][0];
    for (let i = 0; i < k; i++) {
      if (!obj[node[i][0]] || !obj[node[i][2]]) {
        res.push([node[i][0], node[i][2]]);
        obj[node[i][0]] = 1;
        obj[node[i][2]] = 1;
      }
    }
    for (let i = 0; i < k; i++) {
      if (!obj[node[i][1]]) {
        res.push([start, node[i][1]]);
        obj[node[i][1]] = 1;
      }
    }
    for (let i = 0; i < res.length; i++) {
      console.log(res[i].join(" "));
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [n, k] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let node = [];
    for (let i = 0; i < k; i++) {
      node.push(
        readline()
          .trim()
          .split(" ")
          .map((cur) => parseInt(cur))
      );
    }
    let res = [],
      obj = {};
    for (let i = 0; i < k; i++) {
      if (!obj[node[i][2]] || !obj[node[i][0]]) {
        if (!obj[node[i][0]]) res.push([node[i][2], node[i][0]]);
        else res.push([node[i][0], node[i][2]]);
        obj[node[i][2]] = 1;
        obj[node[i][0]] = 1;
      }
      if (!obj[node[i][0]] || !obj[node[i][1]]) {
        if (!obj[node[i][1]]) res.push([node[i][0], node[i][1]]);
        else res.push([node[i][1], node[i][0]]);
        obj[node[i][1]] = 1;
        obj[node[i][0]] = 1;
      }
    }
    for (let i = 0; i < res.length; i++) {
      console.log(res[i].join(" "));
    }
  }
};
solve();

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--) {
		const [n, m] = rna();

		const used = [];
		for (let i = 0; i < m; i++) {
			let [a, b, c] = rna();
			if (a > c) [a, c] = [c, a];
			console.log(a, c);
			used[a] = 1;
		}

		for (let i = 1, u; i <= n; i++) {
			if (!used[i]) {
				if (u) console.log(u, i);
				u = i;
			}
		}
	}
}

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--) {
		const [n, m] = rna();

		const used = [];
		for (let i = 0; i < m; i++) {
			let [a, b, c] = rna();
			if (a > b) [a, b] = [b, a];
			console.log(a, c);
			used[c] = 1;
		}

		for (let i = 0, u; i < n; i++) {
			if (!used[i]) {
				if (u) console.log(u+1, i+1);
				u = i;
			}
		}
	}
}


Victor has a 24-hour clock that shows the time in the format "HH:MM" (00 $$$\le$$$ HH $$$\le$$$ 23, 00 $$$\le$$$ MM $$$\le$$$ 59). He looks at the clock every $$$x$$$ minutes, and the clock is currently showing time $$$s$$$. How many different palindromes will Victor see in total after looking at the clock every $$$x$$$ minutes, the first time being at time $$$s$$$?For example, if the clock starts out as 03:12 and Victor looks at the clock every $$$360$$$ minutes (i.e. every $$$6$$$ hours), then he will see the times 03:12, 09:12, 15:12, 21:12, 03:12, and the times will continue to repeat. Here the time 21:12 is the only palindrome he will ever see, so the answer is $$$1$$$.A palindrome is a string that reads the same backward as forward. For example, the times 12:21, 05:50, 11:11 are palindromes but 13:13, 22:10, 02:22 are not.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of each test case follows. The only line of each test case contains a string $$$s$$$ of length $$$5$$$ with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59" (both "HH" and "MM" have exactly two digits) and an integer $$$x$$$ ($$$1 \leq x \leq 1440$$$) — the number of minutes Victor takes to look again at the clock.

For each test case, output a single integer — the number of different palindromes Victor will see if he looks at the clock every $$$x$$$ minutes starting from time $$$s$$$.

NoteThe first test case is explained in the statement.

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine() {
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace("\r", "");
}

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

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine()
        .split(" ")
        .map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********
function revStr(str){
    return Array.from(str).reverse().join('');
}
function palindromeTimeList(){
    const timesAr = [];
    for(let i=0;i<16;i++){
        let tm = i;
        if(tm<10){
            tm = `0${tm}`;
        }
        else{
            tm = `${tm}`
        }
        let acTime = `${tm}:${revStr(tm)}`;
        let cvMin = tm*60 + parseInt(revStr(tm)) ;
        // console.log(acTime , cvMin)

        timesAr.push(cvMin);
    }
    return timesAr;
}
function isPalindromeTime(timeStr = '')
{
    const revStr = timeStr.split('').reverse().join('');
    return (revStr==timeStr );
}
function convertTime(n){
    let hour = Math.floor(n/60)%24;
    n = n%60;
    if(hour<10){
        hour = `0${hour}`;
    }
    if(n<10){
        n = `0${n}`;
    }
    return `${hour}:${n}`;
}
function solve() {
   let t= readSingleInt();
   const arTime = palindromeTimeList();
   while(t--)
   {
       let [timeString,interval]=  readLine().split(' ');
       interval = parseInt(interval);
       let [hour ,min] = timeString.split(':').map( v=> parseInt(v));
       let time = hour*60 + min;
        let ans =0;
        if(isPalindromeTime(timeString)){
            ans++;
        }
       for(let i=time+interval;;i+=interval){
            // console.log('hi')
            const cvs = convertTime(i) ;
            if(cvs==timeString){
                break;
            }
            let res =  isPalindromeTime( convertTime(i) );
            // console.log(cvs)
            if(res){
                ans++;
                // console.log(cvs)
            }
       }

    //    palindromeTimeList()
    //    console.log(isPalindromeTime('07:57'))
       console.log(ans)

   }
}

/*
** 799D
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let is = "";
let cl = 0;

process.stdin.on("data", (inp) => {
    is += inp;
});

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

const readline = () => is[cl++];

// Common Template Ends //

const isPalindrome = (n) => {
  const m = n % 60;
  const h = (n - m) / 60;
  const h1 = h % 10;
  const h0 = (h - h1) / 10;
  return `${h1}${h0}` === `${m < 10 ? '0' : ''}${m}`;
}

const toTime = (hhmm) => {
  const [h, m] = hhmm.split(':').map(n => parseInt(n));
  return h * 60 + m;
}

function main() {
  let nLines = parseInt(readline());
  while(nLines--) {
    const [time, x] = readline().split(' ');
    const start = toTime(time);
    const min = parseInt(x);
    let current = (start + min) % 1440;
    let n = isPalindrome(start) ? 1 : 0;
    while (current !== start) {
      if (isPalindrome(current)) n++;
      current = (current + min) % 1440;
    }

    console.log(n);
  }
}

// https://codeforces.com/blog/entry/69610

'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(v) {
    console.log(v);
}
const palindromes = [
    "00:00",
    "01:10",
    "02:20",
    "03:30",
    "04:40",
    "05:50",
    "10:01",
    "11:11",
    "12:21",
    "13:31",
    "14:41",
    "15:51",
    "20:02",
    "21:12",
    "22:22",
    "23:32",
];

const timeToMm = (v) => {
    const [hh, mm] = v.split(":").map(t => parseInt(t));
    return hh * 60 + mm;
};

const palindromeMinutes = palindromes.map(timeToMm);

// taken from https://codeforces.com/contest/1692/submission/170087380
const solve = () => {
    const [time, incrementStr] = readline().split(" ");
    const startTimeMm = timeToMm(time);
    const increment = parseInt(incrementStr);
    let answer = 0;
    let running = startTimeMm;
    const s = new Set();
    const pad = (v) => ("0" + v).substr(-2);
    const isPalindrome = (a) => a === a.split("").reverse().join("");
    while (true) {
        const timeToCheck = pad(Math.floor(running / 60)) + ":" + pad(running % 60);
        if (s.has(timeToCheck))
            break;

        if (isPalindrome(timeToCheck))
            answer++;

        s.add(timeToCheck);

        running += increment;
        running %= 1440;
    }
    print(answer);
}

/*
const gcd = (a, b) => {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
};

const lcm = (a, b) => a * b / gcd(a, b);

const solve = () => {
    const [time, incrementStr] = readline().split(" ");
    print(`time ${time}`);
    print(`incrementStr ${incrementStr}`);
    const startTimeMm = timeToMm(time);
    const increment = parseInt(incrementStr);
    print(`startTimeMm ${startTimeMm}`);
    let counter = 0;
    for (const palindromeTime of palindromeMinutes) {
        if ((lcm(palindromeTime, startTimeMm) - startTimeMm) % increment == 0)
            counter++;
    }
    print(counter);
};
*/

const main = () => {
    const t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        solve();
    }
};

function solve() {
  const [a, b] = cl().split(' ');
  const bN = Number(b);
  const n = 60 * 24 / bN;
  let start = strToM(a);
  let count = 0;
  const set = new Set();
  while (!set.has(start)) {
    if (MIs(start)) {
      count += 1;
    }
    set.add(start);
    start += bN;
    start %= 1440;
  }
  co(count);
}

function strToM(str) {
  const [a, b] = str.split(':').map((item) => Number(item));
  return a * 60 + b;
}

function MIs(m) {
  m = m % 1440;
  const b = m % 60;
  const a = m / 60 | 0;
  const bStr = b < 10 ? '0' + b : '' + b;
  const aStr = a < 10 ? '0' + a : '' + a;
  return aStr[0] === bStr[1] && aStr[1] === bStr[0];
}

function Solution() {
  let n = Number(cl());
  while (n--) {
    solve();
  }
}

function cl() {
  return lines.shift();
}

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

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', Solution);

const readline = require('readline')

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

function solve(time, p) {
    p = +p
    const [h, m] = time.split(':').map(Number)
    const now = h * 60 + m
    let d = 0
    let ans = 0
    const map = {}
    while (1) {
        const k = cal(now + d)
        if (map[k]) break
        map[k] = 1
        if (isp(k)) ans++
        d += p
        // if (d > 2440) break
    }
    return ans
}
function cal(now) {
    let h = Math.floor(now / 60)
    h %= 24
    if (h < 10) h = '0' + h
    let m = now % 60
    if (m < 10) m = '0' + m
    const s = h + ':' + m
// console.log(s)
    return s
}
function isp(s) {
    for (let i = 0; i < s.length; i++) {
        if (s[i] !== s[s.length - 1 - i]) return false
    }
    return true
}

'use strict';

function solve(a) {
  const [h, m] = a[0].split(':').map(Number),
        t = Number(a[1]);
  let h1 = h,
      m1 = m;
  const set = new Set();
  const check = () => {
    const a = h1.toString().padStart(2, '0'),
          b = m1.toString().padStart(2, '0');
    const str = `${a}${b}`;
    if (str === str.split('').reverse().join('')) set.add(str);
  };
  const next = () => {
    m1 += t;
    h1 += Math.floor(m1 / 60);
    h1 %= 24;
    m1 %= 60;
  };
  check();
  next();
  while (h1 !== h || m1 !== m) {
    check();
    next();
  }
  return set.size;
}

async function main(read) {
  try {
    let t = Number(await read());
    let res = new Array(t);
    for (let i = 0; i < t; i++) {
      const a = (await read()).split(' ');
      res[i] = solve(a);
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

let inputs,
    str = '';
function read() {
  return inputs.next().value.trim();
}
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', input => str += input);
process.stdin.on('end', async () => {
  inputs = str.split('\n').values();
  const output = await main(read);
  process.stdout.write(output);
});

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var S = next();
		var x = nextInt();
		var tmp = S;
		var output = 0;
		while(true){
			var L = myconv(tmp.split(":")[0], 1);
			var R = myconv(tmp.split(":")[1], 1);
			var V = L * 60 + R;
			V += x;
			var LS = Math.floor(V / 60);
			if(LS >= 24){
				LS %= 24;
			}
			if(LS < 10){
				LS = "0" + LS;
			}
			var RS = V % 60;
			if(RS < 10){
				RS = "0" + RS;
			}
			tmp = LS + ":" + RS;
			var ok = true;
			for(var i = 0; i < tmp.length; i++){
				if(tmp[i] != tmp[tmp.length - 1 - i]){
					ok = false;
				}
			}
			if(ok){
				output++;
			}
			if(tmp == S){
				break;
			}
		}
		myout(output);
	}
}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine() {
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace("\r", "");
}

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

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine()
        .split(" ")
        .map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function isPalindromeTime(timeStr = '')
{
    const revStr = timeStr.split('').reverse().join('');
    return (revStr==timeStr );
}
function convertTime(n){
    let hour = Math.floor(n/60)%24;
    n = n%60;
    if(hour<10){
        hour = `0${hour}`;
    }
    if(n<10){
        n = `0${n}`;
    }
    return `${hour}:${n}`;
}
function solve() {
   let t= readSingleInt();
   while(t--)
   {
       let [timeString,interval]=  readLine().split(' ');
       interval = parseInt(interval);
       let [hour ,min] = timeString.split(':').map( v=> parseInt(v));
       let time = hour*60 + min;
        let ans =0;
        let list = new Set();
        if(isPalindromeTime(timeString)){
            ans++;
            list.add(timeString);
        }
       for(let i=time+interval;i<95*24*60;i+=interval){
            // console.log('hi')
            const cvs = convertTime(i) ;
            // if(cvs==timeString){
            //     break;
            // }
            let res =  isPalindromeTime( convertTime(i) );
            // console.log(cvs)
            if(res){
                ans++;
                list.add(cvs);
                // console.log(cvs)
            }
       }

    //    palindromeTimeList()
    //    console.log(isPalindromeTime('07:57'))
       console.log(list.size)

   }
}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine() {
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace("\r", "");
}

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

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine()
        .split(" ")
        .map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function isPalindromeTime(timeStr = '')
{
    const revStr = timeStr.split('').reverse().join('');
    return (revStr==timeStr );
}
function convertTime(n){
    let hour = Math.floor(n/60)%24;
    n = n%60;
    if(hour<10){
        hour = `0${hour}`;
    }
    if(n<10){
        n = `0${n}`;
    }
    return `${hour}:${n}`;
}
function solve() {
   let t= readSingleInt();
   while(t--)
   {
       let [timeString,interval]=  readLine().split(' ');
       interval = parseInt(interval);
       let [hour ,min] = timeString.split(':').map( v=> parseInt(v));
       let time = hour*60 + min;
        let ans =0;
        let list = new Set();
        if(isPalindromeTime(timeString)){
            ans++;
            list.add(timeString);
        }
       for(let i=time+interval;i<90*24*60;i+=interval){
            // console.log('hi')
            const cvs = convertTime(i) ;
            // if(cvs==timeString){
            //     break;
            // }
            let res =  isPalindromeTime( convertTime(i) );
            // console.log(cvs)
            if(res){
                ans++;
                list.add(cvs);
                // console.log(cvs)
            }
       }

    //    palindromeTimeList()
    //    console.log(isPalindromeTime('07:57'))
       console.log(list.size)

   }
}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine() {
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace("\r", "");
}

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

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine()
        .split(" ")
        .map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function isPalindromeTime(timeStr = '')
{
    const revStr = timeStr.split('').reverse().join('');
    return (revStr==timeStr );
}
function convertTime(n){
    let hour = Math.floor(n/60)%24;
    n = n%60;
    if(hour<10){
        hour = `0${hour}`;
    }
    if(n<10){
        n = `0${n}`;
    }
    return `${hour}:${n}`;
}
function solve() {
   let t= readSingleInt();
   while(t--)
   {
       let [timeString,interval]=  readLine().split(' ');
       interval = parseInt(interval);
       let [hour ,min] = timeString.split(':').map( v=> parseInt(v));
       let time = hour*60 + min;
        let ans =0;
        let list = new Set();
        if(isPalindromeTime(timeString)){
            ans++;
            list.add(timeString);
        }
       for(let i=time+interval;i<60*24*60;i+=interval){
            // console.log('hi')
            const cvs = convertTime(i) ;
            // if(cvs==timeString){
            //     break;
            // }
            let res =  isPalindromeTime( convertTime(i) );
            // console.log(cvs)
            if(res){
                ans++;
                list.add(cvs);
                // console.log(cvs)
            }
       }

    //    palindromeTimeList()
    //    console.log(isPalindromeTime('07:57'))
       console.log(list.size)

   }
}

/**
 * Author : Fazlul Hoque
 * Node.js version : 12.16.3
 * command : node fileName.js <input.txt >output.txt
 */
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = ""; //An array of  raw inputs (includes 'n,\r , not usable. need to process before use)
let currentLine = 0; //input sequence controller variable.

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main(); // after input
});

/********** Utility Functions Start **********/
/**
 *  read row Input
 * @returns string
 */
function _readRawLine() {
    return inputString[currentLine++];
}
function readLine() {
    // return _readRawLine().replace(/\s+$/g, '');
    return _readRawLine().replace("\r", "");
}

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

function readSingleInt() {
    const p = readLine();
    return parseInt(p);
}

function readIntArray() {
    return readLine()
        .split(" ")
        .map((v) => parseInt(v));
}

function readArray() {
    return readLine().split(" ");
}

function int(n) {
    return parseInt(n);
}
/********** Utility Functions End **********/
/**
 * Don't Touch this fucntion at all , unless you know what are you doing!
 */
function main() {
    solve();
}

// ********** actual Code Starts from here **********

function isPalindromeTime(timeStr = '')
{
    const revStr = timeStr.split('').reverse().join('');
    return (revStr==timeStr );
}
function convertTime(n){
    let hour = Math.floor(n/60)%24;
    n = n%60;
    if(hour<10){
        hour = `0${hour}`;
    }
    if(n<10){
        n = `0${n}`;
    }
    return `${hour}:${n}`;
}
function solve() {
   let t= readSingleInt();
   while(t--)
   {
       let [timeString,interval]=  readLine().split(' ');
       interval = parseInt(interval);
       let [hour ,min] = timeString.split(':').map( v=> parseInt(v));
       let time = hour*60 + min;
        let ans =0;
        let list = new Set();
        if(isPalindromeTime(timeString)){
            ans++;
            list.add(timeString);
        }
       for(let i=time+interval;i<30*24*60;i+=interval){
            // console.log('hi')
            const cvs = convertTime(i) ;
            // if(cvs==timeString){
            //     break;
            // }
            let res =  isPalindromeTime( convertTime(i) );
            // console.log(cvs)
            if(res){
                ans++;
                list.add(cvs);
                // console.log(cvs)
            }
       }

    //    palindromeTimeList()
    //    console.log(isPalindromeTime('07:57'))
       console.log(list.size)

   }
}

/*
** 799D
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let is = "";
let cl = 0;

process.stdin.on("data", (inp) => {
    is += inp;
});

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

const readline = () => is[cl++];

// Common Template Ends //

const isPalindrome = (n) => {
  const m = n % 60;
  const h = (n - m) / 60;
  const h1 = h % 10;
  const h0 = (h - h1) / 10;
  return `${h1}${h0}` === `${m < 10 ? '0' : ''}${m}`;
}

const toTime = (hhmm) => {
  const [h, m] = hhmm.split(':').map(n => parseInt(n));
  return h * 60 + m;
}

function main() {
  let nLines = parseInt(readline());
  while(nLines--) {
    const [time, x] = readline().split(' ');
    const start = toTime(time);
    const min = parseInt(x);
    let current = start + min;
    let n = isPalindrome(start) ? 1 : 0;
    while (current !== start) {
      if (isPalindrome(current)) n++;
      current = (current + min) % 1440;
    }

    console.log(n);
  }
}

const palindromes = [
    "00:00",
    "01:10",
    "02:20",
    "03:30",
    "04:40",
    "05:50",
    "10:01",
    "11:11",
    "12:21",
    "13:31",
    "14:41",
    "15:51",
    "20:02",
    "21:12",
    "22:22",
    "23:32",
];

const timeToMm = (v) => {
    const [hh, mm] = v.split(":").map(t => parseInt(t));
    return hh * 60 + mm;
};

const palindromeMinutes = palindromes.map(timeToMm);

// taken from https://codeforces.com/contest/1692/submission/170087380
const solve = () => {
    const [time, incrementStr] = readline().split(" ");
    const startTimeMm = timeToMm(time);
    const increment = parseInt(incrementStr);
    let answer = 0;
    let running = startTimeMm;
    const s = new Set();
    const pad = (v) => ("0" + v).substr(-2);
    const isPalindrome = (a) => a === a.split("").reverse().join("");
    while (true) {
        const timeToCheck = pad(Math.floor(running / 60)) + ":" + pad(running % 60);
        if (s.has(timeToCheck))
            break;

        if (isPalindrome(timeToCheck))
            answer++;

        s.add(timeToCheck);

        running += increment;
        running %= 1440;
    }
    console.log(answer);
}

/*
const gcd = (a, b) => {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
};

const lcm = (a, b) => a * b / gcd(a, b);

const solve = () => {
    const [time, incrementStr] = readline().split(" ");
    print(`time ${time}`);
    print(`incrementStr ${incrementStr}`);
    const startTimeMm = timeToMm(time);
    const increment = parseInt(incrementStr);
    print(`startTimeMm ${startTimeMm}`);
    let counter = 0;
    for (const palindromeTime of palindromeMinutes) {
        if ((lcm(palindromeTime, startTimeMm) - startTimeMm) % increment == 0)
            counter++;
    }
    print(counter);
};
*/

const main = () => {
    const t = parseInt(readline());
    for (let i = 0; i < t; i++) {
        solve();
    }
};


A coordinate line has n segments, the i-th segment starts at the position li and ends at the position ri. We will denote such a segment as [li, ri].You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1.Formally we will assume that segment [a, b] covers segment [c, d], if they meet this condition a ≤ c ≤ d ≤ b.

The first line contains integer n (1 ≤ n ≤ 105) — the number of segments. Next n lines contain the descriptions of the segments. The i-th line contains two space-separated integers li, ri (1 ≤ li ≤ ri ≤ 109) — the borders of the i-th segment. It is guaranteed that no two segments coincide.

Print a single integer — the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input.

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

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

function main() {
  let len = +readLine();
  const arr = [];
  const map = new Map();
  let max = -Infinity;
  for (let i = 0; i < len; i++) {
    const row = readLine()
      .split(" ")
      .map((n) => parseInt(n));
    map.set(`${row[0]}_${row[1]}`, i + 1);
    max = Math.max(max, row[1]);
    arr.push(row);
  }

  arr.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
  if (arr[0][1] >= max) console.log(map.get(`${arr[0][0]}_${arr[0][1]}`));
  else console.log(-1);
}

'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 numsOfInput = readline();
  let coordinates = []
  for (let i = 0; i < numsOfInput; i++) {
    const coordinate = readline().split(' ').map(segment => parseInt(segment));

    coordinates.push([...coordinate])
  }

  helper(coordinates);
}

function helper(coordinates) {
    let [minL, maxR] = coordinates[0];
    let index = 0;

    for (let i = 1; i < coordinates.length; i++) {
        const [l,r] = coordinates[i]
        if (l === minL) {
            if (r >= maxR) {
                maxR = r
                index = i
            }
        } else if (l < minL) {
            minL = l;
            if (r >= maxR) {
                maxR = r;
                index = i
            } else {
                index = -1;
            }
        } else {
            if (r > maxR) {
                maxR = r;
                index = -1;
            }
        }

    }

    console.log(index === -1 ? -1 : index + 1)
}

var n = +readline(),
	ans = -1,
	min = 1e10,
	max = 0;

for (var i = 1; i <= n; i++)
	(function(l, r) {
		var f = 0;
		if (l < min || r > max)
			ans = -1;

		if (l <= min) {
			f++;
			min = l;
		}
		if (r >= max) {
			f++;
			max = r;
		}

		if (f === 2)
			ans = i;

	}).apply(0, readline().split(' ').map(Number));

print(ans);

var i, r,
	n = +readline(),
	a = [],
	ans = -1;

for (var i = 1; i <= n; i++)
	a.push(readline().split(' ').map(Number));

r = a.reduce(function(a, b) {
	return [Math.min(a[0], b[0]), Math.max(a[1], b[1])];
});

a.forEach(function(v, i) {
	if (r[0] === v[0] && r[1] === v[1]) ans = i + 1;
});

print(ans);

var i, r,
	n = +readline(),
	a = [],
	b = [],
	ans = -1;

for (var i = 1; i <= n; i++)
	readline().split(' ').map(Number).reduce(function(l, r) {
		a.push(l);
		b.push(r);
	});

var min = Math.min.apply(0, a);
var max = Math.max.apply(0, b);

for(i = 0; i<n; i++)
	if (min === a[i] && max === b[i])
		ans = i + 1;

print(ans);

;(function () {

	print((function (n) {
		var _o = 1e10, o_ = -1, p = -1, l = n;

		while (l--) {
			var s = readline().split(' ').map(Number), _f = false, f_ = false;
			if (_o > s[0]) { _o = s[0]; _f = true; }
			if (o_ < s[1]) { o_ = s[1]; f_ = true; }
			if (_f || f_) p = -1;
			if (_o === s[0] && o_ === s[1]) p = n - l;
		}

		return p;
	})(+readline()));

}).call(this)

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

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

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

function main() {
	var n = parseInt(readline()), segments = [];
	for (var i = 0; i < n; ++i) {
		var data = tokenizeIntegers(readline());
		segments.push({ left: data[0], right: data[1] });
	}
	var leftmost = segments[0].left, rightmost = segments[0].right;
	for (var i = 1; i < n; ++i) {
		leftmost = Math.min(leftmost, segments[i].left);
		rightmost = Math.max(rightmost, segments[i].right);
	}
	for (var i = 0; i < n; ++i) {
		if (segments[i].left == leftmost && segments[i].right == rightmost) {
			print(i+1);
			return;
		}
	}
	print(-1);
}

main();

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

// Make a Snippet for the code above this and then write your logic in main()
function main() {
  const numsOfInput = readline();
  let coordinates = []
  for (let i = 0; i < numsOfInput; i++) {
    const coordinate = readline().split(' ').map(segment => parseInt(segment));

    coordinates.push([...coordinate])
  }

  helper(coordinates);
}

function helper(coordinates) {
    let minL = coordinates[0][0];
    let maxR = coordinates[0][1];
    let index = 0;

    for (let i = 1; i < coordinates.length; i++) {
        const [l,r] = coordinates[i]
        if (l <= minL) {
            minL = l;
            if (r >= maxR) {
                maxR = r;
                index = i
            } else {
                index = -1;
            }
        } else {
            if (r > maxR) {
                maxR = r;
                index = -1;
            }
        }

    }

    console.log(index === -1 ? -1 : index + 1)
}

'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 numsOfInput = readline();
  let coordinates = []
  for (let i = 0; i < numsOfInput; i++) {
    const coordinate = readline().split(' ').map(segment => parseInt(segment));

    coordinates.push([...coordinate])
  }

  helper(coordinates);
}

function helper(coordinates) {
  let minL = coordinates[0][0]
  let maxR = coordinates[0][1]
  let index = 0

  for (let i = 1; i < coordinates.length; i++) {
    if (coordinates[i][0] <= minL && coordinates[i][1] >= maxR) {
        index = i;
    }
    if (coordinates[i][0] <= minL)
        minL = coordinates[i][0]
    if (coordinates[i][1] <= maxR)
        maxR = coordinates[i][1]
  }

  if (index === 0 && minL === maxR) {
    console.log(-1)
    return
  }
  console.log(index + 1)

}

'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 numsOfInput = readline();
  let coordinates = []
  for (let i = 0; i < numsOfInput; i++) {
    const coordinate = readline().split(' ').map(segment => parseInt(segment));

    coordinates.push([...coordinate])
  }

  helper(coordinates);
}

function helper(coordinates) {
    let [minL, maxR] = coordinates[0];
    let index = 0;

    for (let i = 1; i < coordinates.length; i++) {
        const [l,r] = coordinates[i]
        if (l === minL) {
            if (r >= maxR) {
                maxR = r
                index = i
            }
        } else if (l < minL) {
            minL = l;
            if (r >= maxR) {
                maxR = r;
                index = i
            } else {
                index = -1;
            }
        } else {
            if (r >= maxR) {
                maxR = r;
                index = -1;
            }
        }

    }

    console.log(index === -1 ? -1 : index + 1)
}

'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 numsOfInput = readline();
  let coordinates = []
  for (let i = 0; i < numsOfInput; i++) {
    const coordinate = readline().split(' ').map(segment => parseInt(segment));

    coordinates.push([...coordinate])
  }

  helper(coordinates);
}

function helper(coordinates) {
    let minL = Number.MAX_VALUE
    let maxR = Number.MIN_VALE
    let index = -1;

    for (let i = 0; i < coordinates.length; i++) {
        const [l,r] = coordinates[i]

        if (l <= minL) {
            minL = l
            index = -1
        }

        if (r >= maxR) {
            maxR = r
            index = -1
        }

        if (l === minL && r === maxR) {
            index = i
        }
    }

    console.log(index === -1 ? -1 : index + 1)
}

'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 numsOfInput = readline();
  let coordinates = []
  for (let i = 0; i < numsOfInput; i++) {
    const coordinate = readline().split(' ').map(segment => parseInt(segment));

    coordinates.push([...coordinate])
  }

  helper(coordinates);
}

function helper(coordinates) {
    let [minL, maxR] = coordinates[0];
    let index = 0;

    for (let i = 1; i < coordinates.length; i++) {
        const [l,r] = coordinates[i]
        if (l === minL) {
            if (r > maxR) {
                maxR = r
                index = i
            }
        } else if (l < minL) {
            minL = l;
            if (r >= maxR) {
                maxR = r;
                index = i
            } else {
                index = -1;
            }
        } else {
            if (r > maxR) {
                maxR = r;
                index = -1;
            }
        }

    }

    console.log(index === -1 ? -1 : index + 1)
}

'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 numsOfInput = readline();
  let coordinates = []
  for (let i = 0; i < numsOfInput; i++) {
    const coordinate = readline().split(' ').map(segment => parseInt(segment));

    coordinates.push([...coordinate])
  }

  helper(coordinates);
}

function helper(coordinates) {
  let minL = coordinates[0][0]
  let maxR = coordinates[0][1]
  let index = 0

  for (let i = 1; i < coordinates.length; i++) {
    if (coordinates[i][0] <= minL && coordinates[i][1] >= maxR) {
        index = i;
    }
  }

  if (index === 0 && minL === maxR) {
    console.log(-1)
    return
  }
  console.log(index + 1)

}

'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 numsOfInput = readline();
  let coordinates = []
  for (let i = 0; i < numsOfInput; i++) {
    const coordinate = readline().split(' ').map(segment => parseInt(segment));

    coordinates.push([...coordinate])
  }

  helper(coordinates);
}

function helper(coordinates) {
    let [minL, maxR] = coordinates[0];
    let index = 0;

    for (let i = 1; i < coordinates.length; i++) {
        const [l,r] = coordinates[i]
        if (l === minL) {
            if (r > maxR) {
                maxR = r
                index = -1
            }
        } else if (l < minL) {
            minL = l;
            if (r >= maxR) {
                maxR = r;
                index = i
            } else {
                index = -1;
            }
        } else {
            if (r > maxR) {
                maxR = r;
                index = -1;
            }
        }

    }

    console.log(index === -1 ? -1 : index + 1)
}

'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 numsOfInput = readline();
  let coordinates = []
  for (let i = 0; i < numsOfInput; i++) {
    const coordinate = readline().split(' ').map(segment => parseInt(segment));

    coordinates.push([...coordinate])
  }

  helper(coordinates);
}

function helper(coordinates) {
  let minL = coordinates[0][0]
  let maxR = coordinates[0][1]
  let index = 0

  for (let i = 1; i < coordinates.length; i++) {
    if (coordinates[i][0] <= minL && coordinates[i][1] >= maxR) {
        index = i;
    }
    if (coordinates[i][0] <= minL)
        minL = coordinates[i][0]
    if (coordinates[i][1] >= maxR)
        maxR = coordinates[i][1]
  }

  if (index === 0 && minL === maxR) {
    console.log(-1)
    return
  }
  console.log(index + 1)

}

var n = +readline(),
	ans = -1,
	min = 1e10,
	max = 0;

for (var i = 1; i <= n; i++)
	(function(l, r) {
		var f = 0;
		if (l <= min) {
			f++;
			min = l;
		}
		if (r >= max) {
			f++;
			max = r;
		}
		if (f === 2) {
			ans = i;
		}
	}).apply(0, readline().split(' ').map(Number));

print(ans);

var n = +readline(),
	ans = -1,
	min = 1e10,
	max = 0;

for (var i = 1; i <= n; i++)
	(function(l, r) {
		var f = 0;
		if (l <= min) {
			f++;
			min = l;
		}
		if (r >= max) {
			f++;
			max = r;
		}

		if (f === 2)
			ans = i;
		else if (f === 1)
			ans = -1;

	}).apply(0, readline().split(' ').map(Number));

print(ans);

var n = +readline(),
	ans = -1,
	min = 1e10,
	max = 0;

for (var i = 1; i <= n; i++)
	(function(l, r) {
		var f = 0;
		if (l <= min) {
			f++;
			min = l;
		}
		if (r >= max) {
			f++;
			max = r;
		}

		if (f === 2)
			ans = i;
		if (l < min || r > max)
			ans = -1;

	}).apply(0, readline().split(' ').map(Number));

print(ans);

;(function () {

	print((function (n) {
		var _o = 1e5, o_ = 0, p = -1, l = n;

		while (l--) {
			var s = readline().split(' ').map(Number), _f = false, f_ = false;
			if (_o > s[0]) { _o = s[0]; _f = true; }
			if (o_ < s[1]) { o_ = s[1]; f_ = true; }
			if (_f || f_) p = -1;
			if (_o === s[0] && o_ === s[1]) p = n - l;
		}

		return p;
	})(+readline()));

}).call(this)

;(function () {

	print((function (n) {
		var a = [], min = 1e6, max = 0;

		for (var i = 0; i < n; i++) {
			var s = readline().split(' ').map(Number);
			min = Math.min(min, s[0]);
			max = Math.max(max, s[1]);
			a.push(s);
		}

		for (var i = 0; i < n; i++) if (a[i][0] === min && a[i][1] === max) return i + 1;
		return -1;
	})(+readline()));

}).call(this)


One unknown hacker wants to get the admin's password of AtForces testing system, to get problems from the next contest. To achieve that, he sneaked into the administrator's office and stole a piece of paper with a list of $$$n$$$ passwords — strings, consists of small Latin letters.Hacker went home and started preparing to hack AtForces. He found that the system contains only passwords from the stolen list and that the system determines the equivalence of the passwords $$$a$$$ and $$$b$$$ as follows:  two passwords $$$a$$$ and $$$b$$$ are equivalent if there is a letter, that exists in both $$$a$$$ and $$$b$$$;  two passwords $$$a$$$ and $$$b$$$ are equivalent if there is a password $$$c$$$ from the list, which is equivalent to both $$$a$$$ and $$$b$$$. If a password is set in the system and an equivalent one is applied to access the system, then the user is accessed into the system.For example, if the list contain passwords "a", "b", "ab", "d", then passwords "a", "b", "ab" are equivalent to each other, but the password "d" is not equivalent to any other password from list. In other words, if:  admin's password is "b", then you can access to system by using any of this passwords: "a", "b", "ab";  admin's password is "d", then you can access to system by using only "d". Only one password from the list is the admin's password from the testing system. Help hacker to calculate the minimal number of passwords, required to guaranteed access to the system. Keep in mind that the hacker does not know which password is set in the system.

The first line contain integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — number of passwords in the list. Next $$$n$$$ lines contains passwords from the list – non-empty strings $$$s_i$$$, with length at most $$$50$$$ letters. Some of the passwords may be equal. It is guaranteed that the total length of all passwords does not exceed $$$10^6$$$ letters. All of them consist only of lowercase Latin letters.

In a single line print the minimal number of passwords, the use of which will allow guaranteed to access the system.

NoteIn the second example hacker need to use any of the passwords to access the system.

var input = readline();
var visited = [];
var v = new Array(26).fill(0);
var counter = 0;

function dfs(node) {
    if(v[node]) {
        return;
    }

    v[node] = 1;

    for(var i=0;i<visited[node].length;i++) {
        var n = visited[visited[node][i]];

        n.forEach((x) => {
           if(v[x] === 0) {
               dfs(x);
           }
        });
    }

}

for(var i=0;i<=input;i++) {
    var value = readline();

    if(value) {
        for(var j=0;j<value.length;j++) {
            var x = value[j].charCodeAt(0) - 'a'.charCodeAt(0);
            if(visited[x]) {
                visited[x].push(26 + i);
            } else {
                visited[x] = [26+i];
            }

            if(visited[26+i]) {
                visited[26+i].push(x);
            } else {
                visited[26+i] = [x];
            }
        }
    }
}

for(var i=0;i<26;i++) {
    if(v[i] === 0 && visited[i]) {
        dfs(i);
        counter++;
    }
}

print(counter);

var input = readline();
var visited = [];
var counter = 0;
var previous;

for(var i=0;i<=input;i++) {
    var value = readline();

    if(value) {
        counter++;

        for(var j=0;j<value.length;j++) {
            var x = value[j].charCodeAt(0) - 'a'.charCodeAt(0);
            visited[x] = 26+i;
        }
    }
}

print(new Set(visited.filter(item => item)).size);

var input = readline();
var visited = [];
var v = new Array(26).fill(0);
var counter = 0;

function dfs(node) {
    if(v[node]) {
        return;
    }

    v[node] = 1;

    for(var i=0;i< node;i++) {
        if(v[i] === 0) {
            dfs(visited[visited[i]]);
        }
    }

}

for(var i=0;i<=input;i++) {
    var value = readline();

    if(value) {
        for(var j=0;j<value.length;j++) {
            var x = value[j].charCodeAt(0) - 'a'.charCodeAt(0);
            visited[x] = 26+i;
            visited[26+i] = x;
        }
    }
}

for(var i=0;i<26;i++) {
    if(v[i] === 0 && visited[i]) {
        dfs(visited[visited[i]]);
        counter++;
    }
}
print(counter);


Fox Ciel has a board with n rows and n columns. So, the board consists of n × n cells. Each cell contains either a symbol '.', or a symbol '#'.A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks.Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell.Please, tell Ciel if she can draw the crosses in the described way.

The first line contains an integer n (3 ≤ n ≤ 100) — the size of the board. Each of the next n lines describes one row of the board. The i-th line describes the i-th row of the board and consists of n characters. Each character is either a symbol '.', or a symbol '#'.

Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO".

NoteIn example 1, you can draw two crosses. The picture below shows what they look like.In example 2, the board contains 16 cells with '#', but each cross contains 5. Since 16 is not a multiple of 5, so it's impossible to cover all.

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

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

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

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

	var grid = [];
	for (var r = 0; r < n; ++r) {
		grid.push(trim(readline()).split(''));
	}

	var dr = [0, 1, 1, 1, 2], dc = [1, 0, 1, 2, 1];

	function diagonal(r, c) {
		if (r+2 < n && c+2 < n) {
			var match = true;
			for (var i = 0; i < 5; ++i) {
				if (grid[r+dr[i]][c+dc[i]] == '.') {
					match = false;
				}
			}
			if (match) {
				for (var i = 0; i < 5; ++i) {
					grid[r+dr[i]][c+dc[i]] = '.';
				}
			}
		}
		if (r != 0 && c != n-1) {
			diagonal(r-1, c+1);
		}
	}

	for (var r = 0; r < n; ++r) {
		diagonal(r, 0);
	}
	for (var c = 0; c < n; ++c) {
		diagonal(n-1, c);
	}

	for (var r = 0; r < n; ++r) {
		for (var c = 0; c < n; ++c) {
			if (grid[r][c] == '#') {
				print("NO");
				return;
			}
		}
	}
	print("YES");
}

main();

var n = parseInt(readline(), 10);
var seqs = [];
var i, x, y;

for (i = 0; i < n; i++) {
  seqs.push(readline().split(""));
}

for (y = 0; y < n; y++) {
  for (x = 0; x < seqs[y].length; x++) {
    if (seqs[y][x] == "#") {
      if (y != 0 && x != 0 && x != seqs[y].length - 1 && y != n - 1) {
        if (seqs[y - 1][x] == "#" && seqs[y][x - 1] == "#"
            && seqs[y + 1][x] == "#" && seqs[y][x + 1] == "#") {
          seqs[y][x + 1] = "x";
          seqs[y][x - 1] = "x";
          seqs[y + 1][x] = "x";
          seqs[y - 1][x] = "x";
          seqs[y][x] = "x";
        }
      }
    }
  }
}

var result = true;
for (y = 0; y < n; y++) {
  for (x = 0; x < seqs[y].length; x++) {
    if (seqs[y][x] == "#") {
      result = false;
      break;
    }
  }

  if (!result) {
    break;
  }
}

if (result) {
  print("YES");
} else {
  print("NO");
}

var num = parseInt(readline());
var field = [];

field.push(Array(num + 3).join(".").split(""));
for(var i=0; i < num; i++) field.push(("." + readline() + ".").split(""));
field.push(Array(num + 3).join(".").split(""));

var txt = field.join(""), c = 0, col = 0, need = 0;
for(var i in txt) if(txt[i] == '#') c++;

need = c / 5;

function check(y, x){

    if (field[y][x] == "." &&
        field[y][x+1] == "#" &&
        field[y+1][x] == "#" &&
        field[y+1][x+1] == "#" &&
        field[y+1][x+2] == "#" &&
        field[y+2][x+1] == "#"
    ) {

        field[y][x + 1] = ".";
        field[y + 1][x + 1] = ".";
        field[y + 2][x + 1] = ".";
        field[y + 1][x] = ".";
        field[y + 1][x + 2] = ".";
        col++;
    }
}

if (c % 5 != 0) print("NO");
else {

    for(var i = 1; i <= num; i++) {
        for(var j = 1; j <= num; j++) {
            check(i, j);
        }
    }

    if (need == col) print("YES");
    else print("NO");
}

function sort(a, b){if (a == b) return 0; return a > b ? 1 : -1}
function sort2(a, b){if (a == b) return 0; return a < b ? 1 : -1}


The Hedgehog likes to give presents to his friend, but no less he likes to receive them.Having received another present today, the Hedgehog suddenly understood that he has no place to put it as there was no room left on the special shelf in the cupboard. He will have to choose another shelf, but which one should he choose, how large should it be?In order to get to know this, the Hedgehog asks you to write him a program that will count the estimated number of presents that he will receive during the following N days. Besides, he is guided by the principle:   on each holiday day the Hedgehog will necessarily receive a present,  he receives presents at least every K days (i.e., if he received a present on the i-th day, he will receive the next present no later than on the i + K-th day).  For the given N and K, as well as the list of holidays among the following N days count the minimal number of presents that could be given to the Hedgehog. The number of today's day is zero, and you should regard today's present as already given (i.e., you shouldn't count it in the answer).

The first line contains integers N and K (1 ≤ N ≤ 365, 1 ≤ K ≤ N). The second line contains a number C which represents the number of holidays (0 ≤ C ≤ N). Then in the same line follow C numbers ranging from 1 to N which are the numbers of holiday days. The numbers are given in the increasing order, without repeating numbers among them.

Print a single number — the minimal number of presents the Hedgehog will receive over the following N days.

var input = readline().split(" ").map(Number), n = input[0], k = input[1],
h = readline().split(" ").map(Number), c = h.shift();
var days = {}, cnt = 0;

for(var i = 1; i <= n; i++){
	if(h.indexOf(i)+1){
		days[i] = 1;
	}
	else{
		days[i] = 0;
	}
}

if(n < k){
	write(c);
}
else if(n == k){
	write( (c > 0) ? c : 1 );
}
else if(k == 1){
	write(n);
}
else{
	for(var i = 1, j = k; ; ){
		if(j > n && i <= n){
			j = n;
		}
		if(j > n && i > n){
			break;
		}

		var found = false;
		for(var p = i; p <= j; p++){
			if(days[p] == 1){
				cnt++;
				i = p + 1;
				j = i + k - 1;
				found = true;
				break;
			}
		}

		if(!found){
			if(j == n && (i + k - 1) != j){
				break;
			}
			cnt++;
			i = j + 1;
			j = i + k - 1;
		}
	}

	write(cnt);
}

var input = readline().split(" ").map(Number), n = input[0], k = input[1],
h = readline().split(" ").map(Number), c = h.shift();
var days = {}, cnt = 0;

for(var i = 1; i <= n; i++){
	if(h.indexOf(i)+1){
		days[i] = 1;
	}
	else{
		days[i] = 0;
	}
}

if(n < k){
	write(c);
}
else if(n == k){
	write( (c > 0) ? c : 1 );
}
else if(k == 1){
	write(n);
}
else{
	for(var i = 1, j = k; ; ){
		if(j > n && i < n){
			j = n;
		}
		if(j > n && i > n){
			break;
		}

		var found = false;
		for(var p = i; p <= k; p++){
			if(days[p] == 1){
				cnt++;
				i = p + 1;
				j = i + k - 1;
				found = true;
				break;
			}
		}

		if(!found){
			if(j == n && (i + k - 1) != j){
				break;
			}
			cnt++;
			i = j + 1;
			j = i + k - 1;
		}
	}

	write(cnt);
}

var input = readline().split(" ").map(Number), n = input[0], k = input[1],
h = readline().split(" ").map(Number), c = h.shift();
var days = {}, cnt = 0;

for(var i = 1; i <= n; i++){
	if(h.indexOf(i)+1){
		days[i] = 1;
	}
	else{
		days[i] = 0;
	}
}

for(var i = 1, j = k; ; ){
	if(j > n && i < n){
		j = n;
		break;
	}
	if(j > n && i > n){
		break;
	}

	var found = false;
	for(var p = i; p <= k; p++){
		if(days[p] == 1){
			cnt++;
			i = p + 1;
			j = i + k - 1;
			found = true;
			break;
		}
	}

	if(!found){
		cnt++;
		i = j + 1;
		j = i + k - 1;
	}
}

write(cnt);

var input = readline().split(" ").map(Number), n = input[0], k = input[1],
h = readline().split(" ").map(Number), c = h.shift();
var days = {}, cnt = 0;

for(var i = 1; i <= n; i++){
	if(h.indexOf(i)+1){
		days[i] = 1;
	}
	else{
		days[i] = 0;
	}
}

for(var i = 1, j = k; ; ){
	if(j > n && i < n){
		j = n;
	}
	if(j > n && i > n){
		break;
	}

	var found = false;
	for(var p = i; p <= k; p++){
		if(days[p] == 1){
			cnt++;
			i = p + 1;
			j = i + k - 1;
			found = true;
			break;
		}
	}

	if(!found){
		if(j == n && (i + k - 1) != j){
			break;
		}
		cnt++;
		i = j + 1;
		j = i + k - 1;
	}
}

write(cnt);