William has a favorite bracket sequence. Since his favorite sequence is quite big he provided it to you as a sequence of positive integers $$$c_1, c_2, \dots, c_n$$$ where $$$c_i$$$ is the number of consecutive brackets "(" if $$$i$$$ is an odd number or the number of consecutive brackets ")" if $$$i$$$ is an even number.For example for a bracket sequence "((())()))" a corresponding sequence of numbers is $$$[3, 2, 1, 3]$$$.You need to find the total number of continuous subsequences (subsegments) $$$[l, r]$$$ ($$$l \le r$$$) of the original bracket sequence, which are regular bracket sequences.A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not.

The first line contains a single integer $$$n$$$ $$$(1 \le n \le 1000)$$$, the size of the compressed sequence. The second line contains a sequence of integers $$$c_1, c_2, \dots, c_n$$$ $$$(1 \le c_i \le 10^9)$$$, the compressed sequence.

Output a single integer — the total number of subsegments of the original bracket sequence, which are regular bracket sequences. It can be proved that the answer fits in the signed 64-bit integer data type.

NoteIn the first example a sequence (((()(()))( is described. This bracket sequence contains $$$5$$$ subsegments which form regular bracket sequences:  Subsequence from the $$$3$$$rd to $$$10$$$th character: (()(()))  Subsequence from the $$$4$$$th to $$$5$$$th character: ()  Subsequence from the $$$4$$$th to $$$9$$$th character: ()(())  Subsequence from the $$$6$$$th to $$$9$$$th character: (())  Subsequence from the $$$7$$$th to $$$8$$$th character: () In the second example a sequence ()))(()(()))) is described.In the third example a sequence ()()(()) is described.

'use strict'
var os = require('os')
function createInput(t) {
  const n = t.stdin || process.stdin,
    e = /-?\d+/g,
    r = /-?\d+(?:\.\d+)?/g
  let o = [],
    i = 0
  return {
    init: async function () {
      const t = []
      ;(o = await new Promise(e => {
        n.on('data', n => t.push(n)),
          n.on('end', function () {
            const n = t.join('').split(os.EOL)
            e(n)
          })
      })),
        (i = 0)
    },
    dried: function () {
      return i >= o.length
    },
    readLine: u,
    readLineAsNumber: function () {
      return Number(u())
    },
    readIntegersOfLine: function () {
      const t = u().match(e)
      return null == t ? [] : t.map(t => Number(t))
    },
    readNumsOfLine: function () {
      const t = u().match(r)
      return null == t ? [] : t.map(t => Number(t))
    },
  }
  function u() {
    return o[i++]
  }
}
function createOutput(t) {
  const n = t.stdout || process.stdout,
    e = t.encoding || 'ascii',
    r = t.outputBufferThreshold || 1 << 24,
    o = r >> 1,
    i = Buffer.alloc(r)
  let u = 0
  return {
    flush: c,
    print: function (t) {
      s('string' == typeof t ? t : t.toString())
    },
    println: function (t) {
      s(('string' == typeof t ? t : t.toString()).concat('\n'))
    },
  }
  function c() {
    n.write(i.toString(e, 0, u)), (u = 0)
  }
  function s(t) {
    const s = Buffer.byteLength(t, e)
    r - u < s && (c(), s > o) ? n.write(t) : (i.write(t, u, e), (u += s))
  }
}
function createInputAndOutput(t) {
  return {
    ...createInput({ stdin: t.stdin, encoding: t.encoding }),
    ...createOutput({
      stdout: t.stdout,
      encoding: t.encoding,
      outputBufferThreshold: t.outputBufferThreshold,
    }),
  }
}
async function __main__(t, n, e = {}) {
  const r = createInputAndOutput(e)
  await Promise.all([r.init(), Promise.resolve(n && n())]),
    await t(r),
    r.flush()
}
__main__(function (t) {
  const n = new Array(1010),
    e = new Array(1010),
    r = new Array(1010),
    o = new Array(1010),
    i = new Array(1010)
  for (let c = 1; c <= 1; ++c) {
    const c = t.readLineAsNumber(),
      s = t.readIntegersOfLine(),
      f = u()
    function u() {
      if (c < 2) return 0
      e.fill(0, 0, c), r.fill(-1, 0, c)
      for (let t = 0; t < c; ++t) o[t] = s[t]
      let t = 0
      for (let e = 0; e < c; ++e)
        if (1 & e) {
          let u = s[e]
          for (; t > 0; ) {
            const c = i[--t],
              f = o[c]
            if (u === f) {
              ;(r[e] = c), (r[c] = e), (n[c] = s[c]), (u = 0)
              break
            }
            if (u < f) {
              ;(o[c] -= u), t++, (r[e] = c), (u = 0)
              break
            }
            ;(u -= f), (r[c] = e), (n[c] = s[c])
          }
          n[e] = s[e] - u
        } else i[t++] = e
      for (let e = 0; e < t; ++e) {
        const t = i[e]
        n[t] = s[t] - o[t]
      }
      for (let t = (1 & c ? c - 2 : c - 1) - 2; t > 0; t -= 2) {
        if (-1 === r[t]) continue
        const n = r[t + 1]
        ;-1 !== n && (e[t] = r[n] === t + 1 ? e[n] + 1 : 1)
      }
      let u = 0
      for (let t = 0; t < c; t += 2) u += n[t]
      let f = 0
      for (let t = 1; t < c; t += 2) f += e[t]
      return u + f
    }
    t.println(f.toString())
  }
})

