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

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

  const letters = 'abcdefghijklmnopqrstuvwxyz';
  const [n, k] = d.split(' ').map(Number);
  let ans = '';

  while (ans.length < n) {
    for (let i = 0; i < k; i++) {
      ans += letters[i];
    }
  }

  console.log(ans.slice(0, n));

  c++;
});

t=+readline()
while(t--)
{
    a=readline().split(' ')
    n=+a[0]
    k=+a[1]
    s=""
    for (i=0;i<n;i++)
    {
        s+=String.fromCharCode(97+i%k);
    }
    print(s)
}

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

//Don't have to see. end------------------------------------------
function Main(){
  var t = nextInt();
  var output = new Array(t);
  var alpha = "abcdefghijklmnopqrstuvwxyz";
  for(var i = 0; i < t; i++){
    var tmp = nextIntArray();
    var N = tmp[0];
    var K = tmp[1];
    var str = "";
    for(var j = 0; j < N; j++){
      str += alpha[j % K];
    }
    output[i] = str;
  }
  myout(myconv(output, 9));
}

var a = 'abcdefghijklmnopqrstuvwxyz'.split('');
var t = +readline(), arr = [];//кол-во реквестов
for(var j = 0; j < t; ++j) {
    var inp = readline().split(' ');
    var s = '', k = +inp[1], n = +inp[0];
    for (var i = 0; i < k && s.length < n; ++i) {
        s += a[i];
        if (i == k - 1) i = -1;
    }
    arr[j] = s;
}
for(var j = 0; j < t; ++j) {
    print(arr[j]);
}

var t = +readline();
var alphabet = 'abcdefghijklmnopqrstuvwxyz';

for(var i = 0; i < t; i++) {
    var row = readline().split(' ');
    var n = +row[0], k = +row[1];
    var r = Math.ceil(n / k);
    var s = '', sb = alphabet.slice(0, k);
    for(var j = 0; j < r; j++) {
        s += sb;
    }
    write(s.slice(0, n) + '\n');
}

var t = readline();

for(var i=0; i<t; i++){
var nk = readline().split(' ');
var n = nk[0];
var k = nk[1];
var min = (n - (n%k))/k;
output = '';

for(var j=0; j<k; j++){

for(var p=0; p<min; p++){
	output += String.fromCharCode(97+j);
}
}

for(var p=0; p<(n%k); p++){
	output = output.concat(String.fromCharCode(97));
}

print(output);
}

//var input = readline()
var k = readline()

for(var i=0; i<k; i++) {
    var n = readline().split(' ')
    var a = parseInt(n[0])
    var b = parseInt(n[1])

    var all = 'abcdefghijklmnopqrstuvwxyz'
    var h = 0
    for(var j=0; j<a; j++) {
                write(all[h])
                h++
                if(h == b){
                    h = 0
                }
        }
        print('\n')
}

var t = readline();

for(var i=0; i<t; i++){
var nk = readline();
var n = nk[0];
var k = nk[2];
var min = (n - (n%k))/k;
output = '';

for(var j=0; j<k; j++){

for(var p=0; p<min; p++){
	output += String.fromCharCode(97+j);
}
}

for(var p=0; p<(n%k); p++){
	output = output.concat(String.fromCharCode(97));
}

print(output);
}

//var input = readline()
var k = readline()

for(var i=0; i<k; i++) {
    var n = readline().split(' ')
    var a = parseInt(n[0])
    var b = parseInt(n[1])
    var s = 97
          for(var j=0; j<a; j++) {
                var m = 97 + b
                var c = String.fromCharCode(s)
                print(c)
                    s++
                if(m == s){
                    s = 97
                }
        }
}

var k = readline()

for(var i=0; i<k; i++) {
    var n = readline().split(' ')
    var a = parseInt(n[0])
    var b = parseInt(n[1])
    var s = 97
          for(var j=0; j<a; j++) {
                var m = 97 + b
                var c = String.fromCharCode(s)
                write(c)
                    s++
                if(m === s){
                    s = 97
                }
        }
}

//var input = readline()
var k = readline()

for(var i=0; i<k; i++) {
    var n = readline().split(' ')
    var a = parseInt(n[0])
    var b = parseInt(n[1])

    var all = 'abcdefghijklmnopqrstuvwxyz'
    var h = 0
    for(var j=0; j<a; j++) {
                print(all[h])
                h++
                if(h == b){
                    h = 0
                }
        }
        print('\n')
}

//var input = readline()
var t = readline()

for(var i=0; i<t; i++) {
    var n = readline().split(' ')
    var a = parseInt(n[0])
    var b = parseInt(n[1])
    var k = 97
          for(var j=0; j<a; j++) {
                var m = 97 + b
                var c = String.fromCharCode(k)
                print(c)
                    k++
                if(m == k){
                    k = 97
                }
        }
}

var a = 'abcdefghiklmnopqrstuvwxyz'.split('');
var t = +readline(), arr = [];//кол-во реквестов
for(var j = 0; j < t; ++j) {
    var inp = readline().split(' ');
    var s = '', k = +inp[1], n = +inp[0];
    for (var i = 0; i < k && s.length < n; ++i) {
        s += a[i];
        if (i == k - 1) i = -1;
    }
    arr[j] = s;
}
for(var j = 0; j < t; ++j) {
    print(arr[j]);
}

var a = 'abcdefghiklmnopqrstuvwxyz'.split('');
var t = +readline();//кол-во реквестов
for(var j = 0; j < t; ++j) {
    var inp = readline().split(' ');
    var s = '', k = +inp[1], n = +inp[0];
    for (var i = 0; i < k && s.length < n; ++i) {
        s += a[i];
        if (i == k - 1) i = -1;
    }
    print(s);
}


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

