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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var Q = nextInt();
		var list = nextIntArray(N);
		var sum = new Array(N + 1).fill(0);
		for(var i = 0; i < N; i++){
			sum[i + 1] = sum[i] + list[i];
		}
		var binary = new Array(N + 1).fill(0);
		for(var i = 1; i <= N; i++){
			binary[i] = Math.max(binary[i - 1], list[i - 1]);
		}
		binary.push(Math.pow(10, 15));
		var output = new Array(Q);
		for(var i = 0; i < Q; i++){
			var qi = nextInt();
			var L = 0;
			var R = binary.length;
			while(R - L > 1){
				var C = Math.floor((L + R) / 2);
				var hi = binary[C];
				if(hi <= qi){
					L = C;
				}else{
					R = C;
				}
			}
			output[i] = sum[L];
		}
		myout(myconv(output, 8));
	}
}
function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let [n,q]=line[3*_-2].split(' ').map(x=>{return parseInt(x)});
        let a=line[3*_-1].split(' ').map(x=>{return parseInt(x)});
        let b=line[3*_].split(' ').map(x=>{return parseInt(x)});
        let sum=new Array(n+10);
        for(let i=0;i<n;i++)
        {
            sum[i]=a[i];
            if(i>0) sum[i]+=sum[i-1];
        }
        for(let i=1;i<n;i++)
        {
            a[i]=Math.max(a[i],a[i-1]);
        }
        let ans='';
        for(let i=0;i<q;i++)
        {
            let l=0,r=n-1
            while(l<r)
            {
                let mid=Math.floor((l+r+1)/2);
                if(a[mid]>b[i]) r=mid-1;
                else l=mid;
            }
            if(a[l]>b[i]) ans+=0+' ';
            else ans+=sum[l]+' ';
        }
        console.log(ans);
    }
})

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let [n,q]=line[3*_-2].split(' ').map(x=>{return parseInt(x)});
        let a=line[3*_-1].split(' ').map(x=>{return parseInt(x)});
        let b=line[3*_].split(' ').map(x=>{return parseInt(x)});
        let sum=new Array(n+10);
        for(let i=0;i<n;i++)
        {
            sum[i]=a[i];
            if(i>0) sum[i]+=sum[i-1];
        }
        for(let i=1;i<n;i++)
        {
            a[i]=Math.max(a[i],a[i-1]);
        }
        let ans='';
        for(let i=0;i<q;i++)
        {
            let l=0,r=n-1
            // console.log(b[i],l,r);
            while(l<r)
            {
                let mid=Math.floor((l+r+1)/2);
                if(a[mid]>b[i]) r=mid-1;
                else l=mid;
            }
            // console.log(l);
            if(a[l]>b[i]) ans+=0+' ';
            else ans+=sum[l]+' ';
        }
        console.log(ans);
    }
})

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const [n, q] = rns(),
        a = rns(),
        b = rns().map((num, i) => [num, i]);
  b.sort((a, b) => a[0] - b[0]);
  let max = a[0],
      res = new Array(q),
      sum = 0;
  for (let i = 0, j = 0; i < n && j < q; i++) {
    max = Math.max(max, a[i]);
    while (j < q && b[j][0] < max) {
      res[b[j][1]] = sum;
      j++;
    }
    sum += a[i];
  }
  for (let i = 0; i < q; i++) if (res[i] === undefined) res[i] = sum;
  return res.join(' ');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const n = rn(),
        q = rn(),
        tr = new SegTree(n),
        sum = new Array(n);
  sum[0] = 0;
  tr.update(0, 0, 0);
  for (let i = 1; i <= n; i++) {
    var _sum;
    let num = rn();
    tr.update(i, i, num);
    sum[i] = ((_sum = sum[i - 1]) !== null && _sum !== void 0 ? _sum : 0) + num;
  }
  const res = new Array(q);
  for (let i = 0; i < q; i++) {
    const k = rn();
    let l = 0,
        r = n;
    while (l < r) {
      const m = l + r + 1 >> 1;
      const max = tr.query(0, m);
      if (max <= k) {
        l = m;
      } else {
        r = m - 1;
      }
    }
    res[i] = sum[l];
  }
  return res.join(' ');
}
class SegTree {
  constructor(n) {
    this.n = n;
    this.root = this._newNode();
    this.update = (x, y, z) => {
      x = Math.max(x, 0);
      y = Math.min(y, n);
      this._update(this.root, 0, n, x, y, z);
    };
    this.query = (x, y) => {
      x = Math.max(x, 0);
      y = Math.min(y, n);
      return this._query(this.root, 0, n, x, y);
    };
  }
  _newNode(val = 0, left = null, right = null) {
    return {
      val,
      left,
      right
    };
  }
  _up(node) {
    const {
      left,
      right
    } = node;
    if (!left || !right) return;
    node.val = Math.max(left.val, right.val);
  }
  _update(node, l, r, x, y, z) {
    if (!node) return;
    if (l === x && r === y) {
      node.val = Math.max(node.val, z);
      return;
    }
    const mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    if (y <= mid) this._update(node.left, l, mid, x, y, z);else if (x > mid) this._update(node.right, mid + 1, r, x, y, z);else this._update(node.left, l, mid, x, mid, z), this._update(node.right, mid + 1, r, mid + 1, y, z);
    this._up(node);
  }
  _query(node, l, r, x, y) {
    if (y < x) return 0;
    if (!node) return 0;
    if (l === x && r === y) return node.val;
    let res = 0,
        mid = Math.floor((l + r) / 2);
    if (!node.left) {
      node.left = this._newNode();
      node.right = this._newNode();
    }
    if (y <= mid) res = this._query(node.left, l, mid, x, y);else if (x > mid) res = this._query(node.right, mid + 1, r, x, y);else res = Math.max(this._query(node.left, l, mid, x, mid), this._query(node.right, mid + 1, r, mid + 1, y));
    this._up(node);
    return res;
  }
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn();
    return res;
  };
  const re = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rn() - 1;
    return res;
  };
  const rbs = n => {
    let res = new Array(n);
    for (let i = 0; i < n; i++) res[i] = rb();
    return res;
  };
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  const [rn, rb, rns, re, rbs] = convertInput(r);
  try {
    let t = rn();
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

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

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function begin(steps, legs) {
    let n = steps.length;
    let q = legs.length;
    let res = new Array(q).fill(0);

    //print(steps);

    let maxSteps = new Array(n);
    let max = 0;
    for(let i = 0; i < n; i++) {
        if(steps[i] > max) {
            max = steps[i];
        }
        maxSteps[i] = max;
    }
    //print(maxSteps);

    let preSum = new Array(n);
    preSum[0] = steps[0];
    for(let i = 1; i < n; i++) {
        preSum[i] = steps[i] + preSum[i-1];
    }
    //print(preSum);

    let find = (num, nums) => {
        let left = 0, right = nums.length - 1;
        let target = num;
        while(left <= right) {
            let mid = left + Math.floor((right - left)/2);
            if(target < nums[mid]) {
                right = mid - 1;
            } else if(target >= nums[mid]) {
                left = mid + 1;
            }
        }
        return left;
    }

    for(let i = 0; i < q; i++) {
        let pos = find(legs[i], maxSteps);
        if(pos > 0) {
            res[i] = preSum[pos - 1];
        }
        //console.log(pos);
    }
    print(res.join(' '));

}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        let steps =  readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        let legs =  readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        begin(steps, legs);
    }
}

