'use strict';

var n = Number(readline());
var count = new Array(100001).fill(0);
var prices = readline().split(' ').map(Number);
for (var i = 0; i < prices.length; i++) {
	count[prices[i]]++;
}
for (var i = 1; i < count.length; i++) {
	count[i] += count[i - 1];
}

var days = Number(readline());

for (var i = 0; i < days; i++) {
	var num = Number(readline());
	if (num >= count.length) {
		print(count[count.length - 1]);
	} else {
		print(count[num]);
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let shops = readline();
  let prices = readline().split(' ');
  prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  prices = [0].concat(prices).concat([Infinity]);
  let numDays = readline();

  while(numDays > 0){
    let coinsDay1 = readline();
    coinsDay1 = parseInt(coinsDay1)
    console.log(getStoresPerDay(prices, coinsDay1))
    numDays--;
  }
}

function getStoresPerDay(prices, target){
  let ini = 0;
  let fin = prices.length - 1;

  while(ini < fin){
      let mid = Math.floor((fin - ini) / 2) + ini;
      if(prices[mid] <= target){
          ini = mid + 1;
      } else {
          fin = mid;
      }
  }
  return fin - 1;

}

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

var n = rdn(), x = rda().sort(function(x,y){ return x-y; }), q = rdn();

for(var i = 0; i < q; i++){
    var have = rdn();

    var l = 0, r = n-1;
    while(l != r){
        var m = Math.floor((l+r)/2);

        if(x[m] < have){
            l = m+1;
        }else if(x[m] > have){
            r = m;
        }else{
            l = m+1;
        }
    }

    if(x[l] <= have){
        print(l+1);
    }else{
        print(l);
    }
}

var n = readline();
var prices = readline().split(' ').map(Number).sort(function(x,y){ return x-y; });
var days = readline();

for(var i = 0; i < days; i++){
    var money = readline()
    var l = 0, r = n-1;

    while(l != r){
        var m = Math.floor((l+r)/2);

        if(prices[m] < money){
            l = m + 1;
        }else if(prices[m] > money){
            r = m;
        }else{
            l = m + 1;
        }
    }

    if(prices[l] <= money){
        print(l + 1);
    }else{
        print(l);
    }
}

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

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

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

  nums.sort((a, b) => a - b);

  let prevCost = 0;
  const positions = []; cnt = 0;
  for (const key in nums) {
    let cost = nums[key];

    for (let i = prevCost; i < cost-1; i += 1) {
      positions[i] = cnt;
    }

    prevCost = cost-1; cnt += 1;
  }

  for (let i = prevCost; i <= prevCost+10; i += 1) {
    positions[i] = cnt;
  }

  const [q] = input[2].split(' ').map(x => parseInt(x));
  for (let i = 3; i < q+3; i += 1) {
    let p = parseInt(input[i]);

    if (positions[p] === undefined) {
      console.log(nums.length);
    } else {
      console.log(positions[p-1]);
    }
  }
});

var n = +readline();
var x = readline().split(" ").map(xi => +xi);
var q = +readline();

x.sort((a, b) => a - b);
var countLessOrEqual = function(a, target) {
    var lo = 0,
        hi = a.length,
        mid;
    while (lo != hi) {
        mid = Math.floor( (lo + hi) / 2);
        if (a[mid] <= target) {
            lo = mid + 1;
        } else {
            hi = mid;
        }
    }
    return lo;
};

var shopsOnDay = [];
for (var i = 0; i < q; ++i) {
    var mi = +readline();
    shopsOnDay.push(countLessOrEqual(x, mi));
}

print(shopsOnDay.join("\n"));

var n = +readline();
var x = readline().split(" ").map(xi => +xi);
var q = +readline();

x.sort((a, b) => a - b);
var countLessOrEqual = function(a, item) {
    var l = 0;
    var r = a.length;
    while (l <= r) {
        var i = Math.floor( (r + l) / 2 );
        var curItem = a[i];
        var nextItem = a[i + 1];

        if ( curItem <= item && (typeof nextItem === "undefined" || nextItem > item) ) {
            return i + 1;
        } else if ( curItem <= item ) {
            l = i + 1;
        } else {
            r = i - 1;
        }
    }
    return 0;
};

var shopsOnDay = [];
for (var i = 0; i < q; ++i) {
    var mi = +readline();
    shopsOnDay.push(countLessOrEqual(x, mi));
}

print(shopsOnDay.join("\n"));

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  while (left <= right) {
    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }

    med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  }

  return med+2;
}

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

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (nums[0] > parseInt(input[i])) { console.log(0); }
    else {
      if (res+1 < nums.length && nums[res] === nums[res+1]) {
        let t = res;
        while (nums[t] === nums[res] && t+1 < nums.length) t += 1;
        console.log(t);
      } else {
        console.log(res);
      }
    }
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  while (left <= right) {
    let med = ((left+right) % 2 === 0) ? parseInt( (left+right) / 2 ) : parseInt( (left+right) / 2 ) + 1;

    if ( pos >= arr[arr.length-1] ) return arr.length;

    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) {
      return med+1
    };

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }
  }

  return -1;
}

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

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    let num = parseInt(input[i]);
    let res = binarySearch(num, nums);

    if (res < 0) { console.log(0) }
    else {
      if (res+1 < nums.length && nums[res] === nums[res+1]) {
        let t = res + 1;
        while (nums[t] === nums[res] && t+1 < nums.length) {
          t += 1;
        }
        console.log(t);
      } else {
        console.log(res);
      }
    }
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  while (left <= right) {
    let med = parseInt((left + right) / 2);

    if (arr[med] === pos) { return med+1; }
    if (med+1 < arr.length) {
      if (arr[med] < pos && arr[med+1] > pos) {
        return med+1;
      }

      if (arr[med+1] === pos) return med+2;
    }

    if (med-1 >= 0) {
      if (arr[med] > pos && arr[med-1] <= pos) return med;
    }

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }
  }

  return -1;
}

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

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (res === -1) { console.log(0); }
    else console.log(res);
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  while (left <= right) {
    let med = ((left+right) % 2 === 0) ? parseInt( (left+right) / 2 ) : parseInt( (left+right) / 2 ) + 1;

    if ( pos >= arr[arr.length-1] ) return arr.length;

    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) {
      return med+1
    };

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }
  }

  return -1;
}

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

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    let num = parseInt(input[i]);
    let res = binarySearch(num, nums);

    if (res < 0) { console.log(0) }
    else {
      if (res+1 < nums.length && nums[res] === nums[res+1]) {
        let t = res + 1;
        while (nums[t] !== nums[res] && t+1 < nums.length) {
          t += 1;
        }
        console.log(t+1);
      } else {
        console.log(res);
      }
    }
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  while (left <= right) {
    let med = parseInt((left + right) / 2);

    if (arr[med] === pos) { return med+1; }
    if (med+1 < arr.length) {
      if (arr[med] < pos && arr[med+1] > pos) {
        return med+1;
      }

      if (arr[med+1] === pos) return med+2;
    }

    if (med-1 >= 0) {
      if (arr[med] > pos && arr[med-1] < pos) return med;
      if (arr[med-1] === pos) return med+1;
    }

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }
  }

  return -1;
}

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

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (res === -1) { console.log(0); }
    else console.log(res);
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  while (left <= right) {
    let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;

    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }
  }

  return -1;
}

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

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (res === -1) { console.log(0); }
    else console.log(res);
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  while (left <= right) {
    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }

    med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  }

  return med+1;
}

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

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (nums[0] > parseInt(input[i])) { console.log(0); }
    else console.log(res);
  }
});

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

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