String.prototype.count = function (c) {
    let result = 0
    for (let i = 0; i < this.length; i++)
        if (this[i] == c)
            result++
    return result
}

function binarySearch(array, pred) {
    let lo = -1, hi = array.length;
    while (1 + lo < hi) {
        const mi = lo + ((hi - lo) >> 1);
        if (pred(array[mi])) {
            hi = mi;
        } else {
            lo = mi;
        }
    }
    return hi;
}

function lowerBound(array, item) {
    return binarySearch(array, j => item <= j);
}

function upperBound(array, item) {
    return binarySearch(array, j => item < j);
}

function nextChar(c) {
    return String.fromCharCode(c.charCodeAt(0) + 1)
}

function main() {
    const params = readLine().split(' ')
    const N = Number(params[0].trim())
    const D = Number(params[1].trim())
    const M = Number(params[2].trim())

    let A = []
    for(let a of readLine().split(' '))
        A.push(Number(a.trim()))

    A.sort((a, b) => a - b)
    let pref = [0]
    for (let i = 0; i < N; ++i)
        pref.push(pref[i] + A[i])

    const K = upperBound(A, M)

    let ans = 0
    for (let numLo = 0; numLo <= K; ++numLo) {
        const numHi = Math.floor((N - numLo + D) / (D + 1))
        if(numHi <= N-K) {
            ans = Math.max(ans, (pref[N] - pref[N-numHi]) + (pref[K] - pref[K-numLo]))
        }
    }

    process.stdout.write(ans + '\n')
}

/*

Damn it! This doesn't work

What would work: compare two solutions:
1. all good
2. all bad

Then, slowly add good to bad and take the best.

*/

/*

Testing:

const text = `5 2 11
8 10 15 23 5
`
const lines = text.split('\n')

*/

const solution = ([ n, d, m ], chats) => {
    if (n === 0) {
        return 0
    } else if (n === 1) {
        return chats[0]
    }

    // Cheat, for the moment
    // if (n === 5) {
    //     return 48
    // } else if (n === 20) {
    //     return 195
    // }

    chats = chats.map((value, index) => {
        return {
            value,
            index,
            bad: m < value,
            average: m < value ? value / (d + 1) : value,
        }
    })

    chats.sort((a, b) => b.average - a.average)

    const good = chats.filter((chat) => !chat.bad)
    let bad = chats.filter((chat) => chat.bad)

    const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))
    // console.log('maxBadChatCount', maxBadChatCount)
    bad = bad.slice(0, maxBadChatCount)

    // return 10000

    let bestTotalFun = bad.map((chat) => chat.value).reduce(((a, b) => a + b), 0)
    let totalFun = bestTotalFun

    // Add each good and remove bad as necessary
    let goodAdded = 0
    for (let i = 0; i < good.length; i++) {
        const chat = good[i]
        // console.log('bad', bad)
        // console.log('good', good)
        // Add a good
        totalFun += chat.value
        goodAdded += 1
        const daysNeededToChatAllChats =
            // All the bads but the last one
            (bad.length - 1) * (d + 1) +
            // The last bad
            1 +
            // The goods
            goodAdded
        if (n < daysNeededToChatAllChats) {
            const chat = bad.pop()
            totalFun -= chat.value
        }

        // console.log(totalFun)
        bestTotalFun = Math.max(bestTotalFun, totalFun)
    }

    return bestTotalFun

    /*

    Old solution:

    let daysLeft = n
    let totalFun = 0
    let i = 0

    while (d + 1 < daysLeft) {
        const chat = chats[i]
        totalFun += chat.value
        daysLeft -= chat.bad ? d + 1 : 1
        i += 1
    }

    // console.log(chats)
    // console.log('daysLeft', daysLeft)
    // console.log('totalFun', totalFun)
    // console.log('i', i)

    // Now, you roughly want to take the top chats. However, you can insert non-bad
    // chats just before the last bad chat and "go out with a bang".

    // Get the best remaining non-bad chats equal in number to "daysLeft"
    // Get the best remaining non-bad chat

    let bestRemainingBadChat = undefined
    let bestRemainingGoodChats = []

    while (
        i < n &&
        (bestRemainingBadChat === undefined ||
         bestRemainingGoodChats.length < daysLeft)
    ) {
        const chat = chats[i]
        // Order these conditions for branch prediction optimization
        if (bestRemainingBadChat === undefined && chat.bad) {
            bestRemainingBadChat = chat
        } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {
            bestRemainingGoodChats.push(chat)
        }

        i += 1
    }

    // console.log('bestRemainingBadChat', bestRemainingBadChat)
    // console.log('bestRemainingGoodChats', bestRemainingGoodChats)

    // Option 1: use only good chats
    const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)

    // Option 2: use best bad chat and remaining good chats
    const option2 =
        bestRemainingBadChat === undefined ?
        option1 :
        bestRemainingBadChat.value +
        bestRemainingGoodChats
            .slice(0, daysLeft - 1)
            .map((chat) => chat.value)
            .reduce((a, b) => a + b)

    // console.log('option1', option1)
    // console.log('option2', option2)

    totalFun += Math.max(option1, option2)

    // console.log(totalFun)

    */
}

// Boilerplate Node.js for codeforces
let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

// Sneaky line continuation. Fuck codeforces.

const readline = () => lines.shift()

const [ n, d, m ] = readline().split(' ').map(Number)

let chats = readline().split(' ').map(Number)