/**
 * 10/13/22 morning
 * https://codeforces.com/contest/1742/problem/E
 */

const pr = console.log;

function Bisect() {
    return { insort_right, insort_left, bisect_left, bisect_right }
    function insort_right(a, x, lo = 0, hi = null) {
        lo = bisect_right(a, x, lo, hi);
        a.splice(lo, 0, x);
    }
    function bisect_right(a, x, lo = 0, hi = null) { // > upper_bound
        if (lo < 0) throw new Error('lo must be non-negative');
        if (hi == null) hi = a.length;
        while (lo < hi) {
            let mid = parseInt((lo + hi) / 2);
            a[mid] > x ? hi = mid : lo = mid + 1;
        }
        return lo;
    }
    function insort_left(a, x, lo = 0, hi = null) {
        lo = bisect_left(a, x, lo, hi);
        a.splice(lo, 0, x);
    }
    function bisect_left(a, x, lo = 0, hi = null) { // >= lower_bound
        if (lo < 0) throw new Error('lo must be non-negative');
        if (hi == null) hi = a.length;
        while (lo < hi) {
            let mid = parseInt((lo + hi) / 2);
            a[mid] < x ? lo = mid + 1 : hi = mid;
        }
        return lo;
    }
}

const solve = (n, q, a, k) => {
    // pr(n, q, a, k)
    let s = [], sum = 0, bi = new Bisect(), res = [];
    for (const x of a) {
        sum += x;
        s.push(sum);
    }
    let min = [a[0]], cur = a[0];
    for (let i = 1; i < n; i++) {
        cur = Math.max(cur, a[i]);
        min.push(cur);
    }
    // pr(min);
    for (let h of k) {
        let i = bi.bisect_right(min, h) - 1;
        // pr('h', h, 'i', i);
        let v = s[i] || 0;
        res.push(v);
    }
    pr(res.join(" "))
};