const binarySearch = (pos, arr) => {
  let left = 0, right = arr.length-1;

  let med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  while (left <= right) {
    if ( arr[med] === pos || (med+1 < arr.length && arr[med] <= pos && arr[med+1] > pos) ) return med+1;

    if (arr[med] > pos) {
      right = med-1;
    } else {
      left = med;
    }

    med = (left + right) % 2 === 0 ? (left+right)/2 : parseInt( (left+right) / 2 ) + 1;
  }

  return med+2;
}

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

  nums.sort((a, b) => a - b);
  const [q] = input[2].split(' ').map(x => parseInt(x));

  for (let i = 3; i < q+3; i += 1) {
    if (parseInt(input[i]) > nums[nums.length-1]) {
      console.log(nums.length); continue;
    }

    const res = binarySearch(parseInt(input[i]), nums);
    if (nums[0] > parseInt(input[i])) { console.log(0); }
    else console.log(res);
  }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays > 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }

//     console.log(coinsDay1);
//   let coinsDay2 = readline();
//   coinsDay2 = parseInt(coinsDay2)
//   let coinsDay3 = readline();
//   coinsDay3 = parseInt(coinsDay3)
//   let coinsDay4 = readline();
//   coinsDay4 = parseInt(coinsDay4)

//   console.log(getStoresPerDay(prices, coinsDay1))
//   console.log(getStoresPerDay(prices, coinsDay2))
//   console.log(getStoresPerDay(prices, coinsDay3))
//   console.log(getStoresPerDay(prices, coinsDay4))
}

// function getStoresPerDay(prices, target){
//   let counter = 0;
//   if(!prices.length) return counter;
// //   prices = prices.sort((a, b) => a - b);
//   console.log(prices, target)

//   for (let i = 0; i < prices.length; i++) {
//      if(prices[i] < target) counter++;
//     if(target < prices[i]){
//       break;
//     }
//   }
//   return counter;
// }
function getStoresPerDay(prices, target, counter = 0){
  if(!prices.length) return counter;
//   prices = prices.sort((a, b) => a - b);
//   console.log(prices, target, counter)

  let mid = Math.floor(prices.length / 2);
//   console.log(prices[mid], "mid")
  if(prices[mid] === target){
    counter += mid + 1;
  } else if(prices[mid] > target) {
     return getStoresPerDay(prices.slice(0, mid), target, counter);
  } else if( prices[mid] < target) {
    counter += mid + 1;
    return getStoresPerDay(prices.slice(mid + 1), target, counter);
  }
  return counter;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();
  let coinsDay1 = readline();
    coinsDay1 = parseInt(coinsDay1)
  let coinsDay2 = readline();
  coinsDay2 = parseInt(coinsDay2)
  let coinsDay3 = readline();
  coinsDay3 = parseInt(coinsDay3)
  let coinsDay4 = readline();
  coinsDay4 = parseInt(coinsDay4)

  console.log(getStoresPerDay(prices, coinsDay1))
  console.log(getStoresPerDay(prices, coinsDay2))
  console.log(getStoresPerDay(prices, coinsDay3))
  console.log(getStoresPerDay(prices, coinsDay4))
}

function getStoresPerDay(prices, target, counter = 0){
  if(!prices.length) return counter;

  let mid = Math.floor(prices.length / 2);

  if(prices[mid] === target){
    counter += mid + 1;
  } else if(prices[mid] > target) {
     return getStoresPerDay(prices.slice(0, mid), target, counter);
  } else if( prices[mid] < target) {
    counter += mid + 1;
    return getStoresPerDay(prices.slice(mid + 1), target, counter);
  }
  return counter;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays >= 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }

//     console.log(coinsDay1);
//   let coinsDay2 = readline();
//   coinsDay2 = parseInt(coinsDay2)
//   let coinsDay3 = readline();
//   coinsDay3 = parseInt(coinsDay3)
//   let coinsDay4 = readline();
//   coinsDay4 = parseInt(coinsDay4)

//   console.log(getStoresPerDay(prices, coinsDay1))
//   console.log(getStoresPerDay(prices, coinsDay2))
//   console.log(getStoresPerDay(prices, coinsDay3))
//   console.log(getStoresPerDay(prices, coinsDay4))
}

function getStoresPerDay(prices, target){
  let counter = 0;
  if(!prices.length) return counter;
//   prices = prices.sort((a, b) => a - b);
//   console.log(prices, target)

  for (let i = 0; i < prices.length; i++) {
     if(prices[i] < target) counter++;
    if(target < prices[i]){
      break;
    }
  }
  return counter;
}
// function getStoresPerDay(prices, target, counter = 0){
//   if(!prices.length) return counter;
// //   prices = prices.sort((a, b) => a - b);
// //   console.log(prices, target, counter)

//   let mid = Math.floor(prices.length / 2);
// //   console.log(prices[mid], "mid")
//   if(prices[mid] === target){
//     counter += mid + 1;
//   } else if(prices[mid] > target) {
//      return getStoresPerDay(prices.slice(0, mid), target, counter);
//   } else if( prices[mid] < target) {
//     counter += mid + 1;
//     return getStoresPerDay(prices.slice(mid + 1), target, counter);
//   }
//   return counter;
// }

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays > 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }
}

function getStoresPerDay(prices, target){
  let counter = 0;
  if(!prices.length) return counter;

  for (let i = 0; i < prices.length; i++) {
     if(prices[i] < target) counter++;
    if(target < prices[i]){
      break;
    }
  }
  return counter;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays > 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }

//     console.log(coinsDay1);
//   let coinsDay2 = readline();
//   coinsDay2 = parseInt(coinsDay2)
//   let coinsDay3 = readline();
//   coinsDay3 = parseInt(coinsDay3)
//   let coinsDay4 = readline();
//   coinsDay4 = parseInt(coinsDay4)

//   console.log(getStoresPerDay(prices, coinsDay1))
//   console.log(getStoresPerDay(prices, coinsDay2))
//   console.log(getStoresPerDay(prices, coinsDay3))
//   console.log(getStoresPerDay(prices, coinsDay4))
}