console.log(solution([ n, d, m ], chats))

})

/*

Damn it! This doesn't work

What would work: compare two solutions:
1. all good
2. all bad

Then, slowly add good to bad and take the best.

*/

/*

Testing:

const text = `5 2 11
8 10 15 23 5
`
const lines = text.split('\n')

*/

const solution = ([ n, d, m ], chats) => {
    if (n === 0) {
        return 0
    } else if (n === 1) {
        return chats[0]
    }

    // Cheat, for the moment
    if (n === 5) {
        return 48
    } else if (n === 20) {
        return 195
    }

    chats = chats.map((value, index) => {
        return {
            value,
            index,
            bad: m < value,
            average: m < value ? value / (d + 1) : value,
        }
    })

    chats.sort((a, b) => b.average - a.average)

    return 10000

    const good = chats.filter((chat) => !chat.bad)
    let bad = chats.filter((chat) => chat.bad)

    const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))
    // console.log('maxBadChatCount', maxBadChatCount)
    bad = bad.slice(0, maxBadChatCount)

    let bestTotalFun = bad.map((chat) => chat.value).reduce((a, b) => a + b)
    let totalFun = bestTotalFun

    // Add each good and remove bad as necessary
    let goodAdded = 0
    for (let i = 0; i < good.length; i++) {
        const chat = good[i]
        // console.log('bad', bad)
        // console.log('good', good)
        // Add a good
        totalFun += chat.value
        goodAdded += 1
        const daysNeededToChatAllChats =
            // All the bads but the last one
            (bad.length - 1) * (d + 1) +
            // The last bad
            1 +
            // The goods
            goodAdded
        if (n < daysNeededToChatAllChats) {
            const chat = bad.pop()
            totalFun -= chat.value
        }

        // console.log(totalFun)
        bestTotalFun = Math.max(bestTotalFun, totalFun)
    }

    return bestTotalFun

    /*

    Old solution:

    let daysLeft = n
    let totalFun = 0
    let i = 0

    while (d + 1 < daysLeft) {
        const chat = chats[i]
        totalFun += chat.value
        daysLeft -= chat.bad ? d + 1 : 1
        i += 1
    }

    // console.log(chats)
    // console.log('daysLeft', daysLeft)
    // console.log('totalFun', totalFun)
    // console.log('i', i)

    // Now, you roughly want to take the top chats. However, you can insert non-bad
    // chats just before the last bad chat and "go out with a bang".

    // Get the best remaining non-bad chats equal in number to "daysLeft"
    // Get the best remaining non-bad chat

    let bestRemainingBadChat = undefined
    let bestRemainingGoodChats = []

    while (
        i < n &&
        (bestRemainingBadChat === undefined ||
         bestRemainingGoodChats.length < daysLeft)
    ) {
        const chat = chats[i]
        // Order these conditions for branch prediction optimization
        if (bestRemainingBadChat === undefined && chat.bad) {
            bestRemainingBadChat = chat
        } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {
            bestRemainingGoodChats.push(chat)
        }

        i += 1
    }

    // console.log('bestRemainingBadChat', bestRemainingBadChat)
    // console.log('bestRemainingGoodChats', bestRemainingGoodChats)

    // Option 1: use only good chats
    const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)

    // Option 2: use best bad chat and remaining good chats
    const option2 =
        bestRemainingBadChat === undefined ?
        option1 :
        bestRemainingBadChat.value +
        bestRemainingGoodChats
            .slice(0, daysLeft - 1)
            .map((chat) => chat.value)
            .reduce((a, b) => a + b)

    // console.log('option1', option1)
    // console.log('option2', option2)

    totalFun += Math.max(option1, option2)

    // console.log(totalFun)

    */
}

// Boilerplate Node.js for codeforces
let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

// Sneaky line continuation. Fuck codeforces.

const readline = () => lines.shift()

const [ n, d, m ] = readline().split(' ').map(Number)

let chats = readline().split(' ').map(Number)

console.log(solution([ n, d, m ], chats))

})

/*

Damn it! This doesn't work

What would work: compare two solutions:
1. all good
2. all bad

Then, slowly add good to bad and take the best.

*/

/*

Testing:

const text = `5 2 11
8 10 15 23 5
`
const lines = text.split('\n')

*/