const main = () => {
    const readLine = () => input[currentLine++];
    const ni = () => readLine() - '0';
    const nas = () => readLine().split(" ");
    const nai = () => nas().map(Number);
    const nal = () => nas().map(BigInt);
    let input = '', currentLine = 0;
    process.stdin.on('data', (stdin) => input += stdin)
    process.stdin.on('end', () => {
        input = input.split('\n');
        let t = ni();
        while (t--) {
            let [n, q] = nai(), a = nai(), k = nai();
            solve(n, q, a, k);
        }
    });
};

main()

const readline = require('readline')

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

function solve(n, arr, qs) {
    const max = Array(n)
    const hs = Array(n)
    for (let i = 0; i < arr.length; i++) {
        const x = arr[i]
        max[i] = x
        hs[i] = x
        if (i) {
            max[i] = Math.max(max[i], max[i - 1])
            hs[i] += hs[i - 1]
        }
    }
    // console.log(max, hs)
    return qs.map(k => {
        const i = binarySearch(0, n - 1, x => max[x] <= k)
        return i < 0 ? 0 : hs[i]
    }).join(' ')
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

let buf='';

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

process.stdin.on('end',function(){
    const {EOL}=require('os');
    let line=buf.split(EOL);
    let t=parseInt(line[0]);
    for(let _=1;_<=t;_++)
    {
        let [n,q]=line[3*_-2].split(' ').map(x=>{return parseInt(x)});
        let a=line[3*_-1].split(' ').map(x=>{return parseInt(x)});
        let b=line[3*_].split(' ').map(x=>{return parseInt(x)});
        let sum=new Array(n+10);
        for(let i=0;i<n;i++)
        {
            sum[i]=a[i];
            if(i>0) sum[i]+=sum[i-1];
        }
        for(let i=1;i<n;i++)
        {
            a[i]=Math.max(a[i],a[i-1]);
        }
        let ans='';
        for(let i=0;i<q;i++)
        {
            let l=0,r=n-1;
            while(l<r)
            {
                let mid=Math.floor((l+r+1)/2);
                if(a[mid]>b[i]) r=mid-1;
                else l=mid;
            }
            if(a[l]>b[l]) ans+=0+' ';
            else ans+=sum[l]+' ';
        }
        console.log(ans);
    }
})

'use strict';

var fs = require('fs');

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

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

function solve(read) {
  const [rn, rb, rns, re, rbs] = convertInput(read);
  const [n, q] = rns(),
        a = rns(),
        b = rns().map((num, i) => [num, i]);
  b.sort((a, b) => a[0] - b[0]);
  let max = a[0],
      res = new Array(q),
      sum = 0;
  for (let i = 0, j = 0; i < n && j < q; i++) {
    max = Math.max(max, a[i]);
    while (j < q && b[j][0] < max) {
      res[b[j][1]] = sum;
      j++;
    }
    sum += a[i];
  }
  for (let i = 0; i < q; i++) if (res[i] === undefined) res[i] = sum;
  return res.join(' ');
}
function convertInput(read) {
  const rn = () => Number(read());
  const rb = () => BigInt(read());
  const rns = () => read().split(/\s+/).map(Number);
  const re = () => read().split(/\s+/).map(s => Number(s) - 1);
  const rbs = () => read().split(/\s+/).map(BigInt);
  return [rn, rb, rns, re, rbs];
}
function main(r) {
  try {
    let t = Number(r());
    let res = new Array(t);
    let limit = 0;
    for (let i = 0; i < t; i++) {
      var _solve;
      const s = (_solve = solve(r)) !== null && _solve !== void 0 ? _solve : '';
      if (t < limit) {
        process.stdout.write(s.toString());
        process.stdout.write('\n');
      } else {
        res[i] = s;
      }
    }
    if (t >= limit) {
      return res.join('\n');
    } else {
      return '';
    }
  } catch (error) {
    console.log(error);
  }
}

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

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

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function begin(steps, legs) {
    let n = steps.length;
    let q = legs.length;
    let res = new Array(q).fill(0);

    //print(steps);

    let maxSteps = new Array(n);
    let max = 0;
    for(let i = 0; i < n; i++) {
        if(steps[i] > max) {
            max = steps[i];
        }
        maxSteps[i] = max;
    }
    //print(maxSteps);

    let preSum = new Array(n);
    preSum[0] = steps[0];
    for(let i = 1; i < n; i++) {
        preSum[i] = steps[i] + preSum[i-1];
    }
    //print(preSum);

    let find = (num, nums) => {
        let left = 0, right = nums.length - 1;
        let target = num;
        while(left <= right) {
            let mid = left + Math.floor((right - left)/2);
            if(target < nums[mid]) {
                right = mid - 1;
            } else if(target >= nums[mid]) {
                left = mid + 1;
            }
        }
        return left;
    }

    for(let i = 0; i < q; i++) {
        let pos = find(legs[i], maxSteps);
        if(pos > 0) {
            res[i] = preSum[pos - 1];
        }
        //console.log(pos);
    }
    print(res);

}

function main() {
    var caseNum = parseInt(readline(), 10);
    for (var i = 0; i < caseNum; i++) {
        var n = readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        let steps =  readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        let legs =  readline()
            .trim()
            .split(' ')
            .map((y) => parseInt(y, 10));
        begin(steps, legs);
    }
}


var t = Number(readline());
for (var i = 0; i < t; ++i)
{
    var param = readline().split(' ').map((val) => Number(val));
    var n = param[0];
    var mice = readline().split(' ').map((val) => Number(val));
    mice.sort((a, b) => a - b).reverse();

    var saved = 0;
    var cat = 0;
    for (var val of mice)
    {
        if (val > cat)
        {
            saved++;
            var distance = n - val;
            cat += distance;
        }
    }
    print(saved);
}

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

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

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

// ********** Code Start **********
function main() {
  var a = parseInt(readline())
  while(a--){
    var b = readline().split(' ').map(Number)
    var d = readline().split(' ').map(Number)
    d.sort(function(a,b){
			return b - a;
		});
    var cat = 0
    var count = 0
    for(let i = 0; i < d.length;i++){
      if(cat >= d[i]) break
      cat += b[0] - d[i]
      count++
    }
    print(count)
  }
}

'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 ok(x,n,k,a)
{
    let sum=0
    for(let i=x;i<k;i++)
        sum+=a[k-1]-a[i]
    if(a[k-1]<=sum)
       return 0;
    let cat=sum
    if(cat+(k-x)*(n-a[k-1])<n)
         return 1
    return 0;
}
function main() {
    let t=Number(readline())
    for(let j=1;j<=t;j++)
    {
        let [n,k]=readline().split(' ').map(Number)
        let a=readline().split(' ').map(Number)
        a.sort((a,b)=>a-b)
        let ans=0
        let L=0,R=k-1
        while(L<=R)
        {
            let Mid=Math.floor((L+R)/2)
            if(ok(Mid,n,k,a))
            {
                ans=k-Mid
                R=Mid-1
            }
            else
                L=Mid+1
        }
        console.log(ans)
    }
}

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

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var K = nextInt();
		var list = nextIntArray(K);
		list.sort(function(a,b){
			return b - a;
		});
		var output = 0;
		var sum = 0;
		for(var i = 0; i < K; i++){
			var xi = list[i];
			if(sum < xi){
				output++;
				sum += N - xi;
			}else{
				break;
			}
		}
		myout(output);
	}
}

