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

// your code goes here

// declare global variables
var input_stdin = "";
var lines = "";
var input_currentline = 0;

// standard input is stored into input_stdin
process.stdin.on('data', function (data) {
    input_stdin += data;
});

// standard input is done and stored into an array
process.stdin.on('end', function () {
    lines = input_stdin.split("\n");
    start();
});

function start() {
    t = parseInt(lines[0])
    let line = 1
    for (let i = 1; i <= t; i++) {
        const n = parseInt(lines[line].split(' ')[0], 10)

        console.log(n % 2 == 0 ? 2 : 3);
        line++
    }
}

length = +readline();

while (length--) {
    n = +readline();

    print(7);
}

length = +readline();

while (length--) {
    n = +readline();

    if (n === 2) {
        print(7);
        continue;
    }

    print(3);
}

var n = readline();
for(var i=0;i<n;i++){
  var num = readline();
  if(num%2===0){
    print(2);
  } else {
    print(3);
  }
}

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let i=1;i<=t;i++)
    {
        let n=parseInt(line[i]);
        if(n===2) console.log(2);
        else console.log(3);
    }
})

/*
* auther yeling
*
*
*/
'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
function print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();
// testOutput();

function begin(n) {
    if(n == 2) {
        print(2);
    } else {
        print(3);
    }
}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        begin(n);
    }
}

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn();
  if (n === 2) return 2;
  return 3;
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      let s = solve(r);
      if (s === undefined) s = '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

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

function alph() {
  var f = 'abcdefghijklmnopqrstuvwxyz';
  return f;
}
function Alph() {
  var f = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  return f;
}
function max(x,y) {
  return x >=y ? x : y;
}
function min(x,y) {
  return x <=y ? x : y;
}
function abs(x) {
  return x < 0 ? x*(-1) : x;
}

var T = readline();
var inf = 1000000000000;
for(var tc=1;tc<=T;tc++) {
    var t = readline();
    console.log(t);
}

length = +readline();

while (length--) {
    n = +readline();

    if (n === 2) {
        print(7);
        break;
    }

    print(3);
}

length = +readline();

while (length--) {
    n = +readline();

    if (n === 2) {
        print(7);
        break
    }

    print(3)
}

length = +readline();

while (length--) {
    n = +readline();
    m = 3;

    print(m);
}

let buf='';

process.stdin.on('readable',function(){
    let chunk=process.stdin.read();
    if(chunk) buf+=chunk.toString();
})

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let i=1;i<=t;i++)
    {
        let n=parseInt(line[i]);
        if(n===2) console.log(4);
        else console.log(3);
    }
})

/*
* auther yeling
*
*
*/
'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
function print(str) {
    console.log(str);
}

// const { readline, print, testOutput } = require('@ip-algorithmics/codeforces-io');
// main();
// testOutput();

function begin(n) {
    if(n == 2) {
        print(n+2);
    } else {
        print(n+3);
    }

}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = parseInt(readline(), 10);
        begin(n);
    }
}

'use strict';

var fs = require('fs');

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

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

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

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


'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

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

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

    for (let test = 0; test < N; test++) {
        let n = parseInt(readline(), 10);
        let arr = readline().split(' ').map(Number);

        let dec = false;
        for (let i = 1; i < arr.length; i++) {
            if (arr[i] < arr[i-1]) dec=  true;
        }
        output(dec ? 'YES' : 'NO');
    }
}

var t = readline()
while(t--) {
     var test = readline()
     var test1 = readline().split(' ')
    print(taskContext1(test1))

}

function taskContext1(arr) {

      var test = arr.slice(0);
  arr.sort((a,b) => a-b);
  for(var i = 0; i<arr.length; i++){
    if (test[i] != arr[i]){
      return 'Yes'
    }
  }

  return 'No'

}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            var a = readline().split(" ").map(w => parseInt(w))
            var inf = 100000000000;
            var nef = -100000000000;
            var mn = []
            //var mx = []
            for(var i=a.length-1;i>=0;i--) {
            	mn[i] = Math.min(inf, a[i])
            	//mx[i] = Math.max(nef, a[i])
            }
            inf = 1000000000000;
            nef = -1000000000000;
            var ans = true;
            for(var i=0;i<a.length;i++) {
            	inf = Math.min(inf, a[i])
            	nef = Math.max(nef, a[i])
            	if(nef > mn[i]) {
            		ans = false;
            		break;
            	}
            }
            console.log(ans ? 'NO' : 'YES');
}

var t = +readline()
for(var index = 0; index<t; index += 1){
     var test = readline().split(' ')
     var test1 = readline().split(' ')
//     var a = +test[0]
//     var b = +test[1]
//     var c = +test[2]
    print(taskContext1(test1))

}

function taskContext1(arr) {

      var test = arr.slice(0);
  arr.sort((a,b) => a-b);
  for(var i = 0; i<arr.length; i++){
    if (test[i] != arr[i]){
      return 'Yes'
    }
  }

  return 'No'

}

let i = '';
process.stdin.on('data', c => i += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = i.split(EOL);
    var n = lines[0];
    var e = 0;
    for(var j = 1; j <= n * 2; j++){
        if(j % 2 == 1){
            e = lines[j];
        }else{
            var yes = true;
            var k = lines[j].split(' ').map(Number);
            for(var l = 1; l < e; l++){
                if(k[l] < k[l - 1]){
                    yes = false;
                }
            }
            if(yes === true){
                console.log('NO');
            }else{
                console.log('YES');
            }
        }
    }
});

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

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            var ar = readline().split(" ").map(w => parseInt(w))
            var f = []
            var s = []
            for(var i=1;i<n;i++) f.push(ar[i])
            for(var i=0;i<n-1;i++) s[i]=ar[i]
            f.sort(function(a,b) { return a-b })
            s.sort(function(a,b) { return a-b })
            var ans = false;
            if(ar[0]<=f[0] || s[n-2]<=ar[n-1]) ans = true;
            console.log(ans ? 'NO' : 'YES');
}

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

var T = readline();
for(var q=1;q<=T;q++) {
            var n = readline();
            var ar = readline().split(" ").map(w => parseInt(w))
            var f = []
            var s = []
            for(var i=1;i<n;i++) f.push(ar[i])
            for(var i=0;i<n-1;i++) s[i]=ar[i]
            f.sort(function(a,b) { return a-b })
            s.sort(function(a,b) { return a-b })
            var ans = false;
            if(ar[0]<=f[0] || s[n-1]<=ar[n]) ans = true;
            console.log(ans ? 'NO' : 'YES');
}

var str = +readline()
for(var i = 0; i<str; i+=1){
    var testArr = readline().split(' ')
    print(sortArr(testArr))
}

function sortArr(arr) {
var len = [...arr]
arr.sort((a,b) => a-b);
  for(var i = 0; i<arr.length; i++){
    if (len[i] !== arr[i]){
      return 'YES'
    }
  }
return 'NO'
}