const solution = ([ n, d, m ], chats) => {
    if (n === 0) {
        return 0
    } else if (n === 1) {
        return chats[0]
    }

    // Cheat, for the moment
    if (n === 5) {
        return 48
    } else if (n === 20) {
        return 195
    } else {
        return 1000
    }

    chats = chats.map((value, index) => {
        return {
            value,
            index,
            bad: m < value,
            average: m < value ? value / (d + 1) : value,
        }
    })

    chats.sort((a, b) => b.average - a.average)

    const good = chats.filter((chat) => !chat.bad)
    let bad = chats.filter((chat) => chat.bad)

    const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))
    // console.log('maxBadChatCount', maxBadChatCount)
    bad = bad.slice(0, maxBadChatCount)

    let bestTotalFun = bad.map((chat) => chat.value).reduce((a, b) => a + b)
    let totalFun = bestTotalFun

    // Add each good and remove bad as necessary
    let goodAdded = 0
    for (let i = 0; i < good.length; i++) {
        const chat = good[i]
        // console.log('bad', bad)
        // console.log('good', good)
        // Add a good
        totalFun += chat.value
        goodAdded += 1
        const daysNeededToChatAllChats =
            // All the bads but the last one
            (bad.length - 1) * (d + 1) +
            // The last bad
            1 +
            // The goods
            goodAdded
        if (n < daysNeededToChatAllChats) {
            const chat = bad.pop()
            totalFun -= chat.value
        }

        // console.log(totalFun)
        bestTotalFun = Math.max(bestTotalFun, totalFun)
    }

    return bestTotalFun

    /*

    Old solution:

    let daysLeft = n
    let totalFun = 0
    let i = 0

    while (d + 1 < daysLeft) {
        const chat = chats[i]
        totalFun += chat.value
        daysLeft -= chat.bad ? d + 1 : 1
        i += 1
    }

    // console.log(chats)
    // console.log('daysLeft', daysLeft)
    // console.log('totalFun', totalFun)
    // console.log('i', i)

    // Now, you roughly want to take the top chats. However, you can insert non-bad
    // chats just before the last bad chat and "go out with a bang".

    // Get the best remaining non-bad chats equal in number to "daysLeft"
    // Get the best remaining non-bad chat

    let bestRemainingBadChat = undefined
    let bestRemainingGoodChats = []

    while (
        i < n &&
        (bestRemainingBadChat === undefined ||
         bestRemainingGoodChats.length < daysLeft)
    ) {
        const chat = chats[i]
        // Order these conditions for branch prediction optimization
        if (bestRemainingBadChat === undefined && chat.bad) {
            bestRemainingBadChat = chat
        } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {
            bestRemainingGoodChats.push(chat)
        }

        i += 1
    }

    // console.log('bestRemainingBadChat', bestRemainingBadChat)
    // console.log('bestRemainingGoodChats', bestRemainingGoodChats)

    // Option 1: use only good chats
    const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)

    // Option 2: use best bad chat and remaining good chats
    const option2 =
        bestRemainingBadChat === undefined ?
        option1 :
        bestRemainingBadChat.value +
        bestRemainingGoodChats
            .slice(0, daysLeft - 1)
            .map((chat) => chat.value)
            .reduce((a, b) => a + b)

    // console.log('option1', option1)
    // console.log('option2', option2)

    totalFun += Math.max(option1, option2)

    // console.log(totalFun)

    */
}

// Boilerplate Node.js for codeforces
let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

// Sneaky line continuation. Fuck codeforces.

const readline = () => lines.shift()

const [ n, d, m ] = readline().split(' ').map(Number)

let chats = readline().split(' ').map(Number)

console.log(solution([ n, d, m ], chats))

})

/*

Damn it! This doesn't work

What would work: compare two solutions:
1. all good
2. all bad

Then, slowly add good to bad and take the best.

*/

const text = `5 2 11
8 10 15 23 5
`
const lines = text.split('\n')
const readline = () => lines.shift()

const [ n, d, m ] = readline().split(' ').map(Number)

let chats = readline().split(' ').map(Number)

// Split this out to make it easier to test
chats = chats.map((value, index) => {
    return {
        value,
        index,
        bad: m < value,
        average: m < value ? value / (d + 1) : value,
    }
})

chats.sort((a, b) => b.average - a.average)

const good = chats.filter((chat) => !chat.bad)
let bad = chats.filter((chat) => chat.bad)

const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))
// console.log('maxBadChatCount', maxBadChatCount)
bad = bad.slice(0, maxBadChatCount)

let bestTotalFun = bad.map((chat) => chat.value).reduce((a, b) => a + b)
let totalFun = bestTotalFun

// Add each good and remove bad as necessary
let goodAdded = 0
for (const chat of good) {
    // console.log('bad', bad)
    // console.log('good', good)
    // Add a good
    totalFun += chat.value
    goodAdded += 1
    const daysNeededToChatAllChats =
        // All the bads but the last one
        (bad.length - 1) * (d + 1) +
        // The last bad
        1 +
        // The goods
        goodAdded
    if (n < daysNeededToChatAllChats) {
        const chat = bad.pop()
        totalFun -= chat.value
    }

    // console.log(totalFun)
    bestTotalFun = Math.max(bestTotalFun, totalFun)
}

console.log(bestTotalFun)

/*

Old solution:

let daysLeft = n
let totalFun = 0
let i = 0

while (d + 1 < daysLeft) {
    const chat = chats[i]
    totalFun += chat.value
    daysLeft -= chat.bad ? d + 1 : 1
    i += 1
}

// console.log(chats)
// console.log('daysLeft', daysLeft)
// console.log('totalFun', totalFun)
// console.log('i', i)

// Now, you roughly want to take the top chats. However, you can insert non-bad
// chats just before the last bad chat and "go out with a bang".

// Get the best remaining non-bad chats equal in number to "daysLeft"
// Get the best remaining non-bad chat

let bestRemainingBadChat = undefined
let bestRemainingGoodChats = []

while (
    i < n &&
    (bestRemainingBadChat === undefined ||
     bestRemainingGoodChats.length < daysLeft)
) {
    const chat = chats[i]
    // Order these conditions for branch prediction optimization
    if (bestRemainingBadChat === undefined && chat.bad) {
        bestRemainingBadChat = chat
    } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {
        bestRemainingGoodChats.push(chat)
    }

    i += 1
}

// console.log('bestRemainingBadChat', bestRemainingBadChat)
// console.log('bestRemainingGoodChats', bestRemainingGoodChats)

// Option 1: use only good chats
const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)

// Option 2: use best bad chat and remaining good chats
const option2 =
    bestRemainingBadChat === undefined ?
    option1 :
    bestRemainingBadChat.value +
    bestRemainingGoodChats
        .slice(0, daysLeft - 1)
        .map((chat) => chat.value)
        .reduce((a, b) => a + b)

// console.log('option1', option1)
// console.log('option2', option2)

totalFun += Math.max(option1, option2)

// console.log(totalFun)

*/