'use strict'
var os = require('os')
function createInput(t) {
  const n = t.stdin || process.stdin,
    e = /-?\d+/g,
    r = /-?\d+(?:\.\d+)?/g
  let o = [],
    i = 0
  return {
    init: async function () {
      const t = []
      ;(o = await new Promise(e => {
        n.on('data', n => t.push(n)),
          n.on('end', function () {
            const n = t.join('').split(os.EOL)
            e(n)
          })
      })),
        (i = 0)
    },
    dried: function () {
      return i >= o.length
    },
    readLine: u,
    readLineAsNumber: function () {
      return Number(u())
    },
    readIntegersOfLine: function () {
      const t = u().match(e)
      return null == t ? [] : t.map(t => Number(t))
    },
    readNumsOfLine: function () {
      const t = u().match(r)
      return null == t ? [] : t.map(t => Number(t))
    },
  }
  function u() {
    return o[i++]
  }
}
function createOutput(t) {
  const n = t.stdout || process.stdout,
    e = t.encoding || 'ascii',
    r = t.outputBufferThreshold || 1 << 24,
    o = r >> 1,
    i = Buffer.alloc(r)
  let u = 0
  return {
    flush: c,
    print: function (t) {
      s('string' == typeof t ? t : t.toString())
    },
    println: function (t) {
      s(('string' == typeof t ? t : t.toString()).concat('\n'))
    },
  }
  function c() {
    n.write(i.toString(e, 0, u)), (u = 0)
  }
  function s(t) {
    const s = Buffer.byteLength(t, e)
    r - u < s && (c(), s > o) ? n.write(t) : (i.write(t, u, e), (u += s))
  }
}
function createInputAndOutput(t) {
  return {
    ...createInput({ stdin: t.stdin, encoding: t.encoding }),
    ...createOutput({
      stdout: t.stdout,
      encoding: t.encoding,
      outputBufferThreshold: t.outputBufferThreshold,
    }),
  }
}
async function __main__(t, n, e = {}) {
  const r = createInputAndOutput(e)
  await Promise.all([r.init(), Promise.resolve(n && n())]),
    await t(r),
    r.flush()
}
__main__(function (t) {
  const n = new Array(1010),
    e = new Array(1010),
    r = new Array(1010),
    o = new Array(1010),
    i = new Array(1010)
  for (let c = 1; c <= 1; ++c) {
    const c = t.readLineAsNumber(),
      s = t.readIntegersOfLine(),
      f = u()
    function u() {
      if (c < 2) return 0
      e.fill(0, 0, c), r.fill(-1, 0, c)
      for (let t = 0; t < c; ++t) o[t] = s[t]
      let t = 0
      for (let e = c - 1; e >= 0; --e)
        if (1 & e) i[t++] = e
        else {
          let u = s[e]
          for (; t > 0; ) {
            const c = i[--t],
              f = o[c]
            if (u === f) {
              ;(r[e] = c), (r[c] = e), (n[c] = s[c]), (u = 0)
              break
            }
            if (u < f) {
              ;(o[c] -= u), t++, (r[e] = c), (u = 0)
              break
            }
            ;(u -= f), (r[c] = e), (n[c] = s[c])
          }
          n[e] = s[e] - u
        }
      for (let e = 0; e < t; ++e) {
        const t = i[e]
        n[t] = s[t] - o[t]
      }
      for (let t = (1 & c ? c - 2 : c - 1) - 2; t > 0; t -= 2) {
        if (-1 === r[t]) continue
        const n = r[t + 1]
        ;-1 !== n && (e[t] = r[n] === t + 1 ? e[n] + 1 : 1)
      }
      let u = 0
      for (let t = 0; t < c; t += 2) u += n[t]
      let f = 0
      for (let t = 1; t < c; t += 2) f += e[t]
      return u + f
    }
    t.println(f.toString())
  }
})