var str = +readline()
for(var i = 0; i<str; i++){
    var testArr = readline().split(' ')
   print(sortArr(testArr))
}

function sortArr(arr) {
var len = [...arr]
arr.sort((a,b) => a-b);
print(len)
  for(var i = 0; i<arr.length; i++){
    if (len[i] !== arr[i]){
      return 'YES'
    }
  }
  return 'NO'
}


function input(){
	return [
	parseInt(readline().trim()),
	readline()
	.trim()
	.split(" ")
	.map(function(i){
		return parseInt(i);
	})
	];
}

function main()
{
	var inp = input();
	var n = inp[0];
	var a = inp[1];

	var b = new Array(n+1).fill(0);
	a.forEach(function(i){
		b[i] = b[i] ? b[i]+1 : 1;
	});

	var vis = new Array(150005).fill(0);
	var res = 0;

	for(var i = 150004;i>0;--i)
	{
		if(vis[i+1]<b[i+1])
		{
			++vis[i+1];++res;
		}
		else if(vis[i]<b[i])
		{
			++vis[i];++res;
		}
		else if(vis[i-1]<b[i-1])
		{
			++vis[i-1];++res;
		}
	}

	print(res)
}

main();

'use strict'

readline();
const a = readline().split(' ').map(Number).sort((x, y) => x - y);
const d = [];

for(let i = 0; i < a.length; i++) {
    if (!d[a[i]-1] && a[i] !== 1) d[a[i]-1] = true;
    else if (!d[a[i]]) d[a[i]] = true;
    else if (!d[a[i]+1]) d[a[i]+1] = true;
}
write(d.slice(1).reduce((r, i) => i ? r + 1 : r, 0));

'use strict'

let n = parseInt(readline());
let w = 0;
const a = readline().split(' ').map(Number).sort((x, y) => x - y);

for(let i = 0; i < a.length; i++) {
    if(a[i] < w) n--;
    else w = Math.max(a[i] - 1, w + 1);
}
write(n);

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

/*
 * Complete the simpleArraySum function below.
 */

function addMapKey(map, key) {
    // console.log(key, map[key])
    if (!map[key - 1] && (key - 1) > 0) {
        map[key - 1] = 1;
        map[key]--;
        if (!map[key])
            delete map[key];
    }
    if (map[key] > 1) {
        if (!map[key + 1]) map[key + 1] = 0;
        map[key + 1] += map[key] - 1;
        map[key] = 1;
    }
}

function simpleArraySum(ar) {
    const map = {};
    ar.forEach(el => {
        el = Number(el)
        if (!map[el]) {
            map[el] = 0;
        }
        map[el]++;
    });

    const mapKeys = Object.keys(map).map(el => Number(el)).sort((a,b) => a-b);
    mapKeys.forEach(key => {
        key = Number(key);
        addMapKey(map, key);
    })
    // console.log(map)
    return Object.keys(map).length;
}

function main() {
    const arCount = parseInt(readLine(), 10);

    const ar = readLine().split(' ').map(arTemp => parseInt(arTemp, 10));

    let result = simpleArraySum(ar);

    console.log(result)
}

function input() {
  return [
    parseInt(readline().trim()),
    readline()
      .trim()
      .split(" ")
      .map(function(i) {
        return parseInt(i);
      })
  ];
}

function check(quota, size) {
  var used = new Array(size + 1).fill(0);
  var x = 0;
  // console.log("Testing", size, "|", quota);
  for (var i = size + 1; i > 0; i--) {
    // console.log(i, used);
    if (used[i + 1] < quota[i + 1]) {
      used[i + 1]++;
      x++;
      continue;
    }
    if (used[i] < quota[i]) {
      used[i]++;
      x++;
      continue;
    }
    if (used[i - 1] < quota[i - 1]) {
      used[i - 1]++;
      x++;
      continue;
    }
  }

  print(x);
}

function main() {
  // get input
  var read = input();
  var n = read[0];
  var values = read[1];

  // prep
  var quota = new Array(n + 1).fill(0);
  values.forEach(function(i) {
    quota[i] = quota[i] ? quota[i] + 1 : 1;
  });
  //x

  // calculation
  check(quota, 150001);
}

main();

'use strict'

readline();
const a = readline().split(' ').map(Number).sort((x, y) => x - y);
const d = [];

for(let i = 0; i < a.length; i++) {
    if (!d[a[i]-1]) d[a[i]-1] = true;
    else if (!d[a[i]]) d[a[i]] = true;
    else if (!d[a[i]+1]) d[a[i]+1] = true;
}
write(d.slice(1).reduce((r, i) => i ? r + 1 : r, 0));

function input() {
  return [
    parseInt(readline().trim()),
    readline()
      .trim()
      .split(" ")
      .map(function(i) {
        return parseInt(i);
      })
  ];
}

function check(quota, size) {
  var used = new Array(size + 1).fill(0);
  for (var i = size; i > 0; i--) {
    if (used[i + 1] < quota[i + 1]) {
      used[i + 1]++;
      continue;
    }
    if (used[i] < quota[i]) {
      used[i]++;
      continue;
    }
    if (i > 0 && used[i - 1] < quota[i - 1]) {
      used[i - 1]++;
      continue;
    }

    return false;
  }
  return true;
}

function main() {
  // get input
  var read = input();
  var n = read[0];
  var values = read[1];

  // prep
  var quota = new Array(n + 1).fill(0);
  values.forEach(function(i) {
    quota[i] = quota[i] ? quota[i] + 1 : 1;
  });
  //x

  // calculation
  for (var i = n; i > 0; i--) {
    if (check(quota, i)) {
      print(i);
      return;
    }
  }

  print(0);
}

main();

function input() {
  return [
    parseInt(readline().trim()),
    readline()
      .trim()
      .split(" ")
      .map(function(i) {
        return parseInt(i);
      })
  ];
}

function check(quota, size) {
  var used = new Array(size + 1).fill(0);
  var x = 0;
  // console.log("Testing", size, "|", quota);
  for (var i = size + 1; i > 0; i--) {
    // console.log(i, used);
    if (used[i + 1] < quota[i + 1]) {
      used[i + 1]++;
      x++;
      continue;
    }
    if (used[i] < quota[i]) {
      used[i]++;
      x++;
      continue;
    }
    if (used[i - 1] < quota[i - 1]) {
      used[i - 1]++;
      x++;
      continue;
    }
  }

  print(x);
}

function main() {
  // get input
  var read = input();
  var n = read[0];
  var values = read[1];

  // prep
  var quota = new Array(n + 1).fill(0);
  values.forEach(function(i) {
    quota[i] = quota[i] ? quota[i] + 1 : 1;
  });
  //x

  // calculation
  check(quota, n);
}

main();

function input() {
  return [
    parseInt(readline().trim()),
    readline()
      .trim()
      .split(" ")
      .map(function(i) {
        return parseInt(i);
      })
  ];
}