function getStoresPerDay(prices, target){
  let counter = 0;
  if(!prices.length) return counter;

  for (let i = 0; i < prices.length; i++) {
     if(prices[i] < target) counter++;
    if(target < prices[i]){
      break;
    }
  }
  return counter;
}
// function getStoresPerDay(prices, target, counter = 0){
//   if(!prices.length) return counter;
// //   prices = prices.sort((a, b) => a - b);
// //   console.log(prices, target, counter)

//   let mid = Math.floor(prices.length / 2);
// //   console.log(prices[mid], "mid")
//   if(prices[mid] === target){
//     counter += mid + 1;
//   } else if(prices[mid] > target) {
//      return getStoresPerDay(prices.slice(0, mid), target, counter);
//   } else if( prices[mid] < target) {
//     counter += mid + 1;
//     return getStoresPerDay(prices.slice(mid + 1), target, counter);
//   }
//   return counter;
// }

'use strict';

function binarySearch(num, prices, left, right) {
	while (left <= right) {
		var mid = parseInt(left + (right - left) / 2);
		if (mid == 0 && prices[mid] > num) {
			return 0;
		} else if (mid == prices.length - 1 && prices[mid] <= num) {
			return prices.length;
		} else if (prices[mid] <= num && prices[mid + 1] > num) {
			return mid + 1;
		} else if (prices[mid] < num) {
			left = mid + 1;
		} else {
			right = mid - 1;
		}
	}
	return -1;
}

var n = Number(readline());
var prices = readline().split(' ').map(Number).sort(function (a, b) {
	return a - b;
});
var days = Number(readline());

for (var i = 0; i < days; i++) {
	var num = Number(readline());
	var index = binarySearch(num, prices, 0, prices.length - 1);
	print(index);
}

var n = +readline();
var x = readline().split(" ").map(xi => +xi);
var q = +readline();
var m = [];

x.sort((a, b) => a - b);
var countLessOrEqual = function(a, item) {
    var l = 0;
    var r = a.length;
    while (l <= r) {
        var i = Math.floor((r + l) / 2);
        var curItem = a[i];
        var nextItem = a[i + 1];

        if ( curItem <= item && (typeof nextItem === "undefined" || nextItem > item) ) {
            return i + 1;
        } else if ( curItem < item ) {
            l = i + 1;
        } else {
            r = i - 1;
        }
    }
    return 0;
};

var shopsOnDay = [];
for (var i = 0; i < q; ++i) {
    mi = +readline();
    shopsOnDay.push(countLessOrEqual(x, mi));
}

print(shopsOnDay.join("\n"));

var n = +readline();
var x = readline().split(" ").map(xi => +xi);
var q = +readline();

x.sort((a, b) => a - b);
var countLessOrEqual = function(a, target) {
    var lo = 0,
        hi = a.length,
        mid;
    while (lo != hi) {
        mid = Math.floor( (lo + hi) / 2);
        if (a[mid] <= target) {
            lo = mid + 1;
        } else {
            hi = mid;
        }
    }
    if (a[mid] <= target) {
        return mid + 1;
    } else {
        return 0;
    }
};

var shopsOnDay = [];
for (var i = 0; i < q; ++i) {
    var mi = +readline();
    shopsOnDay.push(countLessOrEqual(x, mi));
}

print(shopsOnDay.join("\n"));

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays >= 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }

//     console.log(coinsDay1);
//   let coinsDay2 = readline();
//   coinsDay2 = parseInt(coinsDay2)
//   let coinsDay3 = readline();
//   coinsDay3 = parseInt(coinsDay3)
//   let coinsDay4 = readline();
//   coinsDay4 = parseInt(coinsDay4)

//   console.log(getStoresPerDay(prices, coinsDay1))
//   console.log(getStoresPerDay(prices, coinsDay2))
//   console.log(getStoresPerDay(prices, coinsDay3))
//   console.log(getStoresPerDay(prices, coinsDay4))
}

// function getStoresPerDay(prices, target){
//   let counter = 0;
//   if(!prices.length) return counter;
// //   prices = prices.sort((a, b) => a - b);
//   console.log(prices, target)

//   for (let i = 0; i < prices.length; i++) {
//      if(prices[i] < target) counter++;
//     if(target < prices[i]){
//       break;
//     }
//   }
//   return counter;
// }
function getStoresPerDay(prices, target, counter = 0){
  if(!prices.length) return counter;
//   prices = prices.sort((a, b) => a - b);
//   console.log(prices, target, counter)

  let mid = Math.floor(prices.length / 2);
//   console.log(prices[mid], "mid")
  if(prices[mid] === target){
    counter += mid + 1;
  } else if(prices[mid] > target) {
     return getStoresPerDay(prices.slice(0, mid), target, counter);
  } else if( prices[mid] < target) {
    counter += mid + 1;
    return getStoresPerDay(prices.slice(mid + 1), target, counter);
  }
  return counter;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  let shops = readline();
  let prices = readline().split(' ');
    prices = prices.map(el => parseInt(el)).sort((a, b) => a - b);
  let numDays = readline();

  while(numDays > 0){
      let coinsDay1 = readline();
     coinsDay1 = parseInt(coinsDay1)
     console.log(getStoresPerDay(prices, coinsDay1))
      numDays--;
  }

//     console.log(coinsDay1);
//   let coinsDay2 = readline();
//   coinsDay2 = parseInt(coinsDay2)
//   let coinsDay3 = readline();
//   coinsDay3 = parseInt(coinsDay3)
//   let coinsDay4 = readline();
//   coinsDay4 = parseInt(coinsDay4)

//   console.log(getStoresPerDay(prices, coinsDay1))
//   console.log(getStoresPerDay(prices, coinsDay2))
//   console.log(getStoresPerDay(prices, coinsDay3))
//   console.log(getStoresPerDay(prices, coinsDay4))
}

function getStoresPerDay(prices, target){
  let counter = 0;
  if(!prices.length) return counter;
//   prices = prices.sort((a, b) => a - b);
  console.log(prices, target)

  for (let i = 0; i < prices.length; i++) {
     if(prices[i] < target) counter++;
    if(target < prices[i]){
      break;
    }
  }
  return counter;
}
// function getStoresPerDay(prices, target, counter = 0){
//   if(!prices.length) return counter;
// //   prices = prices.sort((a, b) => a - b);
// //   console.log(prices, target, counter)

//   let mid = Math.floor(prices.length / 2);
// //   console.log(prices[mid], "mid")
//   if(prices[mid] === target){
//     counter += mid + 1;
//   } else if(prices[mid] > target) {
//      return getStoresPerDay(prices.slice(0, mid), target, counter);
//   } else if( prices[mid] < target) {
//     counter += mid + 1;
//     return getStoresPerDay(prices.slice(mid + 1), target, counter);
//   }
//   return counter;
// }