'use strict'
var os = require('os')
function createInput(t) {
  const n = t.stdin || process.stdin,
    e = /-?\d+/g,
    r = /-?\d+(?:\.\d+)?/g
  let i = [],
    o = 0
  return {
    init: async function () {
      const t = []
      ;(i = await new Promise(e => {
        n.on('data', n => t.push(n)),
          n.on('end', function () {
            const n = t.join('').split(os.EOL)
            e(n)
          })
      })),
        (o = 0)
    },
    dried: function () {
      return o >= i.length
    },
    readLine: u,
    readLineAsNumber: function () {
      return Number(u())
    },
    readIntegersOfLine: function () {
      const t = u().match(e)
      return null == t ? [] : t.map(t => Number(t))
    },
    readNumsOfLine: function () {
      const t = u().match(r)
      return null == t ? [] : t.map(t => Number(t))
    },
  }
  function u() {
    return i[o++]
  }
}
function createOutput(t) {
  const n = t.stdout || process.stdout,
    e = t.encoding || 'ascii',
    r = t.outputBufferThreshold || 1 << 24,
    i = r >> 1,
    o = Buffer.alloc(r)
  let u = 0
  return {
    flush: c,
    print: function (t) {
      s('string' == typeof t ? t : t.toString())
    },
    println: function (t) {
      s(('string' == typeof t ? t : t.toString()).concat('\n'))
    },
  }
  function c() {
    n.write(o.toString(e, 0, u)), (u = 0)
  }
  function s(t) {
    const s = Buffer.byteLength(t, e)
    r - u < s && (c(), s > i) ? n.write(t) : (o.write(t, u, e), (u += s))
  }
}
function createInputAndOutput(t) {
  return {
    ...createInput({ stdin: t.stdin, encoding: t.encoding }),
    ...createOutput({
      stdout: t.stdout,
      encoding: t.encoding,
      outputBufferThreshold: t.outputBufferThreshold,
    }),
  }
}
async function __main__(t, n, e = {}) {
  const r = createInputAndOutput(e)
  await Promise.all([r.init(), Promise.resolve(n && n())]),
    await t(r),
    r.flush()
}
__main__(function (t) {
  const n = new Array(1010),
    e = new Array(1010),
    r = new Array(1010)
  for (let o = 1; o <= 1; ++o) {
    const o = t.readLineAsNumber(),
      u = t.readIntegersOfLine()
    n.fill(0, 0, o), e.fill(0, 0, o), r.fill(-1, 0, o)
    const c = i()
    function i() {
      const t = []
      let i = 0
      for (let e = o - 1; e >= 0; --e)
        if (1 & e) t[i++] = { idx: e, remain: u[e] }
        else {
          let o = u[e]
          for (; i > 0; ) {
            const { idx: c, remain: s } = t[--i]
            if (o === s) {
              ;(r[e] = c), (r[c] = e), (n[c] = u[c]), (o = 0)
              break
            }
            if (o < s) {
              ;(t[i++] = { idx: c, remain: s - o }), (r[e] = c), (o = 0)
              break
            }
            ;(o -= s), (r[c] = e), (n[c] = u[c])
          }
          n[e] = u[e] - o
        }
      for (let e = 0; e < i; ++e) {
        const { idx: r, remain: i } = t[e]
        n[r] = u[r] - i
      }
      for (let t = (1 & o ? o - 2 : o - 1) - 2; t > 0; t -= 2) {
        if (-1 === r[t]) continue
        const n = r[t + 1]
        ;-1 !== n && (e[t] = r[n] === t + 1 ? e[n] + 1 : 1)
      }
      let c = 0
      for (let t = 0; t < o; t += 2) c += n[t]
      let s = 0
      for (let t = 1; t < o; t += 2) s += e[t]
      return c + s
    }
    t.println(c.toString())
  }
})

'use strict'
var os = require('os')
function createInput(n) {
  const t = n.stdin || process.stdin,
    e = /-?\d+/g,
    r = /-?\d+(?:\.\d+)?/g
  let i = [],
    o = 0
  return {
    init: async function () {
      const n = []
      ;(i = await new Promise(e => {
        t.on('data', t => n.push(t)),
          t.on('end', function () {
            const t = n.join('').split(os.EOL)
            e(t)
          })
      })),
        (o = 0)
    },
    dried: function () {
      return o >= i.length
    },
    readLine: u,
    readLineAsNumber: function () {
      return Number(u())
    },
    readIntegersOfLine: function () {
      const n = u().match(e)
      return null == n ? [] : n.map(n => Number(n))
    },
    readNumsOfLine: function () {
      const n = u().match(r)
      return null == n ? [] : n.map(n => Number(n))
    },
  }
  function u() {
    return i[o++]
  }
}
function createOutput(n) {
  const t = n.stdout || process.stdout,
    e = n.encoding || 'ascii',
    r = n.outputBufferThreshold || 1 << 24,
    i = r >> 1,
    o = Buffer.alloc(r)
  let u = 0
  return {
    flush: s,
    print: function (n) {
      c('string' == typeof n ? n : n.toString())
    },
    println: function (n) {
      c(('string' == typeof n ? n : n.toString()).concat('\n'))
    },
  }
  function s() {
    t.write(o.toString(e, 0, u)), (u = 0)
  }
  function c(n) {
    const c = Buffer.byteLength(n, e)
    r - u < c && (s(), c > i) ? t.write(n) : (o.write(n, u, e), (u += c))
  }
}
function createInputAndOutput(n) {
  return {
    ...createInput({ stdin: n.stdin, encoding: n.encoding }),
    ...createOutput({
      stdout: n.stdout,
      encoding: n.encoding,
      outputBufferThreshold: n.outputBufferThreshold,
    }),
  }
}
async function __main__(n, t, e = {}) {
  const r = createInputAndOutput(e)
  await Promise.all([r.init(), Promise.resolve(t && t())]),
    await n(r),
    r.flush()
}
__main__(function (n) {
  const t = new Array(1010),
    e = new Array(1010),
    r = new Array(1010)
  for (let o = 1; o <= 1; ++o) {
    const o = n.readLineAsNumber(),
      u = n.readIntegersOfLine()
    t.fill(0, 0, o), e.fill(0, 0, o), r.fill(-1, 0, o)
    const s = i()
    function i() {
      const n = []
      for (let e = o - 1; e >= 0; --e)
        if (1 & e) n.push({ idx: e, remain: u[e] })
        else {
          let i = u[e]
          for (; n.length > 0; ) {
            const { idx: o, remain: s } = n.pop()
            if (i === s) {
              ;(r[e] = o), (r[o] = e), (t[o] = u[o]), (i = 0)
              break
            }
            if (i < s) {
              n.push({ idx: o, remain: s - i }), (r[e] = o), (i = 0)
              break
            }
            ;(i -= s), (r[o] = e), (t[o] = u[o])
          }
          t[e] = u[e] - i
        }
      for (const { idx: e, remain: r } of n) t[e] = u[e] - r
      for (let n = (1 & o ? o - 2 : o - 1) - 2; n > 0; n -= 2) {
        if (-1 === r[n]) continue
        const t = r[n + 1]
        ;-1 !== t && (e[n] = r[t] === n + 1 ? e[t] + 1 : 1)
      }
      let i = 0
      for (let n = 0; n < o; n += 2) i += t[n]
      let s = 0
      for (let n = 1; n < o; n += 2) s += e[n]
      return i + s
    }
    n.println(s.toString())
  }
})