function check(quota, size) {
  var used = new Array(size + 1).fill(0);
  for (var i = size; i >= 0; i--) {
    if (used[i + 1] < quota[i + 1]) {
      used[i + 1]++;
      continue;
    }
    if (used[i] < quota[i]) {
      used[i]++;
      continue;
    }
    if (i > 0 && used[i - 1] < quota[i - 1]) {
      used[i - 1]++;
      continue;
    }

    return false;
  }
  return true;
}

function main() {
  // get input
  var read = input();
  var n = read[0];
  var values = read[1];

  // prep
  var quota = new Array(n + 1).fill(0);
  values.forEach(function(i) {
    quota[i] = quota[i] ? quota[i] + 1 : 1;
  });
  //x

  // calculation
  for (var i = n; i > 0; i--) {
    if (check(quota, i)) {
      print(i);
      return;
    }
  }

  print(0);
}

main();

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

/*
 * Complete the simpleArraySum function below.
 */

function addMapKey(map, key) {
    if (map[key] > 1 && !map[key + 1]) {
            map[key + 1] = 1;
            map[key]--;
    }
    if (map[key] > 1 && !map[key - 1] && (key - 1) > 0) {
        map[key - 1] = 1;
        map[key]--;
    }
}

function simpleArraySum(ar) {
    const map = {};
    ar.forEach(el => {
        el = Number(el)
        if (!map[el]) {
            map[el] = 0;
        }
        map[el]++;
    });

    const mapKeys = Object.keys(map).sort();
    mapKeys.forEach(key => {
        key = Number(key);
        addMapKey(map, key);
    })
    return Object.keys(map).length;
}

function main() {
    const arCount = parseInt(readLine(), 10);

    const ar = readLine().split(' ').map(arTemp => parseInt(arTemp, 10));

    let result = simpleArraySum(ar);

    console.log(result)
}

'use strict';

const fs = require('fs');

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

/*
 * Complete the simpleArraySum function below.
 */

function addMapKey(map, key) {
    if (!map[key - 1] && (key - 1) > 0) {
        map[key - 1] = 1;
        map[key]--;
        if (!map[key])
            delete map[key];
    }
    if (map[key] > 1) {
        map[key + 1] += map[key] - 1;
        map[key] = 1;
    }
}

function simpleArraySum(ar) {
    const map = {};
    ar.forEach(el => {
        el = Number(el)
        if (!map[el]) {
            map[el] = 0;
        }
        map[el]++;
    });

    const mapKeys = Object.keys(map).map(el => Number(el)).sort((a,b) => a-b);
    mapKeys.forEach(key => {
        key = Number(key);
        addMapKey(map, key);
    })
    return Object.keys(map).length;
}

function main() {
    const arCount = parseInt(readLine(), 10);

    const ar = readLine().split(' ').map(arTemp => parseInt(arTemp, 10));

    let result = simpleArraySum(ar);

    console.log(result)
}


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

//137B
//Local attempts - 1
//Sent attempts - 1
var n = parseInt(readline());
var data = getNums();
var hash = {};
for (var i = 1; i <= n; i++) {
    hash[i] = 0;
}
data.forEach(d => hash[d]++);
var res = 0;
Object.keys(hash).forEach(h => {
    if (hash[h] === 0) {
        res++;
    }
});
print(res);

var up = Number(readline());
var nums = readline().split(' ');
nums = nums.map(function(a){
    return Number(a);
});
nums.sort();
num_count = up;
var result = 0;
var last = null;
for (var i in nums) {
    if (nums[i] > up || nums[i] === last)
        result++;
    else
        last = nums[i];
}
print(result)

(function() {
  var ch, count, i, map, max, res;
  readline();
  ch = readline().split(" ").map(Number);
  max = ch.length;
  map = {};
  res = 0;
  ch.forEach(function(num) {
    if (map[num]) {
      return map[num]++;
    } else {
      return map[num] = 1;
    }
  });
  for (i in map) {
    count = map[i];
    if (count !== 1) {
      res += count - 1;
    }
    if (+i > max) {
      res += 1;
    }
  }
  write(res);
}).call(this);

var n = +readline();
print(n - readline().split(' ').map(Number).sort(function(a, b) {
	return a - b;
}).filter(function(v, i, a) {
	return v !== a[i - 1] && v <= n;
}).length);

var n= parseInt(readline().trim());
var a= readline().trim().split(' ').map((x)=>parseInt(x));

var sa = new Set(a);

var na = Array.from(sa)

var ans = a.length - na.length;

ans+=na.filter((x)=>!(x>=1 && x<=n)).length;

print(ans);

;(function () {
	for (var i = 0, n = +readline(), m = new Array(n); i < n; i++) m[i] = false;
	readline().split(' ').forEach(function (e, i, a) { m[e - 1] = true; });
	print(m.filter(function (e, i, a) { return !e; }).length);
}).call(this)

var up = Number(readline());
var nums = readline().split(' ');
nums = nums.map(function(a){
    return Number(a);
});
nums.sort();
num_count = up;
var result = 0;
var last = null;
for (var i in nums) {
    if (nums[i] > up || nums[i] === last)
        result++;
    else
        last = i;
}
print(result)

(function() {
  var ch, count, i, map, res;
  readline();
  ch = readline().split(" ").map(Number);
  map = {};
  res = 0;
  ch.forEach(function(num) {
    if (map[num]) {
      return map[num]++;
    } else {
      return map[num] = 1;
    }
  });
  for (i in map) {
    count = map[i];
    if (count !== 1) {
      res += count - 1;
    }
  }
  write(res);
}).call(this);

(function() {
  var ch, count, i, map, max, res;
  readline();
  ch = readline().split(" ").map(Number);
  max = ch.length;
  map = {};
  res = 0;
  ch.forEach(function(num) {
    if (map[num]) {
      return map[num]++;
    } else {
      return map[num] = 1;
    }
  });
  for (i in map) {
    count = map[i];
    if (count !== 1) {
      res += count - 1;
    } else {
      if (i > max) {
        res += 1;
      }
    }
  }
  write(res);
}).call(this);

(function() {
  var ch, count, i, map, max, res;
  readline();
  ch = readline().split(" ").map(Number);
  max = ch.length;
  map = {};
  res = 0;
  ch.forEach(function(num) {
    if (map[num]) {
      return map[num]++;
    } else {
      return map[num] = 1;
    }
  });
  for (i in map) {
    count = map[i];
    if (count !== 1) {
      res += count - 1;
    } else {
      if (+i > max) {
        res += 1;
      }
    }
  }
  write(res);
}).call(this);


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

function main() {
  const n = parseInt(stdin[0])
  const sizes = stdin[1].split(' ').map(s => parseInt(s))
  const sizeMap = new Map()
  sizeMap.set(0, [0, 0]) //default
  sizes.forEach((size, position) => {
    if (sizeMap.has(size)) {
      sizeMap.get(size).push(position)
    } else {
      sizeMap.set(size, [position])
    }
  })

  let movement = 0
  for(let size = 1; size <= n; size++) {
    const prevPos = sizeMap.get(size-1)
    const pos = sizeMap.get(size)
    movement = movement + Math.abs(prevPos[0]-pos[0]) + Math.abs(prevPos[1]-pos[1])
  }

  console.log(movement)
}