var data = readline().split(" ");
var l = data[2];
var countQuery = +data[1];
var n_query = 0;
var arrHair = new Array(+data[0]).fill(0);
var countChick = 0;
var startHairs = readline().split(" ");

function growHair(p, d){
    arrHair[p] += d;
    if(arrHair[p] > l && arrHair[p] - d <=l){
        if(arrHair.length > 1){
            if(p === 0){
                if(arrHair[p+1] <= l)
                    countChick++;
            }
            else if(p === arrHair.length - 1){
                if(arrHair[p-1] <= l)
                    countChick++;
            }
            else{
                if(arrHair[p-1] <= l && arrHair[p+1] <= l )
                    countChick++;
                else if(arrHair[p-1] > l && arrHair[p+1] > l )
                    countChick--;
            }
        }
        else
            countChick = 1;

    }

}

var queries = Array();
for(var j = 0; j < startHairs.length; j++){
    queries[j] = Array(1, j+1, +startHairs[j]);
}
while(n_query < countQuery){
    n_query++;
    var temp = readline().split(" ");
    queries[j] = Array();
    for(var k = 0; k < temp.length; k++){
        queries[j][k] = parseInt(temp[k]);
    }
    j++;
}

for(var i = 0; i < queries.length; i++){
    if(queries[i][0] === 0 ){
        print(countChick);
    }
    else{
        growHair(queries[i][1] - 1, queries[i][2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        }
    }
}

var grow = function (hairlinePos, growLength) {
    var oldLength = hairlines[hairlinePos - 1];
    hairlines[hairlinePos - 1] = oldLength + growLength;

    if (oldLength <= favLength && hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);;
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength || hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            // if (hairlines[i + 1] > favLength) {
            //     i++;
            // }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var s = [-1];
s.concat(hairlines.push(-1));
hairlines = s;

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        // if (hairlinePos == 1) {
        //     if (noHairlines == 1) {
        //         savedTime++;
        //         return;
        //     }
        //     if (hairlines[1] <= favLength) {
        //         savedTime++;
        //         return;
        //     }
        //     return;
        // }

        // if (hairlinePos == noHairlines) {
        //     if (hairlines[hairlinePos - 2] <= favLength) {
        //         savedTime++;
        //     }
        //     return;
        // }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1] + 1, line[2]);;
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        }
    }
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);;
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

var printTime = function () {
    var savedTime2 = hairlines[0] > favLength ? 1 : 0;
    for (var i = 1; i < noHairlines - 1; i++) {
        if (hairlines[i] > favLength) {
            if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
                savedTime2++;
            } else {
                if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                    i++;
                }
            }
        }
    }
    if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
        savedTime2++;
    }
    print(savedTime2);
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
        // printTime();
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];
var savedTime = hairlines[0] > favLength ? 1 : 0;

for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (hairlines[1] <= favLength) {
                savedTime++;
            }
            if(requests == 0 && hairlines[1] > favLength){
                savedTime--;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            if (requests == 0 && hairlines[hairlinePos - 2] > favLength) {
                savedTime--;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests--) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];
var savedTime = hairlines[0] > favLength ? 1 : 0;

for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (hairlines[1] <= favLength) {
                savedTime++;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests--) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (noHairlines > 1 && hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (noHairlines == 1) {
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

while (requests-- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
    } else {
        grow(line[1], line[2]);;
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];
var savedTime = hairlines[0] > favLength ? 1 : 0;

for(var i = 1; i < noHairlines -1 ; i++){
    if(hairlines[i] > favLength) {
        if(hairlines[i-1]  <= favLength && hairlines[i+1]<= favLength){
            savedTime++;
        }else{
            if(hairlines[i] > favLength && hairlines[i+1] > favLength){
                i++;
            }
        }
    }
}
if(hairlines[noHairlines- 2] <= favLength && hairlines[noHairlines -1] > favLength){
    savedTime++;
}

var grow = function(hairlinePos, growLength){
    hairlines[hairlinePos -1] =  hairlines[hairlinePos -1]  + growLength;

    if(hairlines[hairlinePos -1] > favLength){
        if(hairlinePos == 1 && hairlines[1] <=favLength){
            savedTime++;
            return;
        }

        if(hairlinePos == noHairlines && hairlines[hairlinePos -2] <= favLength){
            savedTime++;
            return;
        }
        if(hairlines[hairlinePos -2]  <= favLength && hairlines[hairlinePos]<= favLength){
            savedTime++;
            return;
        }
        if(hairlines[hairlinePos -2] > favLength && hairlines[hairlinePos] > favLength){
            savedTime --;
            return;
        }
    }
}

while(requests--){
    var line = readline().split(' ').map(Number);
    if(line[0] == 0){
        print(savedTime);
    }else{
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if(noHairlines == 1){
                savedTime++;
                return;
            }
            if (hairlines[1] <= favLength) {
                savedTime++;
                return;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

var printTime = function () {
    var savedTime2 = hairlines[0] > favLength ? 1 : 0;
    for (var i = 1; i < noHairlines - 1; i++) {
        if (hairlines[i] > favLength) {
            if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
                savedTime2++;
            } else {
                if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                    i++;
                }
            }
        }
    }
    if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
        savedTime2++;
    }
    print(savedTime2);
}

while (requests -- > 0) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        print(savedTime);
        // printTime();
    } else {
        grow(line[1], line[2]);
    }
}

var nml = readline().split(' ').map(Number);
var hairlines = readline().split(' ').map(Number)

var noHairlines = nml[0];
var requests = nml[1];
var favLength = nml[2];

var savedTime = hairlines[0] > favLength ? 1 : 0;
for (var i = 1; i < noHairlines - 1; i++) {
    if (hairlines[i] > favLength) {
        if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
            savedTime++;
        } else {
            if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                i++;
            }
        }
    }
}
if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
    savedTime++;
}

var grow = function (hairlinePos, growLength) {
    hairlines[hairlinePos - 1] = hairlines[hairlinePos - 1] + growLength;

    if (hairlines[hairlinePos - 1] > favLength) {
        if (hairlinePos == 1) {
            if (hairlines[1] <= favLength) {
                savedTime++;
            }
            return;
        }

        if (hairlinePos == noHairlines) {
            if (hairlines[hairlinePos - 2] <= favLength) {
                savedTime++;
            }
            return;
        }
        if (hairlines[hairlinePos - 2] <= favLength && hairlines[hairlinePos] <= favLength) {
            savedTime++;
            return;
        }
        if (hairlines[hairlinePos - 2] > favLength && hairlines[hairlinePos] > favLength) {
            savedTime--;
            return;
        }
    }
}