'use strict'
var os = require('os')
function createInput(t) {
  const n = t.stdin || process.stdin,
    e = /-?\d+/g,
    r = /-?\d+(?:\.\d+)?/g
  let i = [],
    o = 0
  return {
    init: async function () {
      const t = []
      ;(i = await new Promise(e => {
        n.on('data', n => t.push(n)),
          n.on('end', function () {
            const n = t.join('').split(os.EOL)
            e(n)
          })
      })),
        (o = 0)
    },
    dried: function () {
      return o >= i.length
    },
    readLine: u,
    readLineAsNumber: function () {
      return Number(u())
    },
    readIntegersOfLine: function () {
      const t = u().match(e)
      return null == t ? [] : t.map(t => Number(t))
    },
    readNumsOfLine: function () {
      const t = u().match(r)
      return null == t ? [] : t.map(t => Number(t))
    },
  }
  function u() {
    return i[o++]
  }
}
function createOutput(t) {
  const n = t.stdout || process.stdout,
    e = t.encoding || 'ascii',
    r = t.outputBufferThreshold || 1 << 24,
    i = r >> 1,
    o = Buffer.alloc(r)
  let u = 0
  return {
    flush: s,
    print: function (t) {
      c('string' == typeof t ? t : t.toString())
    },
    println: function (t) {
      c(('string' == typeof t ? t : t.toString()).concat('\n'))
    },
  }
  function s() {
    n.write(o.toString(e, 0, u)), (u = 0)
  }
  function c(t) {
    const c = Buffer.byteLength(t, e)
    r - u < c && (s(), c > i) ? n.write(t) : (o.write(t, u, e), (u += c))
  }
}
function createInputAndOutput(t) {
  return {
    ...createInput({ stdin: t.stdin, encoding: t.encoding }),
    ...createOutput({
      stdout: t.stdout,
      encoding: t.encoding,
      outputBufferThreshold: t.outputBufferThreshold,
    }),
  }
}
async function __main__(t, n, e = {}) {
  const r = createInputAndOutput(e)
  await Promise.all([r.init(), Promise.resolve(n && n())]),
    await t(r),
    r.flush()
}
__main__(function (t) {
  const n = new Array(1010),
    e = []
  for (let i = 1; i <= 1; ++i) {
    const i = t.readLineAsNumber(),
      o = t.readIntegersOfLine(),
      u = r()
    function r() {
      let t = 0
      for (let r, u = 0; u < i; u += 2) {
        let s = o[u],
          c = o[u]
        for (r = u + 1; r < i; ++r)
          if (1 & r) {
            if (((c -= o[r]), c < s && (s = c <= 0 ? 0 : c), 0 === s)) break
          } else c += o[r]
        ;(n[u] = o[u] - s), (t += n[u]), (e[u] = 0 === s ? r : -1)
      }
      for (let t = 1 & i ? i - 2 : i - 1; t >= 0; t -= 2) {
        let e = o[t],
          r = o[t]
        for (let n = t - 1; n >= 0; --n)
          if (1 & n) r += o[n]
          else if (((r -= o[n]), r < e && (e = r <= 0 ? 0 : r), 0 === e)) break
        n[t] = o[t] - e
      }
      let r = BigInt(t)
      for (let t = 1, u = i - 1; t < u; t += 2) {
        if (n[t] !== o[t]) continue
        let u = e[t + 1],
          s = 0
        for (; -1 != u && ((s += 1), n[t] === o[t] && u + 1 !== i); )
          u = e[u + 1]
        r += BigInt(s)
      }
      return r
    }
    t.println(u.toString())
  }
})