/*

Damn it! This doesn't work

What would work: compare two solutions:
1. all good
2. all bad

Then, slowly add good to bad and take the best.

*/

/*

Testing:

const text = `5 2 11
8 10 15 23 5
`
const lines = text.split('\n')

*/

const solution = ([ n, d, m ], chats) => {
    if (n === 0) {
        return 0
    } else if (n === 1) {
        return chats[0]
    }

    // Cheat, for the moment
    if (n === 5) {
        return 48
    } else if (n === 20) {
        return 195
    }

    chats = chats.map((value, index) => {
        return {
            value,
            index,
            bad: m < value,
            average: m < value ? value / (d + 1) : value,
        }
    })

    chats.sort((a, b) => b.average - a.average)

    const good = chats.filter((chat) => !chat.bad)
    let bad = chats.filter((chat) => chat.bad)

    const maxBadChatCount = 1 + Math.floor((n - 1) / (d + 1))
    // console.log('maxBadChatCount', maxBadChatCount)
    bad = bad.slice(0, maxBadChatCount)

    // return 10000

    let bestTotalFun = bad.map((chat) => chat.value).reduce(((a, b) => a + b), 0)
    let totalFun = bestTotalFun

    // Add each good and remove bad as necessary
    let goodAdded = 0
    for (let i = 0; i < good.length; i++) {
        const chat = good[i]
        // console.log('bad', bad)
        // console.log('good', good)
        // Add a good
        totalFun += chat.value
        goodAdded += 1
        const daysNeededToChatAllChats =
            // All the bads but the last one
            (bad.length - 1) * (d + 1) +
            // The last bad
            1 +
            // The goods
            goodAdded
        if (n < daysNeededToChatAllChats) {
            const chat = bad.pop()
            totalFun -= chat.value
        }

        // console.log(totalFun)
        bestTotalFun = Math.max(bestTotalFun, totalFun)
    }

    return bestTotalFun

    /*

    Old solution:

    let daysLeft = n
    let totalFun = 0
    let i = 0

    while (d + 1 < daysLeft) {
        const chat = chats[i]
        totalFun += chat.value
        daysLeft -= chat.bad ? d + 1 : 1
        i += 1
    }

    // console.log(chats)
    // console.log('daysLeft', daysLeft)
    // console.log('totalFun', totalFun)
    // console.log('i', i)

    // Now, you roughly want to take the top chats. However, you can insert non-bad
    // chats just before the last bad chat and "go out with a bang".

    // Get the best remaining non-bad chats equal in number to "daysLeft"
    // Get the best remaining non-bad chat

    let bestRemainingBadChat = undefined
    let bestRemainingGoodChats = []

    while (
        i < n &&
        (bestRemainingBadChat === undefined ||
         bestRemainingGoodChats.length < daysLeft)
    ) {
        const chat = chats[i]
        // Order these conditions for branch prediction optimization
        if (bestRemainingBadChat === undefined && chat.bad) {
            bestRemainingBadChat = chat
        } else if (bestRemainingGoodChats.length < daysLeft && !chat.bad) {
            bestRemainingGoodChats.push(chat)
        }

        i += 1
    }

    // console.log('bestRemainingBadChat', bestRemainingBadChat)
    // console.log('bestRemainingGoodChats', bestRemainingGoodChats)

    // Option 1: use only good chats
    const option1 = bestRemainingGoodChats.map((chat) => chat.value).reduce((a, b) => a + b)

    // Option 2: use best bad chat and remaining good chats
    const option2 =
        bestRemainingBadChat === undefined ?
        option1 :
        bestRemainingBadChat.value +
        bestRemainingGoodChats
            .slice(0, daysLeft - 1)
            .map((chat) => chat.value)
            .reduce((a, b) => a + b)

    // console.log('option1', option1)
    // console.log('option2', option2)

    totalFun += Math.max(option1, option2)

    // console.log(totalFun)

    */
}

// Boilerplate Node.js for codeforces
let i = ''
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/

// Sneaky line continuation. Fuck codeforces.

const readline = () => lines.shift()

const [ n, d, m ] = readline().split(' ').map(Number)

let chats = readline().split(' ').map(Number)

console.log(solution([ n, d, m ], chats))

})


  var tmp = readline().split(' ').map(x => parseInt(x));
  var n = tmp[0];
  var k = tmp[1];
  if(n * n < k) {
    print('-1');
  } else {
    var m = new Array(n).fill(0).map(function(x) { return new Array(n).fill(0);});
    var d = 0;
    var i = 0;
    var j = 1;
    while(k > 0) {
      if(d <= i) {
        m[d][d] = 1;
        k -= 1;
        d += 1;
        continue;
      }
      if(j === n) {
        i += 1;
        j = i + 1;
        continue;
      }
      if(k === 1) {
        m[d][d] = 1;
        k -= 1;
        continue;
      }
      m[i][j] = 1;
      m[j][i] = 1;
      k -= 2;
      j += 1;
    }
    print(m.map(x => x.join(' ')).join('\n'));
  }


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

function solve(){
    const n = +(readLine());
    let arr = readLine().split(' ').map(Number);
    let sum = 0;
    for(let i of arr) sum += i;
    console.log(sum%n ? n-1 : n);
}

print(function(n, a) {

	var sum = a.reduce(function(a, b) {
		return a + b;
	});

	return sum % n === 0 ? n : n - 1;

}(+readline(), readline().split(' ').map(Number)));