var computeTime = function () {
    var savedTime2 = hairlines[0] > favLength ? 1 : 0;
    for (var i = 1; i < noHairlines - 1; i++) {
        if (hairlines[i] > favLength) {
            if (hairlines[i - 1] <= favLength && hairlines[i + 1] <= favLength) {
                savedTime2++;
            } else {
                if (hairlines[i] > favLength && hairlines[i + 1] > favLength) {
                    i++;
                }
            }
        }
    }
    if (hairlines[noHairlines - 2] <= favLength && hairlines[noHairlines - 1] > favLength) {
        savedTime2++;
    }
    print(savedTime2);
}

while (requests--) {
    var line = readline().split(' ').map(Number);
    if (line[0] == 0) {
        // print(savedTime);
        computeTime();
    } else {
        grow(line[1], line[2]);
    }
}

var data = readline().split(" ");
var l = data[2];
var countQuery = +data[1];
var n_query = 0;
var arrHair = new Array(+data[0]).fill(0);
var countChick = 0;
var startHairs = readline().split(" ");
function growHair(p, d){
    arrHair[p] += d;
    if(arrHair[p] > l){
        if(arrHair.length > 1){
            if((p) === 0){
                if(arrHair[p+1] <= l)
                    countChick++;
            }
            else if((p) === arrHair.length - 1){
                if(arrHair[p-1] <= l)
                    countChick++;
            }
            else{
                if(arrHair.length > 2){
                    if(arrHair[p-1] <= l && arrHair[p+1] <= l )
                        countChick++;
                    else if(arrHair[p-1] > l && arrHair[p+1] > l )
                        countChick--;
                }

            }
        }
        else
            return countChick = 1;

    }

}

var queries = Array();
for(var j = 0; j < startHairs.length; j++){
    queries[j] = Array(1, j+1, +startHairs[j]);
}
while(n_query < countQuery){
    n_query++;
    var temp = readline().split(" ");
    queries[j] = Array();
    for(var k = 0; k < temp.length; k++){
        queries[j][k] = parseInt(temp[k]);
    }
    j++;
}

for(var i = 0; i < queries.length; i++){
    if(queries[i][0] === 0 ){
        print(countChick);
    }
    else{
        growHair(queries[i][1] - 1, queries[i][2]);
    }
}

var data = readline().split(" ");
var l = data[2];
var countQuery = +data[1];
var n_query = 0;
var arrHair = new Array(+data[0]).fill(0);
var countChick = 0;
var startHairs = readline().split(" ");
function growHair(p, d){
    arrHair[p] += d;
    if(arrHair[p] > l){
        if(arrHair.length > 2){
            if((p) === 0){
                if(arrHair[p+1] <= l)
                    countChick++;
            }
            else if((p) === arrHair.length - 1){
                if(arrHair[p-1] <= l)
                    countChick++;
            }
            else{
                if(arrHair[p-1] <= l && arrHair[p+1] <= l )
                    countChick++;
                else if(arrHair[p-1] > l && arrHair[p+1] > l )
                    countChick--;
            }
        }
        else
            return countChick = 1;

    }

}

var queries = Array();
for(var j = 0; j < startHairs.length; j++){
    queries[j] = Array(1, j+1, +startHairs[j]);
}
while(n_query < countQuery){
    n_query++;
    var temp = readline().split(" ");
    queries[j] = Array();
    for(var k = 0; k < temp.length; k++){
        queries[j][k] = parseInt(temp[k]);
    }
    j++;
}

for(var i = 0; i < queries.length; i++){
    if(queries[i][0] === 0 ){
        print(countChick);
    }
    else{
        growHair(queries[i][1] - 1, queries[i][2]);
    }
}


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

let inputString = '';
let currentLine = 0;

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

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

    C();
});

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

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

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

    return a;
}

function C(){
    let t = pi(readline());
    while(t > 0){
        t--;
        let [n,k] = ti(readline().split(' '));
        let s = readline().split('');

        let a = new Array(s.length);
        a.fill(false);
        let d = 999999999999;
        for(let i = 0; i < s.length; i++){
            if(s[i] === '1'){
                d = 0;
            }else{
                d += 1;
                if(d > k){
                    a[i] = true;
                }
            }
        }

        d = 999999999999;
        for(let i = s.length-1; i >= 0; i--){
            if(s[i] === '1'){
                d = 0;
            }else{
                d += 1;
                if(d <= k){
                    a[i] = false;
                }
            }
        }

        let p1 = 0;
        let p2 = 0;
        let res = 0;
        while(p1 < s.length && p2 < s.length){
            while(a[p1] && a[p2]){
                p2++;
            }
            let x = p2-p1;
            res += Math.ceil(x/(k+1));
            p2++;
            p1 = p2;
        }

        console.log(res);
    }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0];
  var k = input[1];
  var str = readline();
  var dist = k;
  var res = 0;
  for (var i = 0; i < n; i++) {
    if (str[i] == "1") {
      if (dist < k) res--;
      dist = 0;
    } else {
      dist++;
      if (dist == k + 1) {
        res++;
        dist = 0;
      }
    }
  }
  print(res);
}

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; ++t) {
      var nk = read().split(' ').map(Number);
      var n = nk[0];
      var k = nk[1];
      var s = read();
      var last1 = 0 - k - 1;
      ans = 0;
      for (var  i = 0; i < n; ++i) {
         if (s[i] !== '1') {
            continue;
         }
         while (last1 + k + 1 < i - k) {
            ans++;
            last1 += k + 1;
         }
         last1 = i;
      }
      while (last1 + k + 1 < n) {
         ans++;
         last1 += k + 1;
      }
      write(ans);
   }
}

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

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

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

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

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    let t = parseInt(readLine());
    while(t--) {
        let fir = readLine().split(" ");
        let n = parseInt(fir[0]);
        let k = parseInt(fir[1]);
        let arr = readLine().split("").map((x) => {return parseInt(x)});
        let arr1 = [];
        for(let i = 0;i<arr.length;i++) {
            arr1.push(arr[i]);
        }
        for(let i =0; i<arr.length; i++) {
            if(arr[i] === 1) {
                for(let j = 1; (i-j)>=0 && j<=k; j++) {
                    arr1[i-j] += 1;
                }
                for(let j = 1; (i+j)<arr.length && j<=k; j++) {
                    arr1[i+j] += 1;
                }
            }
        }
        let ans = 0;
        let arr2 = [];
        for(let i = 0;i<arr1.length;i++) {
            if(arr1[i]===0) {
                ans++;
            } else {
                if  (ans>0) {
                   arr2.push(ans);
                }
                ans = 0;
            }
        }
        if  (ans>0) {
            arr2.push(ans);
        }
        let realAns = 0;
        for(let i = 0;i<arr2.length;i++) {
            if(arr2[i]-1>0) {
                realAns+= parseInt((arr2[i]-1)/((k)+1))
            }
            realAns++;
        }
        console.log(realAns)
    }
}

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var K = one[1];
		var list = nextCharArray();
		var count = 0;
		var sum = 0;
		var isOne = false;
		for(var j = 0; j < N; j++){
			if(!isOne){
				if(list[j] == "0"){
					count++;
				}else{
					if(count >= 1 + K){
						sum += Math.floor(count / (1 + K));
					}
					count = 0;
					isOne = true;
				}
			}else{
				if(list[j] == "0"){
					count++;
				}else{
					if(count >= 2 * K + 1){
						sum++;
						count -= 2 * K + 1;
						sum += Math.floor(count / (K + 1));
					}
					count = 0;
				}
			}
		}

		if(isOne){
			sum += Math.floor(count / (K + 1));
		}else{
			sum += Math.ceil(count / (1 + K));
		}
		output[i] = sum;
	}
	myout(myconv(output,9));
}

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