'use strict'
var os = require('os')
function createInput(t) {
  const n = t.stdin || process.stdin,
    e = /-?\d+/g,
    r = /-?\d+(?:\.\d+)?/g
  let i = [],
    o = 0
  return {
    init: async function () {
      const t = []
      ;(i = await new Promise(e => {
        n.on('data', n => t.push(n)),
          n.on('end', function () {
            const n = t.join('').split(os.EOL)
            e(n)
          })
      })),
        (o = 0)
    },
    dried: function () {
      return o >= i.length
    },
    readLine: u,
    readLineAsNumber: function () {
      return Number(u())
    },
    readIntegersOfLine: function () {
      const t = u().match(e)
      return null == t ? [] : t.map(t => Number(t))
    },
    readNumsOfLine: function () {
      const t = u().match(r)
      return null == t ? [] : t.map(t => Number(t))
    },
  }
  function u() {
    return i[o++]
  }
}
function createOutput(t) {
  const n = t.stdout || process.stdout,
    e = t.encoding || 'ascii',
    r = t.outputBufferThreshold || 1 << 24,
    i = r >> 1,
    o = Buffer.alloc(r)
  let u = 0
  return {
    flush: s,
    print: function (t) {
      c('string' == typeof t ? t : t.toString())
    },
    println: function (t) {
      c(('string' == typeof t ? t : t.toString()).concat('\n'))
    },
  }
  function s() {
    n.write(o.toString(e, 0, u)), (u = 0)
  }
  function c(t) {
    const c = Buffer.byteLength(t, e)
    r - u < c && (s(), c > i) ? n.write(t) : (o.write(t, u, e), (u += c))
  }
}
function createInputAndOutput(t) {
  return {
    ...createInput({ stdin: t.stdin, encoding: t.encoding }),
    ...createOutput({
      stdout: t.stdout,
      encoding: t.encoding,
      outputBufferThreshold: t.outputBufferThreshold,
    }),
  }
}
async function __main__(t, n, e = {}) {
  const r = createInputAndOutput(e)
  await Promise.all([r.init(), Promise.resolve(n && n())]),
    await t(r),
    r.flush()
}
__main__(function (t) {
  const n = new Array(1010),
    e = []
  for (let i = 1; i <= 1; ++i) {
    const i = t.readLineAsNumber(),
      o = t.readIntegersOfLine(),
      u = r()
    function r() {
      let t = 0
      for (let r, u = 0; u < i; u += 2) {
        let s = o[u],
          c = o[u]
        for (r = u + 1; r < i; ++r)
          if (1 & r) {
            if (((c -= o[r]), c < s && (s = c <= 0 ? 0 : c), 0 === s)) break
          } else c += o[r]
        ;(n[u] = o[u] - s), (t += n[u]), (e[u] = 0 === s ? r : -1)
      }
      for (let t = 1 & i ? i - 2 : i - 1; t >= 0; t -= 2) {
        let e = o[t],
          r = o[t]
        for (let n = t - 1; n >= 0; --n)
          if (1 & n) r += o[n]
          else if (((r -= o[n]), r < e && (e = r <= 0 ? 0 : r), 0 === e)) break
        n[t] = o[t] - e
      }
      let r = BigInt(t)
      for (let t = 1, u = i - 1; t < u; t += 2) {
        if (n[t] !== o[t]) continue
        let u = e[t + 1],
          s = 0
        for (; -1 != u && ((s += 1), u + 1 !== i); ) u = e[u + 1]
        r += BigInt(s)
      }
      return r
    }
    t.println(u.toString())
  }
})


A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.Ahcl wants to construct a beautiful string. He has a string $$$s$$$, consisting of only characters 'a', 'b', 'c' and '?'. Ahcl needs to replace each character '?' with one of the three characters 'a', 'b' or 'c', such that the resulting string is beautiful. Please help him!More formally, after replacing all characters '?', the condition $$$s_i \neq s_{i+1}$$$ should be satisfied for all $$$1 \leq i \leq |s| - 1$$$, where $$$|s|$$$ is the length of the string $$$s$$$.

The first line contains positive integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Next $$$t$$$ lines contain the descriptions of test cases. Each line contains a non-empty string $$$s$$$ consisting of only characters 'a', 'b', 'c' and '?'.  It is guaranteed that in each test case a string $$$s$$$ has at least one character '?'. The sum of lengths of strings $$$s$$$ in all test cases does not exceed $$$10^5$$$.

For each test case given in the input print the answer in the following format:   If it is impossible to create a beautiful string, print "-1" (without quotes);  Otherwise, print the resulting beautiful string after replacing all '?' characters. If there are multiple answers, you can print any of them.