const readline = require('readline')

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

function solve(n, k, arr) {
    arr.sort((a, b) => a - b)
    // console.log('arr', arr)
    const need = []
    for (let i = k - 1; i >= 0; i--) {
        need[i] = i !== k - 1 ? need[i + 1] + n - arr[i] : n - arr[i]
        // need[i] = i ? need[i - 1] + n - arr[i] : n - arr[i]
    }
    // console.log(need)
    const idx = binarySearch(0, k - 1, x => need[x] >= n)
    return k - (idx + 1)
}
function binarySearch(l, r, fn) {
    while (l <= r) {
        const m = Math.floor((l + r) / 2)
        if (fn(m)) {
            l = m + 1
        } else {
            r = m - 1
        }
    }
    return r
}

 var t = parseInt(readline());
  function solve() {
    var inp = readline()
      .split(" ")
      .map((data) => +data);

    var a = inp[0];
    var b = inp[1];

    var mice = readline()
      .split(" ")
      .map((data) => +data)
      .sort((a, b) => {
        if (a > b) {
          return -1;
        } else if (a < b) {
          return 1;
        } else {
          return 0;
        }
      });
    var cat = 0;
    var save = 0;

    for (var i = 0; i < b; i++) {
      if (cat < mice[i]) {
        save++;
        cat += a - mice[i];
      } else {
        break;
      }
    }
    return save;
  }

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b)
{
    if(b==0)
      return a;
    return gcd(b,a%b);
}
function ok(x,n,k,a)
{
    let sum=0
    for(let i=x;i<k;i++)
        sum+=a[k-1]-a[i]
    if(a[k-1]<=sum)
       return 0;
    let cat=sum
    if(cat+(k-x)*(n-a[k-1])<n)
    return 1
    else return 0;
}
function main() {
   let t=Number(readline())
    for(let j=1;j<=t;j++)
    {
        //let n=12
        //let k=11
        //a=[1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9,10 ,11].map(Number)
        let [n,k]=readline().split(' ').map(Number)
        let a=readline().split(' ').map(Number)
        //let n=4
        //let a=[1,1,1,1]
        a.sort((a,b)=>a-b)
        let ans=0
        let L=0,R=k-1
      //  ok(7,12,11,a);
      //  break;
        while(L<=R)
        {
            let Mid=Math.floor((L+R)/2)
            if(ok(Mid,n,k,a))
            {
                ans=k-Mid
                R=Mid-1
            }
            else
                L=Mid+1
        }
        console.log(ans)
    }
}

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

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

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

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

		let ans = 0;
		for (let i = 0, sm = 0; i < x.length; i++) {
			sm += n-x[i];
			if (sm >= n) {
				break;
			}
			ans++;
		}

		console.log(ans);
	}
}

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0;
    var x = 0;
    for(i = 1; i <= t * 2; i++){
        var k = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            n = k[0], x = k[1];
        }else{
            k.sort(function(a, b){return b - a});
            var a = 0;
            var ans = 0;
            for(j = 0; j < x; j++){
                a += n - k[j];
                if(a >= n){
                    break;
                }
                ans++;
            }
            console.log(ans);
        }
    }
});