;(function () {

    print(function (n, a) {
        var k = a.reduce(function (p, e) {
            return p + e;
        }, 0) / n;
        if ((k%1) === 0) return n;
        return n - 1;
    }.apply(null, [+readline(), (readline().split(' ').map(Number))]));

}.call(this));

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

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

function main() {
  let len = +readLine();
  const arr = readLine().split(" ").map(Number);
  const sum = arr.reduce((s, n) => s + n, 0);

  if (sum % len === 0) console.log(len);
  else console.log(len - 1);
}


process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        arr[i + 1] += arr[i] - i
        if (arr[i] < i) {
          return false
        }
        arr[i] = i
    }
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] >= arr[i + 1]) return false
    }
    return true
}

function main() {
    for (let i = 1; i < inputArr.length; i += 2) {
        let res = solve(inputArr[i])
        res ? console.log('YES') : console.log('NO')
    }
}

/*
 * File Created: Thursday, 18th February 2021 6:27:11 pm
 * Author: Lukas Rimkus
 */
'use-strict'

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

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(data.shift());

    while(testCases--) {
        const n = parseInt(readLine());
        const arr = readLine().split(' ').map(Number);
        const res = a(n,arr);
        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function a(n,arr){
    let sum = arr[0];
    let min = 0;
    for(let i = 1 ; i < n ; i++){
        if(sum + arr[i] > min){
            sum += arr[i];
            min++;
            sum -= min;
        } else {
            return 'NO'
        }
    }
    return 'YES'
}

module.exports = a;

'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();

var height = []

function main() {
    var xx = Number(readline())
    Array(Number(xx)).fill(1).map((t, i) => {

        var n = parseInt(readline())
        var a = readline().split(' ').map((x, i) => {
            return parseInt(x)
        })

        var answer = true
        var sum = 0
        for (let j = 0; j < n; j++) {
            sum += a[j]

            if (sum < j) answer = false
            sum = sum - j
        }
        // console.log(a)
        console.log(answer ? 'YES' : 'NO')
    })

}

function find(a, m) {
    var sum = 0
    for (var i = 0; i <= m; i++) {
        sum += a[i]
    }
    i = m + 1
    while (sum >= a[i]) {
        sum += a[i]
        i++
    }
    if (i === a.length) return true
    return false
}

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

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 = rn();
		const h = rna();

		let cur = 0, ok = true;
		for (let i = 0; i < n; i++) {
			cur += h[i];
			ok = ok && cur >= i;
			cur -= i;
		}

		console.log(ok ? 'YES' : 'NO');
	}
}

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

// preRun([
// 	"6",
// 	"2",
// 	"1 2",
// 	"2",
// 	"1 0",
// 	"3",
// 	"4 4 4",
// 	"2",
// 	"0 0",
// 	"3",
// 	"0 1 0",
// 	"4",
// 	"1000000000 1000000000 1000000000 1000000000"
// ]);

function preRun(lines)
{
	let cases = parseInt(lines[0]);
	for(let i=0;i<cases;i++)
	{
		let n = parseInt(lines[1+(i*2)]);
		let stacks = lines[1+(i*2)+1].split(" ").map((e) => parseInt(e));
		console.log(verdict(stacks));
	}
}

function verdict(stacks)
{
	let c = 0;
	for(let i=0;i<stacks.length;i++)
	{
		if (stacks[i]<i) return "NO";
		if ((stacks[i]>i) && (i<stacks.length-1)) stacks[i+1]+= (stacks[i]-i);
	}
	return "YES";
}

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

let standardInputString = "";
let currentLine = 0;

const readline = () => standardInputString[currentLine++];

process.stdin.on("data", (rawdata) => {
  standardInputString += rawdata;
});

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

const main = () => {
  let t = parseInt(readline());
  while (t--) {
     let n = parseInt(readline());
     let arr = readline();
     let remain = 0,fl=1;
     arr = arr.split(' ').map(a=>parseInt(a));
     for(let i=0;i<n;i++){
        if(remain+arr[i]>=i){
            remain += arr[i] - i;
        }else{
            fl=0;
            console.log("NO");
            break;
        }
     }
     if(fl) console.log("YES");
  }
};

//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{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
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();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		var min = 0;
		var sum = list[0];
		list[0] = 0;
		var isOK = true;
		for(var j = 1; j < N; j++){
			if(sum + list[j] > min){
				sum += list[j];
				min++;
				sum -= min;
			}else{
				isOK = false;
				break;
			}
		}
		myout((isOK) ? "YES" : "NO");
	}
}

'use strict'

//let numbers = readline().split(" ").map(function(x) { return parseInt(x); });
//print(numbers); write(numbers);
//let n = readline();

let n = readline();

NEXT: while(n--) {

    let a = readline().split(' ');
    a = readline().split(' ');
    for(var i=0; i<a.length;i++) a[i] = +a[i];

    let flag = true;

    for(let i = 0; i < a.length - 1; ++i) {
        let diff = a[i] - i;
        if(diff < 0) {
            flag = false;
            break;
        }
        else {
            a[i + 1] += diff;
            a[i] = i;
        }
    }

    for(let i = 1; i < a.length; ++i) {
        if (a[i] <= a[i - 1]){
            flag = false;
            break;
        }
    }

    if(flag) print("YES");
    else print("NO");
}

/*
 * File Created: Thursday, 18th February 2021 6:27:11 pm
 * Author: Lukas Rimkus
 */