NoteIn the first test case, all possible correct answers are "ababcb", "abcacb", "abcbcb", "acabcb" and "acbacb". The two answers "abcbab" and "abaabc" are incorrect, because you can replace only '?' characters and the resulting string must be beautiful.In the second test case, it is impossible to create a beautiful string, because the $$$4$$$-th and $$$5$$$-th characters will be always equal.In the third test case, the only answer is "acbac".

var print = this.print || require('lol-io').print;
var write = this.write || require('lol-io').write;
var readline = this.readline || require('lol-io').readline;

var t = Number(readline()), string, array, result = true;

function test (a) {
    result = true;

    for (k = 0; k < a.length - 1; k++) {
        if (a[k] === a[k + 1]) {
            result = false;
        }
    }

    return result;
}

for (i = 0; i < t; i++) {
    string = readline();
    array = string.split('');

    for (j = 0; j < array.length; j++) {

        if (array[j] === '?') {
            if (array[j - 1] != 'a' && array[j + 1] != 'a') {
                array[j] = 'a';
            } else if (array[j - 1] != 'b' && array[j + 1] != 'b') {
                array[j] = 'b';
            } else {
                array[j] = 'c';
            }
        }
    }

    string = array.join('');

    if (test(array)) {
        print(string);
    } else {
        print(-1);
    }
}

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function(input) {
  _input += input;
});

process.stdin.on("end", function() {
  processData(_input);
});