let stop = '';
process.stdin.on('data', c => stop += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = stop.split(EOL);
    var t = lines[0];
    var n = 0, x = 0;
    for(i = 1; i <= t * 2 ; i++){
        var k = lines[i].split(' ').map(Number);
        if(i % 2 == 1){
            n = k[0], x = k[1];
        }else{
            k.sort(function(a, b){return b - a});
            var ans = 0, total = 0;
            for(j = 0; j < x; j++){
                total += n - k[j];
                if(total >= n){
                    break;
                }
                ans++;
            }
            console.log(ans);
        }
    }
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function saveMice(distances, hole) {
    let miceSaved = 0;
    for (let dist of distances) {
       if (hole - dist > 0) {
           miceSaved++;
           hole -= dist;
       } else {
           break;
       }
    }
    return miceSaved;
}

function main() {
    const n = readline();
    for (let i = 0; i < n; i++) {
        const hole = Number(readline().split(' ')[0]);
        const miceDistancesFromHole = readline().split(' ').map(m => hole - Number(m)).sort((a, b) => a - b);
        console.log(saveMice(miceDistancesFromHole, hole))
    }
}

'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 numberOfTestcases = parseInt(readline(), 10)
	for(let i = 0; i < numberOfTestcases; i++) {
		let [hole, mice] = readline().split(" ")
		let positions = readline().split(" ")
		console.log(solve(hole, mice, positions))
		// fs.appendFileSync("output.txt", `Case #${i+1}: ${solve(x)}` + "\n")
	}

}

function solve(hole, mice, positions) {
	let maxMove = hole - 1
	positions.sort((a,b) => a-b)
	let result = 0
	while(maxMove > 0 && positions.length > 0) {
		let position = positions[positions.length -1]
		let moveNeed = hole - position
		if(maxMove >= moveNeed) {
			positions.pop()
			maxMove -= moveNeed
			result++
		}
		else break
	}
	return result
}