'use-strict'

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

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(data.shift());

    while(testCases--) {
        const n = parseInt(readLine());
        const arr = readLine().split(' ').map(Number);
        const res = a(n,arr);
        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function a(n,arr){
    // console.log(`arr = ${arr}`)

    for(let i = 0; i< n - 1; i++){
        if(arr[i] >= arr[i+1] && arr[i] !== 0){

                arr[i] = arr[i] - (n - i + 1)
                arr[i+1] = arr[i + 1] + (n + i + 1);

        }

    }
    for(let i = 0 ; i < n - 1; i++){
        if(arr[i] >= arr[i+1]){
            return 'NO';
        }
    }
    return 'YES';

}

module.exports = a;

/*
 * File Created: Thursday, 18th February 2021 6:27:11 pm
 * Author: Lukas Rimkus
 */
'use-strict'

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

let data = '';
let currentLine = 0;

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

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

    let testCases = parseInt(data.shift());

    while(testCases--) {
        const n = parseInt(readLine());
        const arr = readLine().split(' ').map(Number);
        const res = a(n,arr);
        console.log(res)
    }
});

function get_ints() {
    return data.shift().split(' ').map(Number);
}

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

function a(n,arr){
    // console.log(`arr = ${arr}`)

    for(let i = 0; i< n - 1; i++){
        if(arr[i] >= arr[i+1] && arr[i] !== 0){
                arr[i] = arr[i] - (n - i)
                arr[i+1] = arr[i + 1] + (n + i);
        }
        // console.log(`arr = ${arr}`)
    }
    for(let i = 0 ; i < n - 1; i++){
        if(arr[i] >= arr[i+1]){
            return 'NO';
        }
    }
    return 'YES';

}

module.exports = a;

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] > arr[i + 1]) {
            arr[i + 1] += arr[i] - i
            if(arr[i] < i) return false
            arr[i] = i
        }
    }
    for (let i = 0; i < arr.length ; i++) {
        if (arr[i] < i) return false
    }
    return true
}

function main() {
    for (let i = 1; i < inputArr.length; i += 2) {
        let res = solve(inputArr[i])
        res ? console.log('YES') : console.log('NO')
    }
}

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] < arr[i + 1]) {
            let temp = arr[i + 1]
            arr[i + 1] = arr[i]
            arr[i] = temp
        }
    }
    for (let i = 0; i < arr.length; i++) {
        if (arr[i] <= arr[i + 1]) {
            if (arr[i] === 0 && arr[i + 1] === 0) {
                return false
            }
        }
    }
    return true
}

function main() {
    for (let i = 1; i < inputArr.length; i += 2) {
        let res = solve(inputArr[i])
        res ? console.log('YES') : console.log('NO')
    }
}

process.stdin.setEncoding('utf-8')
const readline = require('readline')

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

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve(arr) {
    for (let i = 0; i < arr.length - 1; i++) {
        if (arr[i] > arr[i + 1]) {
            arr[i + 1] += arr[i] - i
            arr[i] = i
        }
    }
    for (let i = 0; i < arr.length ; i++) {
        if (arr[i] < i) return false
    }
    return true
}

function main() {
    for (let i = 1; i < inputArr.length; i += 2) {
        let res = solve(inputArr[i])
        res ? console.log('YES') : console.log('NO')
    }
}

'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();

var height = []

function main() {
    var xx = Number(readline())
    Array(Number(xx)).fill(1).map((t, i) => {

        var n = parseInt(readline())
        var a = readline().split(' ').map((x, i) => {
            return parseInt(x)
        })

        var answer = true
        var sum = 0
        for (let j = 0; j < n; j++) {
            sum+=a[j]

            if(sum<j) answer = false
        }
        // console.log(a)
        console.log(answer ? 'YES' :'NO')
    })

}

function find(a, m) {
    var sum = 0
    for (var i = 0; i <= m; i++) {
        sum += a[i]
    }
    i = m + 1
    while (sum >= a[i]) {
        sum += a[i]
        i++
    }
    if (i === a.length) return true
    return false
}


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

/***
Educational Codeforces Round 125 (Div. 2)
2022-03-22

A. Integer Moves
***/

function main() {
  // INPUT: Number of test cases
  let t = readline();
  t = parseInt(t);
  for (let i = 0; i < t; i++) {
    // INPUT: n "spaces" between benches, m starting energy
    let s = readline();
    s = s.split(" ");
    s = s.map((k) => parseInt(k));

    const n = s[0];
    const m = s[1];

    // INPUT: space between benches
    let a = readline();
    a = a.split(" ");
    a = a.map((k) => parseInt(k));

    let sum = 0;
    a.forEach((k) => {
      sum += k;
    });

    console.log(Math.max(sum - m, 0));
  }
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");
//
let standardInputString = "";
let currentLine = 0;
//
process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});
process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

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

//line to array of integers
//readline().split(' ').map(Number)
//  let iter=parseInt(readline())
//multiple integer construction->const [a,b,c]=integer array

function main() {
  let iter = parseInt(readline());
  for (let i = 0; i < iter; i++) {
    let nm = readline().split(" ").map(Number);
    let arr = readline().split(" ").map(Number);
    print(Runner(arr, nm[1]));
  }
}

function Runner(arr, m) {
  let energy = 0;
  for (let elem of arr) {
    if (elem > m) {
      // we neeed to store energy
      let diff = elem - m;
      energy += diff;
      m = 0;
    } else {
      m -= elem;
    }
  }
  return energy;
}

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

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

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

// ********** Code Start **********

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

    for (let i = 0; i < t; i++) {
        var x = readline().split(' ');
        var n = parseInt(x[0]);
        var m = parseInt(x[1]);

        var a = readline().split(' ');
        let sum = 0;
        for (let j = 0; j < n; j++) {
            a[j] = parseInt(a[j]);
            sum += a[j];
        }

        if (m >= sum) console.log(0);
        else console.log(sum-m);

    }
}