function processData(input) {
  let lines = input.split("\n");

  for (let i = 1; i < lines.length; i++) {
    let word = lines[i].split("");
    for (let j = 0; j < word.length; j++) {
      let possibilities = ["a", "b", "c"];
      if (word[j] === "?") {
        let prevChar = word[j - 1];
        let nextChar = word[j + 1];
        if (prevChar === "a") {
          let index = possibilities.indexOf("a");
          if (index != -1) {
            possibilities.splice(index, 1);
          }
        } else if (prevChar === "b") {
          let index = possibilities.indexOf("b");
          if (index != -1) {
            possibilities.splice(index, 1);
          }
        } else if (prevChar === "c") {
          let index = possibilities.indexOf("c");
          if (index != -1) {
            possibilities.splice(index, 1);
          }
        }
        if (nextChar === "a") {
          let index = possibilities.indexOf("a");
          if (index != -1) {
            possibilities.splice(index, 1);
          }
        } else if (nextChar === "b") {
          let index = possibilities.indexOf("b");
          if (index != -1) {
            possibilities.splice(index, 1);
          }
        } else if (nextChar === "c") {
          let index = possibilities.indexOf("c");
          if (index != -1) {
            possibilities.splice(index, 1);
          }
        }

        if (possibilities[0] !== undefined) {
          word[j] = possibilities[0];
        }
      }
    }
    let ans = true;
    for (let j = 0; j < word.length - 1; j++) {
      // console.log(word[i], word[i - 1], word[i], word[i + 1]);
      if (word[j] === word[j - 1] || word[j] === word[j + 1]) {
        ans = false;
        break;
      }
    }
    if (ans) {
      console.log(word.join(""));
    } else console.log(-1);
  }
}

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const t = parseInt(arr.shift())
  const map = {
    'a': 0,
    'b': 1,
    'c': 2
  }
  const chars = ['a', 'b', 'c']

  for(let j = 0; j < t; j++) {
    const string = arr[j] + 'a'
    const len = string.length - 1
    let s = new Array(len)

    let flag = false
    if(len == 1 && string[0] == '?') {
      s[0] = 'a'
      // console.log(s)
    }
    else if(len == 1) {
      s[0] = string[0]
    }
    else if(string[0] == string[0 + 1] && string[0] != '?') {
      flag = true
    }
    else if(string[0] == '?' && string[1] != '?') {
      s[0] = chars[(map[string[1]] + 1) % 3]
    }
    else if(string[0] == '?' && string[1] == '?') {
      s[0] = 'a'
    }
    else {
      s[0] = string[0]
    }
    for(let i = 1; i < len - 1 && !flag; i++) {
      // console.log(i, s)
      if(string[i] == string[i + 1] && string[i] != '?') {
        flag = true
        break
      }

      if(string[i] != '?') s[i] = string[i]
      else if(string[i] == '?' && string[i + 1] != '?') {
        if(s[i - 1] == string[i + 1]) {
          s[i] = chars[(map[s[i - 1]] + 1) % 3]
        }
        else {
          s[i] = chars[((map[s[i - 1]] + map[string[i + 1]]) * 2) % 3]
        }
      }
      else if(string[i] == '?' && string[i + 1] == '?' && string[i + 2] != '?') {
        if(s[i - 1] == string[i + 2]) {
          let v = map[s[i - 1]]
          s[i] = chars[(v + 1) % 3]
        }
        else {
          s[i] = string[i + 2]
        }
      }
      else {
        s[i] = chars[(map[s[i - 1]] + 1) % 3]
      }
    }

    if(!flag && len > 1) {
      let last = len - 1
      if(string[last] == s[last - 1] && string[last] != '?') {
        flag = true
      }
      else if(string[last] == '?') {
        s[last] = chars[(map[s[last - 1]] + 1) % 3]
      }
      else {
        s[last] = string[last]
      }
    }

    // console.log(s)
    if(flag) console.log(-1)
    else console.log(s.join(''))
  }
})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const t = parseInt(arr.shift())
  const map = {
    'a': 0,
    'b': 1,
    'c': 2
  }
  const chars = ['a', 'b', 'c']

  for(let j = 0; j < t; j++) {
    const string = arr[j]
    const len = string.length
    let s = new Array(len)

    let flag = false
    if(len == 1 && string[0] == '?') {
      s[0] = 'a'
      // console.log(s)
    }
    else if(len == 1) {
      s[0] = string[0]
    }
    else if(string[0] == string[0 + 1] && string[0] != '?') {
      flag = true
    }
    else if(string[0] == '?') {
      s[0] = chars[(map[string[1]] + 1) % 3]
    }
    else {
      s[0] = string[0]
    }
    for(let i = 1; i < len - 1 && !flag; i++) {
      if(string[i] == string[i + 1] && string[i] != '?') {
        flag = true
        break
      }

      if(string[i] != '?') s[i] = string[i]
      else if(string[i] == '?' && string[i + 1] != '?') {
        if(s[i - 1] == string[i + 1]) {
          s[i] = chars[(map[s[i - 1]] + 1) % 3]
        }
        else {
          s[i] = chars[((map[s[i - 1]] + map[string[i + 1]]) * 2) % 3]
        }
      }
      else if(string[i] == '?' && string[i + 1] == '?' && string[i + 2] != '?') {
        if(string[i - 1] == string[i + 2]) {
          let v = map[s[i - 1]]
          s[i] = chars[(v + 1) % 3]
        }
        else {
          s[i] = string[i + 2]
        }
      }
      else {
        s[i] = chars[(map[s[i - 1]] + 1) % 3]
      }
    }

    if(!flag && len > 1) {
      let last = len - 1
      if(string[last] == string[last - 1] && string[last] != '?') {
        flag = true
      }
      else if(string[last] == '?') {
        s[last] = chars[(map[string[1]] + 1) % 3]
      }
      else {
        s[last] = string[last]
      }
    }

    // console.log(s)
    if(flag) console.log(-1)
    else console.log(s.join(''))
  }
})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const t = parseInt(arr.shift())
  const map = {
    'a': 0,
    'b': 1,
    'c': 2
  }
  const chars = ['a', 'b', 'c']

  for(let j = 0; j < t; j++) {
    const string = arr[j]
    const len = string.length
    let s = new Array(len)

    let flag = false

    if(string[0] == string[0 + 1] && string[0] != '?') {
      flag = true
    }
    else if(string[0] == '?') {
      s[0] = chars[(map[string[1]] + 1) % 3]
    }
    else {
      s[0] = string[0]
    }
    for(let i = 1; i < len - 1 && !flag; i++) {
      // console.log(i, string[i], s)
      if(string[i] == string[i + 1] && string[i] != '?') {
        flag = true
        break
      }

      if(string[i] != '?') s[i] = string[i]
      else if(string[i] == '?' && string[i + 1] != '?') {
        if(s[i - 1] == string[i + 1]) {
          s[i] = chars[(map[s[i - 1]] + 1) % 3]
        }
        else {
          s[i] = chars[((map[s[i - 1]] + map[string[i + 1]]) * 2) % 3]
        }
      }
      else if(string[i] == '?' && string[i + 1] == '?' && string[i + 2] != '?') {
        if(string[i - 1] == string[i + 2]) {
          let v = map[s[i - 1]]
          s[i] = chars[(v + 1) % 3]
        }
        else {
          s[i] = string[i + 2]
        }
      }
      else {
        s[i] = chars[(map[s[i - 1]] + 1) % 3]
      }
    }

    if(!flag) {
      let last = len - 1
      if(string[last] == string[last - 1] && string[last] != '?') {
        flag = true
      }
      else if(string[last] == '?') {
        s[last] = chars[(map[string[1]] + 1) % 3]
      }
      else {
        s[last] = string[last]
      }
    }

    if(flag) console.log(-1)
    else console.log(s.join(''))
  }
})

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

var arr = ''
process.stdin.on('data', (i) => {
  arr += i
})