'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 numberOfTestcases = parseInt(readline(), 10)
	for(let i = 0; i < numberOfTestcases; i++) {
		let [hole, mice] = readline().split(" ")
		let positions = readline().split(" ")
		console.log(solve(hole, mice, positions))
		// print(solve(x))
		// fs.appendFileSync("output.txt", `Case #${i+1}: ${solve(x)}` + "\n")
	}

}

function solve(hole, mice, positions) {
	let maxMove = hole - 1
	positions.sort((a,b) => a-b)
	let heap = new MinHeap((a,b) => {
		if(a<b) return -1
		if(a===b) return 0
		return 1
	})
	while(maxMove > 0 && positions.length > 0) {
		let position = positions[positions.length -1]
		let moveNeed = hole - position
		if(maxMove >= moveNeed) {
			positions.pop()
			maxMove -= moveNeed
			heap.push(position)
		}
		else break
	}

	let result = 0
	let cat = 0
	while(heap.length) {
		let mouse = heap.pop()
		if(mouse < hole - 1) {
			heap.push(mouse + 1)
		} else {
			result++
		}
		cat++
		while(heap.length && cat === heap.peek()) {
			heap.pop()
		}
	}
	return result
}

class MinHeap {
	constructor(fn) {
		this.cmp = fn
		this.arr = []
	}

	get length() {
		return this.arr.length
	}

	peek() {
		return this.arr[0]
	}

	push(val) {
		this.arr.push(val)
		this.bubbleUp()
	}

	pop() {
		let pop = this.arr[0];
		[this.arr[0], this.arr[this.arr.length - 1]] = [this.arr[this.arr.length - 1], this.arr[0]];
		this.arr.pop()
		this.bubbleDown()
		return pop
	}

	swap(a, b) {
		[this.arr[a], this.arr[b]] = [this.arr[b], this.arr[a]]
	}

	bubbleUp() {
		let current = this.arr.length - 1
		while(current > 0) {
			let parent = Math.ceil((current / 2)) - 1
			if(this.cmp(this.arr[current], this.arr[parent]) === -1) {
				this.swap(current, parent)
				current = parent
			} else {
				break
			}
		}
	}

	bubbleDown() {
		let current = 0
		while(true) {
			let left = current * 2 + 1
			if(left >= this.arr.length) return
			let right = left + 1
			if(right >= this.arr.length) right = left
			let smaller
			if(this.cmp(this.arr[left], this.arr[right]) === -1) {
				smaller = left
			} else {
				smaller = right
			}

			if(this.cmp(this.arr[smaller], this.arr[current]) === -1) {
				this.swap(smaller, current)
				current = smaller
			} else {
				break
			}
		}
	}
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let [h, n] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    arr.sort((a, b) => b - a);
    let res = 0,
      j = 0;
    for (let i = 0; i < n; i++) {
      if (j < arr[i]) {
        let d = h - arr[i];
        j += d;
        res++;
      } else break;
    }
    console.log(res);
  }
};
solve();

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

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

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

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

// ********** Code Start **********
function main() {
  let a = parseInt(readline())
  while(a--){
    let b = readline().split(' ').map(Number)
    let d = readline().split(' ').map(Number)
    d.sort(function(a,b){
			return b - a;
		});
    let cat = 0
    let count = 0
    for(let i = 0; i < d.length;i++){
      if(cat >= d[i]) break
      cat += b[0] - d[i]
      count++
    }
    print(count)
  }
}