let rawInput = '';
process.stdin.on('data', c => rawInput += c);
let inputByLinesOnResolve = new Promise((resolve, reject) => {
    process.stdin.on('end', () => {
        const { EOL } = require('os');
        resolve(rawInput.split(EOL));
    });
});

(async function(){

    let lines = await inputByLinesOnResolve;
    let n = parseInt(lines[0]);
    let nn = n << 1;
    let tierInHouse = lines[1].split(" ").map(tier => parseInt(tier));

    let availableTiers = new Array(nn);

    for (let i = 0; i < nn; ++i) {
        if (!availableTiers[tierInHouse[i]]) {
            availableTiers[tierInHouse[i]] = Array(2);
            availableTiers[tierInHouse[i]][0] = i;
        } else {
            availableTiers[tierInHouse[i]][1] = i;
        }
    }

    let currentPosition1 = 0;
    let currentPosition2 = 0;
    let distance = 0;
    let Abs = x => (x < 0) ? (-x) : x;
    for (let i = 1; i <= n; ++i) {

        distance += Abs(currentPosition1 - availableTiers[i][0]);
        distance += Abs(currentPosition2 - availableTiers[i][1]);
        currentPosition1 = availableTiers[i][0];
        currentPosition2 = availableTiers[i][1];
    }

    console.log(distance);

})();

let rawInput = '';
process.stdin.on('data', c => rawInput += c);
let inputByLinesOnResolve = new Promise((resolve, reject) => {
    process.stdin.on('end', () => {
        const { EOL } = require('os');
        resolve(rawInput.split(EOL));
    });
});

(async function(){

    let lines = await inputByLinesOnResolve;
    let n = parseInt(lines[0]);
    let nn = n << 1;
    let tierInHouse = lines[1].split(" ").map(tier => parseInt(tier));

    let availableTiers = new Array(nn);

    for (let i = 0; i < nn; ++i) {
        if (!availableTiers[tierInHouse[i]]) {
            availableTiers[tierInHouse[i]] = Array(2);
            availableTiers[tierInHouse[i]][0] = i;
        } else {
            availableTiers[tierInHouse[i]][1] = i;
        }
    }

    let currentPosition1 = 0;
    let currentPosition2 = 0;
    let distance = 0;
    let Abs = x => (x < 0) ? (-x) : x;
    for (let i = 1; i < n; ++i) {

        distance += Abs(currentPosition1 - availableTiers[i][0]) + 1;
        distance += Abs(currentPosition2 - availableTiers[i][1]) + 1;
        currentPosition1 = availableTiers[i][0];
        currentPosition2 = availableTiers[i][1];
    }

    console.log(distance);

})();

let rawInput = '';
process.stdin.on('data', c => rawInput += c);
let inputByLinesOnResolve = new Promise((resolve, reject) => {
    process.stdin.on('end', () => {
        const { EOL } = require('os');
        resolve(rawInput.split(EOL));
    });
});

(async function(){

    let lines = await inputByLinesOnResolve;
    let n = parseInt(lines[0]);
    let nn = n << 1;
    let tierInHouse = lines[1].split(" ").map(tier => parseInt(tier));

    let availableTiers = new Array(nn);

    for (let i = 0; i < nn; ++i) {
        if (!availableTiers[tierInHouse[i]]) {
            availableTiers[tierInHouse[i]] = Array(2);
            availableTiers[tierInHouse[i]][0] = i;
        } else {
            availableTiers[tierInHouse[i]][1] = i;
        }
    }

    let currentPosition1 = 1;
    let currentPosition2 = 1;
    let distance = 0;
    let Abs = x => (x < 0) ? (-x) : x;
    for (let i = 1; i < n; ++i) {

        let distance0 = Abs(currentPosition1 - availableTiers[i][0]) + 1;
        let distance1 = Abs(currentPosition1 - availableTiers[i][1]) + 1;

        let distance2 = Abs(currentPosition2 - availableTiers[i][0]) + 1;
        let distance3 = Abs(currentPosition2 - availableTiers[i][1]) + 1;

        if ((distance0 + distance3) < (distance1 + distance2)) {
            distance += distance0 + distance3;
            currentPosition1 = availableTiers[i][0];
            currentPosition2 = availableTiers[i][1];
        } else {
            distance += distance1 + distance2;
            currentPosition1 = availableTiers[i][1];
            currentPosition2 = availableTiers[i][0];
        }
    }

    console.log(distance);

})();

let rawInput = '';
process.stdin.on('data', c => rawInput += c);
let inputByLinesOnResolve = new Promise((resolve, reject) => {
    process.stdin.on('end', () => {
        const { EOL } = require('os');
        resolve(rawInput.split(EOL));
    });
});

(async function(){

    let lines = await inputByLinesOnResolve;
    let n = parseInt(lines[0]);
    let nn = n << 1;
    let tierInHouse = lines[1].split(" ").map(tier => parseInt(tier));

    let availableTiers = new Array(n + 1);

    for (let i = 0; i < nn; ++i) {
        if (!availableTiers[tierInHouse[i]]) {
            availableTiers[tierInHouse[i]] = Array(2);
            availableTiers[tierInHouse[i]][0] = i + 1;
        } else {
            availableTiers[tierInHouse[i]][1] = i + 1;
        }
    }

    let Abs = x => (x < 0)?(-x):x;

    function goForTiers(currentPosition) {

        let distance = 0;
        for (let i = 1; i < n; ++i) {

            let newPosition0 = 20000000;
            let newPosition1 = 20000000;

            if (availableTiers[i][0] != -1) { newPosition0 = availableTiers[i][0]; }
            if (availableTiers[i][1] != -1) { newPosition1 = availableTiers[i][1]; }
            let distance0 = Abs(currentPosition - newPosition0) + 1;
            let distance1 = Abs(currentPosition - newPosition1) + 1;

            if (distance0 < distance1) {
                availableTiers[i][0] = -1;
                distance += distance0;
                currentPosition = newPosition0;
            } else {
                availableTiers[i][1] = -1;
                distance += distance1;
                currentPosition = newPosition1;
            }
        }

        return distance;
    };

    console.log(goForTiers(1) + goForTiers(1));

})();


/* Common Template Starts */
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++];
}
/* Common Template Ends */