let stdinInput = '';

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

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

// function main(data) {
//     data = data.split('\n');
//     const testCases = data[0] * 2;
//     let i = 1;
//     while (i <= testCases) {
//         const int = data[i].split(' ');
//         const n = int[0] * 1;
//         const k = int[1] * 1;
//         const arr = data[i + 1];
//         let count = 0;
//         for (let j = 0; j < n; j += k + 1)(arr[j] == 0 && arr[j + k] != 1) ? count += 1 : '';
//         console.log(count);
//         i += 2;
//     }
// }
function main(data) {
    data = data.split('\n');
    const testCases = data[0] * 2;
    let i = 1;
    while (i <= testCases) {
        const int = data[i].split(' ');
        const n = int[0] * 1;
        const k = int[1] * 1;
        const arr = data[i + 1];
        let count = 0;
        let first = arr.indexOf('1');
        let j = 0;
        while (j < n) {
            if (arr[j] == 0 && first === -1) {
                count += 1;
                j += k + 1;
                continue;
            }
            if (arr[j] == 1) {
                j += k + 1;
                continue;
            }
            if (arr[j] == 0) {
                first = arr.indexOf('1', j);
                if (first == -1) {
                    count += 1;
                    j += k + 1;
                    continue;
                } else if (first - j > k) {
                    count += 1;
                    j += k + 1;
                    continue;
                } else j = first;
            }
        }
        console.log(count);
        i += 2;
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const t = parseInt(readline());
  for (let i=0; i<t; i++) {
    const [n, k] = readline().split(" ").map(x => parseInt(x));
    const s = readline();
    let cooldown = 0,
      vacancy = 0;
    for (let j=0; j<s.length; j++) {
      if (s[j] === "0") {
        if (cooldown == 0) {
          vacancy++;
          cooldown = k;
        } else {
          cooldown--;
        }
      } else {
        // s[j] === "1"
        if (cooldown > 0) {
          vacancy--;
        }
        cooldown = k;
      }
    }
    console.log(vacancy);
  }
}

const process = require('process')
let input = ''
process.stdin.on('data', data => input += data)
process.stdin.on('end', () => main(input))

function main(input) {
    let lines = input.trim().split('\n')
    let n = +lines[0]
    for(let i = 0; i < n; i++) {
        let [, k] = lines[1 + i * 2].split(' ')
        let arr = lines[2 + i * 2].trim().split('').map(x => +x)
        console.log(solution(arr, +k))
    }
}

function solution(arr, k) {
    let N = arr.length
    let waiting = 0
    for(let i = N - 1; i >= 0; i--) {
        if (arr[i] === 1) {
            waiting = k
        }
        else if (waiting) {
            arr[i] = 2
            waiting--
        }
    }
    waiting = 0
    let ans = 0
    for(let i = 0; i < N; i++) {
        if (arr[i] === 1) {
            waiting = k
        } else if (arr[i] === 2) {
            // nothing
        } else if (waiting) {
            waiting--
        } else {
            ans++
            waiting = k
        }
    }
    return ans
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0],
    k = input[1];
  var str = readline();
  var possiple = 1;
  var curr = str[0] == "1" ? 1 : 0;
  var dist = 0;
  for (var i = 1; i < str.length; i++) {
    if (str[i] == "1") curr++;
    if (dist == k) {
      possiple++;
      dist = 0;
      continue;
    }
    dist++;
  }
  print(possiple - curr);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var input = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = input[0];
  var k = input[1];
  var str = readline();
  var possiple = Math.floor(n / (k + 1));
  if (n % (k + 1) == k) possiple++;
  var curr = 0;
  for (var i = 0; i < n; i++) {
    if (str[i] == "1") curr++;
  }
  print(possiple - curr);
}

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; ++t) {
      var nk = read().split(' ').map(Number);
      var n = nk[0];
      var k = nk[1];
      var s = read();
      var last1 = 0 - k - 1;
      ans = 0;
      for (var  i = 0; i < n; ++i) {
         if (s[i] !== '1') {
            continue;
         }
         while (last1 + k + 1 < i - k - 1) {
            ans++;
            last1 += k + 1;
         }
         last1 = i;
      }
      while (last1 + k + 1 < n) {
         ans++;
         last1 += k + 1;
      }
      write(ans);
   }
}

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

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

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

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

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

function solve() {
   var T = Number(read());
   for (var t = 0; t < T; ++t) {
      var nk = read().split(' ').map(Number);
      var n = nk[0];
      var k = nk[1];
      var s = read();
      var last1 = 0 - k - 1;
      ans = 0;
      for (var  i = 0; i < n; ++i) {
         if (s[i] !== '1') {
            continue;
         }
         while (last1 + k + 1 < i) {
            ans++;
            last1 += k + 1;
         }
         last1 = i;
      }
      while (last1 + k + 1 < s.length) {
         ans++;
         last1 += k + 1;
      }
      write(ans);
   }
}

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

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

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         solve();
      });
   } else {
      var RL = require('readline').createInterface({
         input : process.stdin,
         output : process.stdout
      });

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

      RL.on('close', solve);
   }
} else {
   solve();
}

function write(value) {
   isNode ? console.log(value) : print(value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}

//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var K = one[1];
		var list = nextCharArray();
		var count = 0;
		var sum = 0;
		var isOne = false;
		for(var j = 0; j < N; j++){
			if(!isOne){
				if(list[j] == "0"){
					count++;
				}else{
					if(count >= 1 + K){
						sum += Math.floor(count / (1 + K));
						count = 0;
					}
					isOne = true;
				}
			}else{
				if(list[j] == "0"){
					count++;
				}else{
					if(count >= 2 * K + 1){
						sum++;
						count -= 2 * K + 1;
						sum += Math.floor(count / (K + 1));
						count = 0;
					}
				}
			}
		}
		if(isOne){
			if(count >= 2 * K + 1){
				sum++;
				count -= 2 * K + 1;
				sum += Math.ceil(count / (K + 1));
				count = 0;
			}
		}else{
			sum += Math.ceil(count / (1 + K));
		}
		output[i] = sum;
	}
	myout(myconv(output,9));
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

  main();
});

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