'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 gcd(a,b)
{
    if(b==0)
      return a;
    return gcd(b,a%b);
}
function ok(x,n,k,a)
{
    let sum=0
    for(let i=x;i<k;i++)
        sum+=a[k-1]-a[i]
    if(a[k-1]<=sum)
       return 0;
    let cat=sum
    if(cat+(k-x)*(n-a[k-1])<=n)
    return 1
    else return 0;
}
function main() {
   let t=Number(readline())
    for(let j=1;j<=t;j++)
    {
        //let n=12
        //let k=11
        //a=[1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9,10 ,11].map(Number)
        let [n,k]=readline().split(' ').map(Number)
        let a=readline().split(' ').map(Number)
        //let n=4
        //let a=[1,1,1,1]
        a.sort((a,b)=>a-b)
        let ans=0
        let L=0,R=k-1
      //  ok(7,12,11,a);
      //  break;
        while(L<=R)
        {
            let Mid=Math.floor((L+R)/2)
            if(ok(Mid,n,k,a))
            {
                ans=k-Mid
                R=Mid-1
            }
            else
                L=Mid+1
        }
        console.log(ans)
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b)
{
    if(b==0)
      return a;
    return gcd(b,a%b);
}
function ok(x,n,k,a)
{
    let sum=0
    for(let i=x;i<k;i++)
        sum+=a[k-1]-a[i]
    if(a[k-1]<=sum)
       return 0;
    let cat=sum
    if(cat+(k-x)*(n-a[k-1])<=n)
    return 1
    else return 0;
}
function main() {
   let t=Number(readline())
    for(let j=1;j<=t;j++)
    {
        //let n=12
        //let k=11
        //a=[1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9,10 ,11].map(Number)
        let [n,k]=readline().split(' ').map(Number)
        let a=readline().split(' ').map(Number)
        //let n=4
        //let a=[1,1,1,1]
        a.sort()
        let ans=0
        let L=0,R=k-1
      //  ok(7,12,11,a);
      //  break;
        while(L<=R)
        {
            let Mid=Math.floor((L+R)/2)
            if(ok(Mid,n,k,a))
            {
                ans=k-Mid
                R=Mid-1
            }
            else
                L=Mid+1
        }
        console.log(ans)
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b)
{
    if(b==0)
      return a;
    return gcd(b,a%b);
}
function ok(x,n,k,a)
{
    let sum=0
    for(let i=x;i<k;i++)
        sum+=a[k-1]-a[i]
    if(a[k-1]<=sum)
       return 0;
    let cat=sum
    if(cat+(k-x)*(n-a[k-1])<n)
    return 1
    else return 0;
}
function main() {
   let t=Number(readline())
    for(let j=1;j<=t;j++)
    {
        //let n=12
        //let k=11
        //a=[1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9,10 ,11].map(Number)
        let [n,k]=readline().split(' ').map(Number)
        let a=readline().split(' ').map(Number)
        //let n=4
        //let a=[1,1,1,1]
        a.sort()
        let ans=0
        let L=0,R=k-1
      //  ok(7,12,11,a);
      //  break;
        while(L<=R)
        {
            let Mid=Math.floor((L+R)/2)
            if(ok(Mid,n,k,a))
            {
                ans=k-Mid
                R=Mid-1
            }
            else
                L=Mid+1
        }
        console.log(ans)
    }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function gcd(a,b)
{
    if(b==0)
      return a;
    return gcd(b,a%b);
}
function ok(x,n,k,a)
{
    console.log(a)
    let sum=0
    for(let i=x;i<k;i++)
        sum+=a[k-1]-a[i]
    if(a[k-1]<=sum)
       return 0;
    let cat=sum
    if(cat+(k-x)*(n-a[k-1])<n)
    return 1
    else return 0;
}
function main() {
   let t=Number(readline())
    for(let j=1;j<=t;j++)
    {
        //let n=12
        //let k=11
        //a=[1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9,10 ,11].map(Number)
        let [n,k]=readline().split(' ').map(Number)
        let a=readline().split(' ').map(Number)
        //let n=4
        //let a=[1,1,1,1]
        a.sort()
        let ans=0
        let L=0,R=k-1
      //  ok(7,12,11,a);
      //  break;
        while(L<=R)
        {
            let Mid=Math.floor((L+R)/2)
            if(ok(Mid,n,k,a))
            {
                ans=k-Mid
                R=Mid-1
            }
            else
                L=Mid+1
        }
        console.log(ans)
    }
}

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

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

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

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

		let ans = 0;
		for (let i = 0, sm = 0; sm < n && i < x.length; i++) {
			sm += n-x[i];
			ans++;
		}
		--ans;

		console.log(ans);
	}
}

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

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

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

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

		let sm = 0, i = 0;
		while (sm < n && i < x.length) {
			sm += n-x[i++];
		}

		const ans = i-1;

		console.log(ans);
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function saveMice(distances, hole) {
    let miceSaved = 0;
    for (let dist of distances) {
       if (hole - dist > 0) {
           miceSaved++;
           hole -= dist;
       } else {
           return miceSaved;
       }
    }
}

function main() {
    const n = readline();
    for (let i = 0; i < n; i++) {
        const hole = Number(readline().split(' ')[0]);
        const miceDistancesFromHole = readline().split(' ').map(m => hole - Number(m)).sort((a, b) => a - b);
        console.log(saveMice(miceDistancesFromHole, hole))
    }
}