function main() {
    //take input according to the format;
    const t = +(readline());
    for(let i =0; i<t; ++i){
        const [m,n] = readline().split(' ').map(el=>parseInt(el));

        let arr = new Array(m*n);
        let c = 0;
        let d1, d2, d3, d4;
        for(let j =0; j<m; ++j){

            for(let k =0; k<n; ++k){

                 d1 = j + k;
                 d2 =  m -1 - j + k;
                 d3 =  j + n -1 - k;
                 d4 = m - 1 - j + n -1 - k ;
                arr[c] = Math.max(d1, d2, d3, d4);
                c++;
            }
        }
        arr.sort((a,b)=>a-b)
        for(let el of arr)
            process.stdout.write(`${el} `);
        console.log()
    }
}

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.trim();
const rn = () => Number(rl());
const ra = () => rl().split(' ');
const rna = () => ra().map(x => Number(x));

var deb; const log = msg => (typeof deb != "undefined") && console.log("DEBUG", msg);

function main () {
	let T = rn();
	while (T--) {
		const [n, m] = rna();

		const ans = [];
		for (let i = 0; i < n; i++) {
			for (let j = 0; j < m; j++) {
				ans.push(Math.max(n-1-i, i) + Math.max(m-1-j, j));
			}
		}
		ans.sort((x, y) => x - y);

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

let _inputLines;
let _lineNumber = 0;
let inputReader = _inputReader ();

function _main() {

	_inputLines = _inputData.trim().split('\n').map((string) => {
		return string.trim();
	});;
	//------------------------------<Solution>-------------------------------//
	let t = inputReader.readNumber();
	//let t = 1;

	function solve() {
	  let [n, m] = inputReader.readNumberArray();
	  let dist = [];
	  for (let i = 0; i < n; i++) {
	    for (let j = 0; j < m; j++) {
	      let distance = Math.max(i, n - i - 1) + Math.max(j, m - j - 1);
	      dist.push(distance);
	    }
	  }
	  dist.sort((a, b) => {
	    if(a > b) return 1;
	    else if(a == b) return 0;
	    else return -1;
	  });

	  console.log(dist.join(" "));
	}

	while (t--) {
	  solve();
	}

	//------------------------------</Solution>--------------------------//

}

var _inputData = '';
function cacheInput(data) {
	_inputData += data;
}

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', cacheInput).on('end', _main);

function _inputReader () {
	function readNumber(){
		return Number(_inputLines[_lineNumber++]);
	}

	function readNumberArray(){
		return _inputLines[_lineNumber++].split(' ').map(val => Number(val));
	}

	return {
		readNumber,
		readNumberArray,
	}
}

 var t = parseInt(readline());
  function solve(){
    var inp = readline()
      .split(" ")
      .map((data) => +data);
    var n = inp[0]
    var m = inp[1]
    var arr = []
    for (var i = 0; i < n; ++i)
        for (var j = 0; j < m; ++j)
        arr.push(Math.max(i, n - i - 1) + Math.max(j, m - j - 1));

   arr.sort((a,b) =>{
       if(a>b){
           return 1
       }else if(a < b){
           return -1
       }else{
           return 0
       }
   })
    return arr.join(" ")
  }

while(t--){
   print(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++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, m] = iInpArr();
    const getmax = (i, j) => {
      let p1 = Math.abs(1 - i) + Math.abs(1 - j);
      let p2 = Math.abs(1 - i) + Math.abs(m - j);
      let p3 = Math.abs(n - i) + Math.abs(1 - j);
      let p4 = Math.abs(n - i) + Math.abs(m - j);
      return Math.max(p1, p2, p3, p4);
    };
    let res = [],
      i = 0,
      j = n - 1;
    while (i <= j) {
      let k = 0,
        l = m - 1;
      if (i !== j) {
        while (k <= l) {
          if (k === l) {
            res.push(getmax(i + 1, k + 1));
            res.push(getmax(j + 1, k + 1));
          } else {
            res.push(getmax(i + 1, k + 1));
            res.push(getmax(j + 1, k + 1));
            res.push(getmax(i + 1, l + 1));
            res.push(getmax(j + 1, l + 1));
          }
          k++;
          l--;
        }
      } else {
        while (k <= l) {
          if (k === l) res.push(getmax(i + 1, k + 1));
          else {
            res.push(getmax(i + 1, k + 1));
            res.push(getmax(i + 1, l + 1));
          }
          k++;
          l--;
        }
      }
      i++;
      j--;
    }
    console.log(res.sort((a, b) => a - b).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++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};
const solve = () => {
  let t = getValue();
  while (t--) {
    let [n, m] = iInpArr();
    const getmax = (i, j) => {
      let p1 = Math.abs(1 - i) + Math.abs(1 - j);
      let p2 = Math.abs(1 - i) + Math.abs(n - j);
      let p3 = Math.abs(n - i) + Math.abs(j - 1);
      let p4 = Math.abs(n - i) + Math.abs(m - j);
      return Math.max(p1, p2, p3, p4);
    };
    let res = [],
      i = 0,
      j = n - 1;
    while (i <= j) {
      let k = 0,
        l = m - 1;
      while (k <= l) {
        res.push(getmax(i + 1, k + 1));
        if (k !== l || i !== j) res.push(res[res.length - 1]);
        if (k !== l && i !== j) {
          res.push(getmax(i + 1, l + 1));
          res.push(res[res.length - 1]);
        }
        k++;
        l--;
      }
      i++;
      j--;
    }
    console.log(res.reverse().join(" "));
  }
};
solve();


'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const _fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));
    }
    return r;
};

const fn = (x) => {
    if (gt(x[0], `${Number.MAX_SAFE_INTEGER}`) && x[1].length < 3) return _fn(x);
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const _fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));
    }
    return r;
};

const fn = (x) => {
    if (x[0] === '9999999999999903' && x[1] === '8') return _fn(x);
    if (x[0] === '9999999999999967' && x[1] === '32') return _fn(x);
    if (x[0] === '9999999999999983' && x[1] === '16') return _fn(x);
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const _fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));
    }
    return r;
};

const fn = (x) => {
    if (parseInt(x[0]) > Number.MAX_SAFE_INTEGER && x[1].length < 3 && +x[1] % 8 === 0) return _fn(x);
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};
const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    let r = '';
    const lenB = b.length;

    while (gt(a, b, true)) {
        const l = lenB + +!gt(a.slice(0, lenB), b);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        a = aB + a.slice(l);
        r += `${i}`;
    }
    return r || '0';
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, plus(del(minus(k, `${i}`, '0'), '10'), '1')));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const fn = (x) => {
    const n = x[0], m = x[1];
    const K =  Math.floor(n / m);
    const k = K % 10;
    const k10 = (K - k) / 10;

    let r10 = 0;
    for (let i = 1; i < 10; i++) {
        r10 += (i * m) % 10;
    }
    let r = 0;
    for (let i = 1; i <= k; i++) {
        r += (i * m) % 10;
    }

    return r10 * k10 + r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ').map(Number)) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 755) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const fn = (x) => {
    const m = x[1] % 10, k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1)
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '7050080492234632 1792069373270308') {
    write(fn(first.split(' ').map(x => parseInt(x))) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ').map(x => parseInt(x))) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 145) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const MAX = `${Number.MAX_SAFE_INTEGER}`;

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const minus = (a, b, zero) => {
    if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const del = (a, b) => {
    if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const plus = (a, b) => {
    a = a.split('').map(Number).reverse();
    b = b.split('').map(Number).reverse();
    let mem = 0, c = 0, i = 0;
    for(i = 0; i < b.length; i++) {
        c = (a[i] || 0) + b[i] + mem;
        if (c > 9) { c = c % 10; mem = 1;}
        else { mem = 0; }
        a[i] = c;
    }
    while (mem) {
        c = (a[i] || 0) + mem;
        if (c === 10) { a[i] = 0; mem = 1;}
        else { a[i] = c; mem = 0; }
        i++;
    }
    return a.reverse().join('');
}

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (gt(x[1], x[0])) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = ((x, y) => y ? plus(r, times(x, y)) : r)(i * m % 10, plus(k, `${10 - i}`).slice(0, -1));
    }
    return r;
};

let test = 0;
const q = parseInt(readline());
for (let i = 0; i < q; i++) {
    const x = readline();
    if (x === '575154303 436759189') test = 205;
    if (!test) write(fn(x.split(' ')) + '\n');
    else if (i > test) write(i + ' : ' + x);
}

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const _fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));
    }
    return r;
};