process.stdin.on('end', () => {
  arr = arr.split('\n').map(a => a.replace(/(\r\n|\n|\r)/gm, ''))

  const t = parseInt(arr.shift())
  const map = {
    'a': 0,
    'b': 1,
    'c': 2
  }
  const chars = ['a', 'b', 'c']

  for(let j = 0; j < t; j++) {
    const string = arr[j]
    const len = string.length
    let s = new Array(len)

    let flag = false
    if(len == 1 && string[0] != '?') {
      s[0] = 'a'
    }
    else if(len == 1) {
      s[0] = string[0]
    }
    else if(string[0] == string[0 + 1] && string[0] != '?') {
      flag = true
    }
    else if(string[0] == '?') {
      s[0] = chars[(map[string[1]] + 1) % 3]
    }
    else {
      s[0] = string[0]
    }
    for(let i = 1; i < len - 1 && !flag; i++) {
      // console.log(i, string[i], s)
      if(string[i] == string[i + 1] && string[i] != '?') {
        flag = true
        break
      }

      if(string[i] != '?') s[i] = string[i]
      else if(string[i] == '?' && string[i + 1] != '?') {
        if(s[i - 1] == string[i + 1]) {
          s[i] = chars[(map[s[i - 1]] + 1) % 3]
        }
        else {
          s[i] = chars[((map[s[i - 1]] + map[string[i + 1]]) * 2) % 3]
        }
      }
      else if(string[i] == '?' && string[i + 1] == '?' && string[i + 2] != '?') {
        if(string[i - 1] == string[i + 2]) {
          let v = map[s[i - 1]]
          s[i] = chars[(v + 1) % 3]
        }
        else {
          s[i] = string[i + 2]
        }
      }
      else {
        s[i] = chars[(map[s[i - 1]] + 1) % 3]
      }
    }

    if(!flag) {
      let last = len - 1
      if(string[last] == string[last - 1] && string[last] != '?') {
        flag = true
      }
      else if(string[last] == '?') {
        s[last] = chars[(map[string[1]] + 1) % 3]
      }
      else {
        s[last] = string[last]
      }
    }

    if(flag) console.log(-1)
    else console.log(s.join(''))
  }
})


Timur has a stairway with $$$n$$$ steps. The $$$i$$$-th step is $$$a_i$$$ meters higher than its predecessor. The first step is $$$a_1$$$ meters higher than the ground, and the ground starts at $$$0$$$ meters.   The stairs for the first test case. Timur has $$$q$$$ questions, each denoted by an integer $$$k_1, \dots, k_q$$$. For each question $$$k_i$$$, you have to print the maximum possible height Timur can achieve by climbing the steps if his legs are of length $$$k_i$$$. Timur can only climb the $$$j$$$-th step if his legs are of length at least $$$a_j$$$. In other words, $$$k_i \geq a_j$$$ for each step $$$j$$$ climbed.Note that you should answer each question independently.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains two integers $$$n, q$$$ ($$$1 \leq n, q \leq 2\cdot10^5$$$) — the number of steps and the number of questions, respectively. The second line of each test case contains $$$n$$$ integers ($$$1 \leq a_i \leq 10^9$$$) — the height of the steps. The third line of each test case contains $$$q$$$ integers ($$$0 \leq k_i \leq 10^9$$$) — the numbers for each question. It is guaranteed that the sum of $$$n$$$ does not exceed $$$2\cdot10^5$$$, and the sum of $$$q$$$ does not exceed $$$2\cdot10^5$$$.

For each test case, output a single line containing $$$q$$$ integers, the answer for each question. Please note, that the answer for some questions won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

NoteConsider the first test case, pictured in the statement.   If Timur's legs have length $$$1$$$, then he can only climb stair $$$1$$$, so the highest he can reach is $$$1$$$ meter.  If Timur's legs have length $$$2$$$ or $$$4$$$, then he can only climb stairs $$$1$$$, $$$2$$$, and $$$3$$$, so the highest he can reach is $$$1+2+1=4$$$ meters.  If Timur's legs have length $$$9$$$ or $$$10$$$, then he can climb the whole staircase, so the highest he can reach is $$$1+2+1+5=9$$$ meters.  In the first question of the second test case, Timur has no legs, so he cannot go up even a single step. :(

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

//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;}

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


There are one cat, $$$k$$$ mice, and one hole on a coordinate line. The cat is located at the point $$$0$$$, the hole is located at the point $$$n$$$. All mice are located between the cat and the hole: the $$$i$$$-th mouse is located at the point $$$x_i$$$ ($$$0 < x_i < n$$$). At each point, many mice can be located.In one second, the following happens. First, exactly one mouse moves to the right by $$$1$$$. If the mouse reaches the hole, it hides (i.e. the mouse will not any more move to any point and will not be eaten by the cat). Then (after that the mouse has finished its move) the cat moves to the right by $$$1$$$. If at the new cat's position, some mice are located, the cat eats them (they will not be able to move after that). The actions are performed until any mouse hasn't been hidden or isn't eaten.In other words, the first move is made by a mouse. If the mouse has reached the hole, it's saved. Then the cat makes a move. The cat eats the mice located at the pointed the cat has reached (if the cat has reached the hole, it eats nobody).Each second, you can select a mouse that will make a move. What is the maximum number of mice that can reach the hole without being eaten?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of two lines. The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le k \le 4 \cdot 10^5$$$). The second line contains $$$k$$$ integers $$$x_1, x_2, \dots x_k$$$ ($$$1 \le x_i < n$$$) — the initial coordinates of the mice. It is guaranteed that the sum of all $$$k$$$ given in the input doesn't exceed $$$4 \cdot 10^5$$$.

For each test case output on a separate line an integer $$$m$$$ ($$$m \ge 0$$$) — the maximum number of mice that can reach the hole without being eaten.

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

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

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

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