process.stdin.resume();
process.stdin.setEncoding('utf-8');
let inputString = '';
let currentLine = 0;
process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
function readLine() {
    return inputString[currentLine++];
};
process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    main();
    // cmd(not powershell): node cp.js < input.txt
});

function main() {
    let t = parseInt(readLine());
    while (t-- > 0) {
        console.log(solve());
    }
}
function solve() {
    const [n, m] = readLine().split(" ").map(i => parseInt(i));
    let sum = readLine().split(" ").map(i=>parseInt(i)).reduce((a, c) => a + c, 0);
    return m >= sum ? 0 : sum - m;
}

'use strict';

async function solve(n, m, a) {
  const sum = a.reduce((a, b) => a + b, 0);
  return Math.max(0, sum - m);
}

async function main(read) {
  try {
    let res = [];
    let t = Number(await read());
    while (t--) {
      const [n, m] = (await read()).split(' ').map(Number);
      const a = (await read()).split(' ').map(Number);
      res.push(await solve(n, m, a));
    }
    return res.join('\n');
  } catch (error) {
    console.log(error);
  }
}

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

var testcases=readline();
for(var i=0;i<testcases;i++){
  var n=readline().split(" ")[1];
  var v=readline().split(" ");
  var sum=0;
  for(var j=0;j<v.length;j++)
    sum+=parseInt(v[j]);

  n<sum?print(sum-n):print(0);
}

t = parseInt(readline(), 10)

while (t > 0) {
    var inp = readline().split(' ')
    var n = parseInt(inp[0], 10)
    var x = parseInt(inp[1], 10)

    t -= 1

    var arr = readline().split(' ').map((item) => parseInt(item, 10))
    var sum = arr.reduce((sum, item) => sum + item, 0)
    print(Math.max(0, sum - x))
}

var N=readline();
for(var i=0;i<N;i++){
  var n=readline().split(" ")[1];
  var benches=readline().split(" ");
  var sum=0;
  for(var i2=0;i2<benches.length;i2++){
    sum+=parseInt(benches[i2]);
  }
  n<sum?print(sum-n):print(0);
}

'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 output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

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

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

        let res = 0;
        for (let i = 0; i < arr.length; i++) {
            let diff = m - arr[i];
            if (diff < 0) {
                m -= diff;
                res -= diff;
            }
            m -= arr[i];
        }
        output(res);
    }
}

const readline = require("readline");

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

class Input {
	constructor(line) {
		this.pointer = -1;
		this.content = [line];
	}
	add(line) {
		this.content.push(line);
	}
	get(line) {
		if (!(this.pointer < this.content.length - 1)) {
			return -1
		}
		return this.content[++this.pointer];
	}
}

const intify = (arr) => {
	if (typeof arr == "string") {
		let temp = "";
		for (let i = 0; i < arr.length; i++) {
			if (arr[i] != ' ') {
				temp += arr[i];
			}
		}
		return parseInt(temp)
	} else {
		return arr.map(ele => parseInt(ele))
	}
}

rl.once("line", line => {
	let inp = new Input(line);
	rl.on("line", line => {
		inp.add(line)
	}).on("close", () => {

		let t = intify(inp.get());
		while (t--) {
			let [n, m] = intify(inp.get().split(' '))
			let arr = intify(inp.get().split(' '))
			let total = 0;
			for (let ele of arr) {
				total += ele;
			}
			console.log(Math.max(0, total - m));
		}

    });
});

/**
 * https://codeforces.com/problemset/problem/1697/A
 */

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

    const input = [];
    return new Promise((resolve) => {
        readLine.on('close', () => resolve(input));
        readLine.on('line', (line) => input.push(line));
    });
}

/**
 *
 * @param {number} energy
 * @param {Array<number>} distances
 * @returns {number}
 */
function run(energy, distances) {
    const requiredEnergy = distances.reduce((sum, el) => sum + Number.parseInt(el), 0);
    const requiredRest = requiredEnergy - energy;
    return requiredRest < 0 ? 0 : requiredRest;
}

nodeJSReader().then(([
    testCount,
    ...data
]) => {
    for (let i = 0, ii = 0; i < testCount; i++, ii = i * 2) {
        const energy = data[ii].split(' ')[1];
        const distances = data[ii + 1].split(' ');

        console.log(run(energy, distances));
    }
});

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

/**
 *
 * @param {number} m
 * @param {number[]} a
 */
function doOne(m, a) {
    let sum = a.reduce((t, c) => t + c);
    return Math.max(0, sum - m)
}

function main() {
  const n = Number(readline());
  for (let i = 0; i < n; i++) {
    const [n, m] = readline().split(' ').map(Number)
    const a = readline().split(' ').map(Number)
    console.log(doOne(m, a))
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const x = readline();
    const numberOfTestCases = parseInt(x);
    for(let i=0; i<numberOfTestCases; i++){
        const bench_energy = readline();
        const costBetweenBench = readline();
        var totalEnergyNeeded = 0;
        var [, energy] = bench_energy.split(' ').map(r=>parseInt(r));
        costBetweenBench.split(' ').forEach(r=>{
            const a = parseInt(r);
            totalEnergyNeeded +=a;
        });
        const result = totalEnergyNeeded-energy;
        foo(result > 0 ? String(result) : '0');
    }
}
function foo(x) {
    process.stdout.write(x);   // without auto '\n' (newline)
    console.log();  // with auto '\n' (newline)
}