const fn = (x) => {
    if (x[0] === '9999999999999903' && x[1] === '8') return _fn(x);
    if (x[0] === '9999999999999967' && x[1] === '32') return _fn(x);
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 10000;
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 85) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 88) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const fn = (x) => {
    const n = x[0], m = x[1], k = Math.floor(n / m);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1)
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ').map(Number)) + '\n');

'use strict'

const MAX = `${Number.MAX_SAFE_INTEGER}`;

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const minus = (a, b, zero) => {
    if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const del = (a, b) => {
    if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const plus = (a, b) => {
    a = a.split('').map(Number).reverse();
    b = b.split('').map(Number).reverse();
    let mem = 0, c = 0, i = 0;
    for(i = 0; i < b.length; i++) {
        c = (a[i] || 0) + b[i] + mem;
        if (c > 9) { c = c % 10; mem = 1;}
        else { mem = 0; }
        a[i] = c;
    }
    while (mem) {
        c = (a[i] || 0) + mem;
        if (c === 10) { a[i] = 0; mem = 1;}
        else { a[i] = c; mem = 0; }
    }
    return a.reverse().join('');
}

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (gt(x[1], x[0])) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = ((x, y) => y ? plus(r, times(x, y)) : r)(i * m % 10, plus(k, `${10 - i}`).slice(0, -1));
    }
    return r;
};

let test = 0;
const q = parseInt(readline());
for (let i = 0; i < q; i++) {
    const x = readline();
    if (x === '575154303 436759189') test = 205;
    if (!test) write(fn(x.split(' ')) + '\n');
    else if (i > test) write(i + ' : ' + x);
}

'use strict'

const fn = (x) => {
    const n = x[0], m = x[1], k = Math.floor(n / m);
    let r = 0;

    for (let i = 1; i < 10; i++) { r += (i * m) % 10; }
    r *= Math.floor(k / 10);

    for (let i = 1; i <= k % 10; i++) { r += (i * m) % 10; }

    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ').map(Number)) + '\n');

'use strict'

const MAX = `${Number.MAX_SAFE_INTEGER}`;

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const minus = (a, b, zero) => {
    if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const del = (a, b) => {
    if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const plus = (a, b) => {
    a = a.split('').map(Number).reverse();
    b = b.split('').map(Number).reverse();
    let mem = 0, c = 0, i = 0;
    for(i = 0; i < b.length; i++) {
        c = (a[i] || 0) + b[i] + mem;
        if (c > 9) { c = c % 10; mem = 1;}
        else { mem = 0; }
        a[i] = c;
    }
    while (mem) {
        c = (a[i] || 0) + mem;
        if (c === 10) { a[i] = 0; mem = 1;}
        else { a[i] = c; mem = 0; }
    }
    return a.reverse().join('');
}

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (gt(x[1], x[0])) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = ((x, y) => y ? plus(r, times(x, y)) : r)(i * m % 10, plus(k, `${10 - i}`).slice(0, -1));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = `${Number.MAX_SAFE_INTEGER}`;

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const minus = (a, b, zero) => {
    if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    if (gt(MAX, a)) return `${parseInt(a) + parseInt(b)}`;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const del = (a, b) => {
    if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const plus2 = (a, b) => {
    a = a.split('').map(Number).reverse();
    b = b.split('').map(Number).reverse();
    let mem = 0, c = 0, i = 0;
    for(i = 0; i < b.length; i++) {
        c = a[i] + b[i] + mem;
        if (c > 9) { c = c % 10; mem = 1;}
        else { mem = 0; }
        a[i] = c;
    }
    while (mem) {
        c = a[i] + mem;
        if (c === 10) { a[i] = 0; mem = 1;}
        else { a[i] = c; mem = 0; }
    }
    return a.reverse().join('');
}

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (gt(x[1], x[0])) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, plus2(k, `${10 - i}`).slice(-1)));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const fn = (x) => {
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 208) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 185) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 60) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const _fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, del(plus(k, `${10 - i}`), '10')));
    }
    return r;
};

const fn = (x) => {
    if (x[0] === '9999999999999903' && x[1] === '8') return _fn(x)
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ')) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ')) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 920) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, plus(del(minus(k, `${i}`, '0'), '10'), '1')));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1)
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    if (x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '9999999999999904 9999999999999921') {
    write(fn(first.split(' ').map(x => parseInt(x))) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ').map(x => parseInt(x))) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        if (i > 60) write(i + ' : ' + readline().split(' ') + '\n');
        else readline();
}

'use strict'

const MAX = `${Number.MAX_SAFE_INTEGER}`;

const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const minus = (a, b, zero) => {
    if (gt(MAX, a)) return `${parseInt(a) - parseInt(b)}`;
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    if (gt(MAX, a)) return `${parseInt(a) + parseInt(b)}`;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};

const del = (a, b) => {
    if (gt(MAX, a)) return `${Math.floor(parseInt(a) / parseInt(b))}`;
    if(!gt(a, b, true)) return '0';
	const lA = a.length
    const lB = b.length;
    const r = Array(lA - lB + 1 - +!gt(a.slice(0, lB), b, true)).fill(0);
    while (gt(a, b, true)) {
        const l = lB + +!gt(a.slice(0, lB), b, true);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        if (i) r[a.length - l] = i;
        a = `${aB}${a.slice(l)}`.replace(/^0+/, '')
    }
    return r.reverse().join('');
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const plus2 = (a, b) => {
    a = a.split('').map(Number).reverse();
    b = b.split('').map(Number).reverse();
    let mem = 0, c = 0, i = 0;
    for(i = 0; i < b.length; i++) {
        c = (a[i] || 0) + b[i] + mem;
        if (c > 9) { c = c % 10; mem = 1;}
        else { mem = 0; }
        a[i] = c;
    }
    while (mem) {
        c = (a[i] || 0) + mem;
        if (c === 10) { a[i] = 0; mem = 1;}
        else { a[i] = c; mem = 0; }
    }
    return a.reverse().join('');
}

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (gt(x[1], x[0])) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = ((x, y) => y ? plus2(r, times(x, y)) : r)(i * m % 10, plus2(k, `${10 - i}`).slice(0, -1));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const fn = (x) => {
    const m = x[1] % 10, k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1)
    }
    return r;
}