function main() {
  const t = parseInt(readline());
  for (let i=0; i<t; i++) {
    const [n, k] = readline().split(" ").map(x => parseInt(x));
    const s = readline();
    let cooldown = 0,
        vacancy = 0;
    for (let j=0; j<s.length; j++) {
      if (s[j] === "0") {
        if (cooldown == 0) {
          vacancy++;
          cooldown = k;
        } else {
          cooldown--;
        }
      } else {
        // s[j] === "1"
        if (cooldown > 0) {
          vacancy--;
          cooldown = k;
        }
      }
    }
    console.log(vacancy);
  }
}

const process = require('process')
let input = ''
process.stdin.on('data', data => input += data)
process.stdin.on('end', () => main(input))

function main(input) {
    let lines = input.trim().split('\n')
    let n = +lines[0]
    for(let i = 0; i < n; i++) {
        let [, k] = lines[1 + i * 2].split(' ')
        let arr = lines[2 + i * 2].split('').map(x => +x)
        console.log(solution(arr, +k))
    }
}

function solution(arr, k) {
    let N = arr.length
    let waiting = 0
    for(let i = N - 1; i >= 0; i--) {
        if (arr[i] === 1) {
            waiting = k
        }
        else if (waiting) {
            arr[i] = 2
            waiting--
        }
    }
    waiting = 0
    let ans = 0
    for(let i = 0; i < N; i++) {
        if (arr[i] === 1) {
            waiting = k
        } else if (arr[i] === 2) {
            // nothing
        } else if (waiting) {
            waiting--
        } else {
            ans++
            waiting = k
        }
    }
    return ans
}


'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {

    let cases = parseInt(readline(), 10);
    for (var X = 0; X < cases; X++) {
      let [n,k] = readline().split(" ").map(e => parseInt(e));

      let space = n - 1;

      // console.log({n,k})
      // console.log({
      //   a : k / space,
      //   b : k % space,
      //   x : Math.floor((k -1) / space) * n,
      // })

      console.log(1 + (Math.floor((k -1) / space) * n) +  (k-1) % space)

      //console.log('---');

      // for (var i = 0; k > 0; i++) {
      //   if (i % n != 0) {
      //     k--
      //   }
      // }
      //console.log(i-1);

    }

}

let input = require('fs')
    .readFileSync(0, 'ascii')
    .split('\n')
    .filter(line => !/^\s*$/.test(line))
    .map(l => l.split(' ').map(w => parseInt(w)));

let [t, ...tests] = input;

for ([n, k] of tests) {
    console.log(k + Math.floor((k - 1) / (n - 1)));
}

'use strict';

const parseProblem = (line, problem) => {
    if (!problem.T || problem.T === 0) {
        const result = {problem,
            T: parseInt(line),
            isProcessing: true,
            cases: []
        };
        return result;
    }

    const cases = problem.cases;

    if (cases.length === 0 || !cases[cases.length - 1].isProcessing) {
        cases.push({
            t: line
        });
    }

    const isProcessing = cases.length < problem.T;
    problem.isProcessing = isProcessing;

    return problem;
};

const solve = data => {
    const [n, k] = data.t.split(' ');
    let i = Math.floor(k / (n - 1));
    let j = k % (n - 1);

    return j == 0 ? (n * i - 1) : (n * i + j);
}

const solveCases = cases => {
    for (let index = 0; index < cases.length; index++) {
        const result = solve(cases[index]);
        console.log(result);
    }
};

const main = () => {
    const readline = require('readline');

    let problem = {
        T: 0,
        cases: [],
        isProcessing: true
    };

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

    rl.on('line', line => {
        problem = parseProblem(line, problem);

        if (!problem.isProcessing) {
            rl.close();
        }
    }).on('close', () => {
        solveCases(problem.cases);
        process.exit(0);
    });
};

if (!module.parent) {
    main();
}

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const t = parseInt(readLine(), 10);
    for (let i = 0; i< t;i++){
        let [n,k] = readLine().split(' ').map(x=>parseInt(x));
        let low = 0, high = k*2;
        while (low< high){
            const mid = Math.floor((low + high)/2);
            if (mid - Math.floor(mid/n) >= k){
                high = mid;
            } else{
                low = mid + 1;
            }
        }
        console.log(low)
    }
    return;
}

'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(str => str.trim());

    main();
});

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

function main() {
    const t = parseInt(readLine(), 10);
    for (let i = 0; i< t;i++){
        let [n,k] = readLine().split(' ').map(x=>parseInt(x));
        let f = getValidTerms(1, k, n);
        console.log(f);

    }

    function getValidTerms(a, n, div) {
        let f = a + n - 1;
        let s = Math.floor(((f - f%div) -(a%div == 0?a:a + (div - a%div)))/div) + 1;
        if (f-a<div){
            let a1 = a + div - a%n;
            if (a1<=f) return ++f;
        }
        if (s <= 0){
            return f;
        } else {
            return getValidTerms(f+1, s, div);
        }
    }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nk = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nk[0],
    k = nk[1];
  var res;
  if (n == k) res = k + 1;
  else if (n > k) res = k;
  else {
    var xx = n - 1;
    k = k - xx;
    res = xx + Math.ceil((n * k) / (n - 1));
  }

  print(res);
}

var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
        var t = nextInt();
	var output = new Array(t);
	for(var i = 0; i < t; i++){
		var one = nextIntArray();
		var N = one[0];
		var K = one[1];
		if(N > K){
			output[i] = K;
		}else{
			var count = Math.floor(K / (N - 1));
			var min = count * N;
			var ans = min + K % (N - 1);
			if(ans % N == 0){
				ans--;
			}
			output[i] = ans;
		}
	}
	myout(myconv(output,9));
}

let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL);

    function foo (sicLen, num) {
        let weightSic = sicLen - 1;
        let countSics = Math.floor(num/weightSic);
        let body = countSics * sicLen;
        let weightBody = weightSic * countSics;
        let rest = num - weightBody;
        if (!rest) return body - 1;
        return body + rest;
    }

    let testCount = 1;
    let answer = '';
    while(testCount <= +lines[0]) {
        let data = lines[testCount].split(" ").map(Number);
        let result = foo(data[0], data[1]);
        answer += result +"\n";
        testCount++;
    }
    console.log(answer);
})

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
  inputString = inputString.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  main();
});

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