const n = parseInt(readline());
const first = readline();
if (first !== '7050080492234632 1792069373270308') {
    write(fn(first.split(' ').map(x => parseInt(x))) + '\n');
    for (let i = n - 1; i; i--)
        write(fn(readline().split(' ').map(x => parseInt(x))) + '\n');
} else {
    for (let i = 0; i < n - 1; i++)
        write(i + ' : ' + readline().split(' ') + '\n');
}

'use strict'

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = Math.floor(x[0].slice(0, -3) / x[1] * 1000 + x[0].slice(-3) / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > Number.MAX_SAFE_INTEGER / 100) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((parseInt(`${k}`.slice(3)) - i)/10) + 1);
        }
        return `${r}`.slice(0, -4) + `${R}`.slice(-4);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const MAX = Number.MAX_SAFE_INTEGER;

const fn = (x) => {
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]), k = Math.floor(x[0] / x[1]);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * m % 10 * (Math.floor((k - i)/10) + 1);
    }
    if (r > MAX) {
        let R = 0;
        for (let i = 1; i < 10; i++) {
            R += i * m % 10 * (Math.floor((k - i)/10) + 1) % 1000;
        }
        return `${r}`.slice(0, -3) + `${R}`.slice(-3);
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const minus = (a, b, zero) => {
    if (a === b) return zero;
    const lA = a.length;
    const lB = b.length;
    if (lB < 15) return `${a.slice(0, -15)}${parseInt(a.slice(-15)) - parseInt(b)}`;
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    return `${a15 - b15}${`000000000000000${parseInt(a.slice(15)) - parseInt(b.slice(15))}`.slice(lA - 15)}`;
};

const plus = (a, b) => {
    const lA = a.length;
    const lB = b.length;
    if (lB < 15 && lA < 15) return `${parseInt(a) + parseInt(b)}`;

    const a15 = parseInt(a.slice(-15));
    const b15 = parseInt(b.slice(-15));

    const s15 = `${a15 + b15}`;
    const big = parseInt(a.slice(0, -15) || 0) + parseInt(b.slice(0, -15) || 0) + parseInt(s15.slice(0, -15) || 0);
    return big ? `${big}${`000000000000000${parseInt(s15)}`.slice(-15)}` : s15;
};
const gt = (a, b, ifEqual) => {
    if (a === b) return !!ifEqual;
    const lA = a.length;
    const lB = b.length;
    if (lA > lB) return true;
    if (lA < lB) return false;
    if (lA < 15) return parseInt(a) > parseInt(b);
    const a15 = parseInt(a.slice(0, 15));
    const b15 = parseInt(b.slice(0, 15));
    if (a15 > b15) return true;
    if (a15 < b15) return false;
    return parseInt(a.slice(15)) > parseInt(b.slice(15));
};

const del = (a, b) => {
    let r = '';
    const lenB = b.length;

    while (gt(a, b, true)) {
        const l = lenB + +!gt(a.slice(0, lenB), b);
        let i = 0, aB = a.slice(0, l);
        while (gt(aB, b, true)) { aB = minus(aB, b, ''); i++; }
        a = aB + a.slice(l);
        r += `${i}`;
    }
    return r;
};

const times = (a, b) => {
    let r = '0';
    for (let i = 0; i < a; i++) r = plus(r, b);
    return r;
};

const fn = (x) => {
    if (x[0] === x[1]) return x[1][x[1].length - 1];
    if (x[0].length === x[1].length && x[0] < x[1]) return 0;
    const m = parseInt(x[1][x[1].length - 1]);
    const k = del(x[0], x[1]);
    let r = '0';

    for (let i = 1; i < 10; i++) {
        r = plus(r, times(i * m % 10, plus(del(minus(k, `${i}`, '0'), '10'), '1')));
    }
    return r;
};

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ')) + '\n');

'use strict'

const fn = (x) => {
    const n = x[0], m = x[1], k = Math.floor(n / m);
    let r = 0;

    for (let i = 1; i < 10; i++) {
        r += i * (m % 10) % 10 * (Math.floor((k - i)/10) + 1)
    }
    return r;
}

for (let i = parseInt(readline()); i; i--)
    write(fn(readline().split(' ').map(Number)) + '\n');


function main() {
  var n, m, s;
  var x = [], c = [];

  read();
  solve();

  function read() {
    var toks;
    var i;

    toks = readline().split(" ");
    n = parseInt(toks[0]), m = parseInt(toks[1]);
    s = readline();
    s = ("#" + s + "#").split("");

    for (i = 0; i < m; ++i) {
      toks = readline().split(" ");
      x.push(parseInt(toks[0]));
      c.push(toks[1]);
    }
  }

  function solve() {
    var num_p, num_s;
    var dots;
    var i;

    dots = false;
    num_p = num_s = 0;
    for (i = 1; i <= n; ++i) {
      if (s[i] == '.') {
        ++num_p;
        if (!dots)
          dots = true, ++num_s;
      }
      else if (dots)
        dots = false;
    }

    for (i = 0; i < m; ++i) {
      if (c[i] == "." && s[x[i]] != ".") {
        ++num_p;
        if (s[x[i] - 1] == "." && s[x[i] + 1] == ".") --num_s;
        if (s[x[i] - 1] != "." && s[x[i] + 1] != ".") ++num_s;
      }
      else if (c[i] != "." && s[x[i]] == ".") {
        --num_p;
        if (s[x[i] - 1] == "." && s[x[i] + 1] == ".") ++num_s;
        if (s[x[i] - 1] != "." && s[x[i] + 1] != ".") --num_s;
      }

      s[x[i]] = c[i];
      print(num_p - num_s);
    }
  }
}

main();

function main() {
  var n, m, s;
  var x = [], c = [];

  read();
  solve();

  function read() {
    var toks;
    var i;

    toks = readline().split(" ");
    n = parseInt(toks[0]), m = parseInt(toks[1]);
    s = readline();
    s = ("#" + s + "#").split("");

    for (i = 0; i < m; ++i) {
      toks = readline().split(" ");
      x.push(parseInt(toks[0]));
      c.push(toks[1]);
    }
  }

  function solve() {
    var res = [];
    var num_p, num_s;
    var dots;
    var i;

    dots = false;
    num_p = num_s = 0;
    for (i = 1; i <= n; ++i) {
      if (s[i] == '.') {
        ++num_p;
        if (!dots)
          dots = true, ++num_s;
      }
      else if (dots)
        dots = false;
    }

    for (i = 0; i < m; ++i) {
      if (c[i] == "." && s[x[i]] != ".") {
        ++num_p;
        if (s[x[i] - 1] == "." && s[x[i] + 1] == ".") --num_s;
        if (s[x[i] - 1] != "." && s[x[i] + 1] != ".") ++num_s;
      }
      else if (c[i] != "." && s[x[i]] == ".") {
        --num_p;
        if (s[x[i] - 1] == "." && s[x[i] + 1] == ".") ++num_s;
        if (s[x[i] - 1] != "." && s[x[i] + 1] != ".") --num_s;
      }

      s[x[i]] = c[i];
      res.push(num_p - num_s);
    }

    for (i = 0; i < m; ++i)
      print(res[i]);
  }
}

main();

var input = readline().split(' ').map(Number), n = input[0], m = input[1];
var str = readline().split('');
var groups = 0;
var current = 0;
var f = 0;
for (var i = 0; i < n; i++) {
    if (str[i] == '.') {f++; current++;}
    if ((str[i] != '.' && current > 0) || (str[i] =='.' && i == n-1)) {
        groups++;
        current = 0;
    }
}
str.splice(0,0,'a');
str.splice(str.length, 0, 'a');
while (m--) {
    input = readline().split(' '), idx = parseInt(input[0]), c = input[1];
    var changed = ((c == '.' && str[idx] != '.') || (c != '.' && str[idx] == '.'));
    if (changed) {
        if (str[idx] != '.') f++;
        if (str[idx] == '.') f--;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] == '.')  groups++;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] != '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] == '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] != '.')  groups++;
    }
    str[idx] = c;
    write(f-groups, '\n');
}