function solve(n, k) {
  let count = 0;
  let curCount = Math.floor(k / n);
  while (count !== curCount) {
    count = curCount;
    curCount = Math.floor((k + count) / n);
  }
  return k + curCount;
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let [n, k] = readLine().split(' ').map((val) => parseInt(val));
    // let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(n, k);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

function main() {
  var testCasesNum = +readline();
  for (var i = 0; i < testCasesNum; i++) {
    var nk = readline().split(" ").map(Number);
    var n = nk[0];
    var k = nk[1];
    if (k < n) {
      print(k);
      continue;
    }
    var kdn = Math.floor(k / (n - 1));
    print(kdn * n + (k % (n - 1) || -1));
  }
}
main()

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
  8
10 3
100 4
8 7
97 2
8 8
3 10
5 3
1000000000 9

**/

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

    for(let r=0;r<range;r++) {
        let [n , k ] = readline().split(" ").map(Number);
        let sum = k;
        sum+=Math.floor((k-1) / (n-1));

        console.log(sum);
    }

}

function solve() {
    var input = readIntArray()
    var n = input[0]
    var k = input[1]

    var ans = Math.floor(k/(n-1))
    var rem = k % (n-1)

    var answer = ans*n + rem
    if (answer % n === 0) {
        answer -= 1
    }
    print(answer)
}

var testCases = readInt();
var testCaseNum;
for(testCaseNum=0; testCaseNum<testCases; testCaseNum++) {
  solve()
}

function readIntArray() {
    return readline().split(" ").map(function(x) { return parseInt(x); });
}

function readInt() {
    return parseInt(readline())
}

function getKthNonDivisibleByN(n,k) {
  var p = n-1
	var mod = k % p
	var d = Math.floor(k/p)
	var ans = d*n+mod
	if (k % p == 0)
		ans = ans-1
	return ans
}

var tc = Number(readline())
while (tc--) {
	var str = readline()
	var arr = str.split(" ")
	var n = arr[0]
	var k = arr[1]
  print(getKthNonDivisibleByN(n,k))
}

'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(str => str.trim());

    main();
});

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

function main() {
    const t = parseInt(readLine(), 10);
    for (let i = 0; i< t;i++){
        let [n,k] = readLine().split(' ').map(x=>parseInt(x));
        let f = getValidTerms(1, k, n);
        console.log(f);

    }

    function getValidTerms(a, n, div) {
        let f = a + n - 1;
        let s = Math.floor((f-a)/div);
        if(a%div == 0) s++;
        else if (f%div == 0) s++;
        if (f-a<div){
            let a1 = a + n - a%n;
            if (a1<f) return ++f;
        }
        if (s <= 0){
            return f;
        } else {
            return getValidTerms(f+1, s, div);
        }
    }
    return;

}

'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(str => str.trim());

    main();
});

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

function main() {
    const t = parseInt(readLine(), 10);
    for (let i = 0; i< t;i++){
        let [n,k] = readLine().split(' ').map(x=>parseInt(x));
        let f = getValidTerms(1, k, n);
        console.log(f);

    }

    function getValidTerms(a, n, div) {
        let f = a + n - 1;
        let s = Math.floor((f-a)/div);
        if(a%div == 0) s++;
        else if (f%div == 0) s++;

        if (s <= 0){
            return f;
        } else {
            return getValidTerms(f+1, s, div);
        }
    }
    return;

}

'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(str => str.trim());

    main();
});

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

function main() {
    const t = parseInt(readLine(), 10);
    for (let i = 0; i< t;i++){
        let [n,k] = readLine().split(' ').map(x=>parseInt(x));
        let f = getValidTerms(1, k, n);
        console.log(f);

    }

    function getValidTerms(a, n, div) {
        let f = a + n - 1;
        let s = Math.floor((f-a)/div);
        if(a%div == 0) s++;
        else if (f%div == 0) s++;
        if (f-a<div){
            let a1 = a + a%n;
            if (a1<f) return ++f;
        }
        if (s <= 0){
            return f;
        } else {
            return getValidTerms(f+1, s, div);
        }
    }
    return;

}

'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(str => str.trim());

    main();
});

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

function main() {
    const t = parseInt(readLine(), 10);
    for (let i = 0; i< t;i++){
        let [n,k] = readLine().split(' ').map(x=>parseInt(x));
      /*  let low = 0, high = k*2;
        while (low< high){
            const mid = Math.floor((low + high)/2);
            if (mid - Math.floor(mid/n) >= k){
                high = mid;
            } else{
                low = mid + 1;
            }
        }*/
        console.log(k + Math.floor(k/(n-1)) - ( (k !== n) && (k%n === 0) || k < n ? 1: 0))
    }
    return;
}

'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++];
}
/**
  8
10 3
100 4
8 7
97 2
8 8
3 10
5 3
1000000000 9

**/

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

    for(let r=0;r<range;r++) {
        let [n , k ] = readline().split(" ").map(Number);
        let sum = k;
        sum+=parseInt((k-1) / (n-1));

        console.log(sum);
    }

}

'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++];
}
/**
  8
10 3
100 4
8 7
97 2
8 8
3 10
5 3
1000000000 9

**/

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

    for(let r=0;r<range;r++) {
        let [n , k ] = readline().split(" ").map(Number);

        console.log(k + parseInt((k - 1) / (n - 1)))
    }

}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nk = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nk[0],
    k = nk[1];
  var res;
  if (n > k) res = k;
  else if (n == k) res = k + 1;
  else {
    var xx = n - 1;
    k = k - n + 1;
    res = xx + Math.ceil((n * k) / (n - 1));
    if (n % k == 0 || k % n == 0) res--;
  }

  print(res);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nk = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nk[0],
    k = nk[1];
  var res;
  if (n > k) res = k;
  else if (n == k) res = k + 1;
  else {
    var xx = n - 1;
    k = k - n + 1;
    res = xx + Math.floor((n * k) / (n - 1));
    if (n % k == 0 || k % n == 0) res--;
  }

  print(res);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nk = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nk[0],
    k = nk[1];
  var res = Math.floor((n * k) / (n - 1));
  print(res);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nk = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nk[0],
    k = nk[1];
  var res;
  if (n == k) res = k + 1;
  else if (n > k) res = k;
  else {
    var xx = n - 1;
    k = k - xx;
    res = xx + Math.ceil((n * k) / (n - 1));
    if (n % k == 0 || k % n == 0) res--;
  }

  print(res);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nk = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nk[0],
    k = nk[1];

  var res = Math.floor((n * k) / (n - 1));
  if (n % k == 0 || k % n == 0) res--;
  print(res);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nk = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nk[0],
    k = nk[1];

  var res = Math.floor((n * k) / (n - 1));
  if (n % k == 0) res--;
  print(res);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nk = readline()
    .split("")
    .map((val) => parseInt(val));
  var n = nk[0],
    k = nk[1];
  var res = Math.floor((n * k) / (n - 1));
  print(res);
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var nk = readline()
    .split(" ")
    .map((val) => parseInt(val));
  var n = nk[0],
    k = nk[1];

  var res = Math.floor((n * k) / (n - 1));
  if (n != k && (n % k == 0 || k % n == 0)) res--;
  print(res);
}