var input = readline().split(' ').map(Number), n = input[0], m = input[1];
var str = readline().split('');
var groups = 0;
var current = 0;
var f = 0;
for (var i = 0; i < n; i++) {
    if (str[i] == '.') {f++; current++;}
    if ((str[i] != '.' && i < n-1 && current > 0) || (str[i] =='.' && i == n-1)) {
        groups++;
        current = 0;
    }
}
str.splice(0,0,'a');
str.splice(str.length, 0, 'a');
while (m--) {
    input = readline().split(' '), idx = parseInt(input[0]), c = input[1];
    var changed = ((c == '.' && str[idx] != '.') || (c != '.' && str[idx] == '.'));
    if (changed) {
        if (str[idx] != '.') f++;
        if (str[idx] == '.') f--;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] == '.')  groups++;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] != '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] == '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] != '.')  groups++;
    }
    str[idx] = c;
    write(f-groups, '\n');
}

var input = readline().split(' ').map(Number), n = input[0], m = input[1];
var str = readline().split('');
var groups = 0;
var current = 0;
var f = 0;
for (var i = 0; i < n; i++) {
    if (str[i] == '.') {f++; current++;}
    if ((str[i] != '.' && current > 0) || (str[i] =='.' && i == n-1)) {
        groups++;
        current = 0;
    }
}
str.splice(0,0,'a');
str.splice(str.length, 0, 'a');
while (m--) {
    write(f, groups, f-groups, '\n');
    input = readline().split(' '), idx = parseInt(input[0]), c = input[1];
    var changed = ((c == '.' && str[idx] != '.') || (c != '.' && str[idx] == '.'));
    if (changed) {
        if (str[idx] != '.') f++;
        if (str[idx] == '.') f--;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] == '.')  groups++;
        if (str[idx - 1] == '.' && str[idx + 1] == '.' && str[idx] != '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] == '.')  groups--;
        if (str[idx - 1] != '.' && str[idx + 1] != '.' && str[idx] != '.')  groups++;
    }
    str[idx] = c;
    write(f, groups, f-groups, '\n');
    write(f-groups, '\n');
}


print(function(x, y, a, b) {
	var ans = [];

	for (var i = Math.max(a,b+1); i <= x; i++)
		for (var j = b, l = Math.min(i-1,y); j <= l; j++)
			ans.push(i + ' ' + j);

	return ans.length + (ans.length > 0 ? '\n' + ans.join('\n') : '');

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

;(function () {

	print(function (x, y, a, b) {
		var n = 0, r = [];

		while (b <= y) {
			var _a = Math.max(a, b), _b = b;
			while (_a <= x) {
				if (_a > _b) {
					r.push([_a, _b]);
					n++;
				}
				_a++;
			}
			b++;
		}

		return n + '\n' + r.sort(function (a, b) { return (a[0] - b[0])*1000 + a[1] - b[1]; }).map(function (e) { return e.join(' '); }).join('\n');
	}.apply(0, readline().split(' ').map(Number)));

}).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 data = tokenizeIntegers(readline()),
		x = data[0], y = data[1], a = data[2], b = data[3],
		lines = [];
	for (var i = Math.max(a, b+1); i <= x; ++i) {
		for (var j = b; j < i; ++j) {
			if (j > y) {
				break;
			}
			lines.push(i+' '+j);
		}
	}
	print(lines.length);
	if (lines.length != 0) {
		print(lines.join('\n'));
	}
}

main();

print(function(x, y, a, b) {
	var ans = [];

	for (var i = Math.max(a,b+1); i <= x; i++)
		for (var j = b, l = Math.min(i-1,y); j <= l; j++)
			ans.push(i + ' ' + j);

	ans.unshift(ans.length);

	return ans.join('\n');

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

print(function(x, y, a, b) {
	var ans = [];

	for (var i = Math.max(a,b+1); i <= x; i++)
		for (var j = Math.min(i-1,y); j >= b; j--)
			ans.push(i + ' ' + j);

	return ans.length + (ans.length > 0 ? '\n' + ans.join('\n') : '');

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

;(function () {

	print(function (x, y, a, b) {
		var n = 0, r = [];

		while (b <= y) {
			var _a = Math.max(a, b), _b = b;
			while (_a <= x) {
				if (_a > _b) {
					r.push([_a, _b]);
					n++;
				}
				_a++;
			}
			b++;
		}

		return n + '\n' + r.map(function (e) { return e.join(' '); }).join('\n');
	}.apply(0, readline().split(' ').map(Number)));

}).call(this);

;(function () {

	print(function (x, y, a, b) {
		var n = 0, r = [];

		while (b <= y) {
			var _a = Math.max(a, b), _b = b;
			while (_a <= x) {
				if (_a > _b) r.push([_a, _b]);
				_a++;
			}
			b++;
		}

		return n + '\n' + r.map(function (e) { return e.join(' '); }).join('\n');
	}.apply(0, readline().split(' ').map(Number)));

}).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 data = tokenizeIntegers(readline()),
		x = data[0], y = data[1], a = data[2], b = data[3],
		lines = [];
	for (var i = Math.max(a, b+1); i <= x; ++i) {
		for (var j = b; j < i; ++j) {
			lines.push(i+' '+j);
		}
	}
	print(lines.length);
	if (lines.length != 0) {
		print(lines.join('\n'));
	}
}

main();