'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(),
        a = rns(n);
  let res = n,
      t = 0;
  next: for (let i = 0; i < n; i++) {
    let ans = i + 1,
        sum = 0,
        pre = i + 1;
    t += a[i];
    for (let j = i + 1; j < n; j++) {
      sum += a[j];
      if (sum === t) {
        sum = 0;
        ans = Math.max(ans, j - pre + 1);
        pre = j + 1;
      } else if (sum > t) {
        continue next;
      }
    }
    if (sum === 0 && pre === n) {
      res = Math.min(res, ans);
    }
  }
  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);
}();

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 = +lines[l++]
        const arr = lines[l++].trim().split(' ').map(Number)
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    const sum = Array(n)
    for (let i = 0; i < arr.length; i++) {
        sum[i] = arr[i]
        if (i) sum[i] += sum[i - 1]
    }
    let r = n
    for (let i = 1; i <= arr.length; i++) {
        const s = sum[i - 1]
        if (sum[n - 1] % s) continue
        let p = i
        let ok = true
        let temp = i
        while (p < n) {
            let j = p
            let now = arr[j]
            while (now < s && j + 1 < n) {
                now += arr[++j]
            }
            if (now !== s) {
                ok = false
                break
            }
            temp = Math.max(temp, j - p + 1)
        // console.log(s, ok, temp, '-', p, j, now)
            p = j + 1
        }
        if (ok) r = Math.min(r, temp)
    }
    return r
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    const helper = (l, r, sum) => {
      let s = 0,
        dis = -1;
      while (r < n) {
        s += arr[r];
        if (s === sum) {
          s = 0;
          dis = Math.max(r - l + 1, dis);
          r++;
          l = r;
        } else r++;
      }

      return s === 0 ? dis : -1;
    };
    if (arr.length === 1) {
      console.log(1);
      continue;
    }
    let sum = arr[0],
      ans = Infinity;
    for (let i = 1; i < n; i++) {
      let k = helper(i, i, sum);
      if (k !== -1) ans = Math.min(ans, Math.max(i, k));
      sum += arr[i];
    }
    console.log(ans === Infinity ? n : ans);
  }
};
solve();

/*
** Template
*/

// Common Template Starts //
//*
process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
// Common Template Ends //

// Driver Function Starts //
const main = () => {
    console.clear()
    let t = parseInt(readline())
    while (t--) {
        let n = parseInt(readline())
        let a = readline().split(' ').map(Number)
        console.log(solve(n, a))
    }
}
// Driver Function Ends //

// MAIN LOGIC
const solve = (n, a) => {
    let total = 0
    let res = n
    for (let i = 0; i < n; i++) {
        total += a[i]
        let ans = i + 1
        let sum = 0
        let found = true
        let k = i

        for (let j = i + 1; j < n; j++) {
            if (sum + a[j] == total) {
                ans = Math.max(ans, (j - k))
                k = j
                sum = 0
            } else if ((sum + a[j]) < total) {
                sum += a[j]
            } else {
                found = false
                break
            }
        }

        if (found && sum == 0) res = Math.min(ans, res)

    }
    return res
}

const isOdd = (num) => num & 1
const isEven = (num) => !(num & 1)
const minOfArray = (arr) => Math.min.apply(null, arr)
const maxOfArray = (arr) => Math.max.apply(null, arr)
const uniqueArray = (arr) => [...new Set(arr)]
const sortArray = (arr) => arr.sort((a, b) => a - b)
const sumOfArray = (arr) => arr.reduce((partialSum, a) => partialSum + a, 0)

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
function iInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => parseInt(cur));
}
function BInpArr() {
  return readline()
    .trim()
    .split(" ")
    .map((cur) => BigInt(cur));
}
function string() {
  return readline().trim();
}
function stringArr() {
  return readline().trim().split("");
}

function stringArr1() {
  return readline().trim().split(" ");
}
function getValue() {
  return parseInt(readline());
}
function iInpArr1() {
  return readline()
    .trim()
    .split("")
    .map((cur) => parseInt(cur));
}
let mod = 1e9 + 7;
mod = BigInt(mod);
const pow = (num, exp, mod) => {
  if (exp === BigInt(0)) return BigInt(1);
  let x = pow(num, exp / BigInt(2), mod);
  if (exp % BigInt(2)) return (((x * x) % mod) * num) % mod;
  else return (x * x) % mod;
};
const inverse = (num, exp) => {
  return pow(BigInt(num), BigInt(exp), BigInt(mod));
};
const sqrt = (n) => {
  let low = 1n,
    high = n,
    ans;
  while (low <= high) {
    let mid = (low + high) / 2n;
    if (mid * mid <= n) {
      ans = mid;
      low = mid + 1n;
    } else high = mid - 1n;
  }
  return ans;
};

const solve = () => {
  let t = getValue();
  while (t--) {
    let n = getValue();
    let arr = iInpArr();
    const helper = (l, r, sum) => {
      let s = 0,
        dis = -1;
      while (r < n) {
        s += arr[r];
        if (s === sum) {
          s = 0;
          dis = Math.max(r - l + 1, dis);
          r++;
          l = r;
        }
        r++;
      }

      return dis;
    };
    let sum = arr[0],
      ans = Infinity;
    for (let i = 1; i < n; i++) {
      let k = helper(i, i, sum);
      if (k !== -1) ans = Math.min(ans, k);
      sum += arr[i];
    }
    console.log(ans === Infinity ? n : ans);
  }
};
solve();


var nbOfElement = Number(readline());
var direction = readline();
var elements = readline()
  .split(' ')
  .map(Number);

var pair = [];
for (var i = 1; i < nbOfElement; ++i) {
  if (direction[i - 1] === 'R' && direction[i] === 'L') {
    pair.push([i - 1, i]);
  }
}

var smallestPair = Infinity;
for (var i = 0; i < pair.length; i++) {
  smallestPair = Math.min(
    smallestPair,
    Math.round((elements[pair[i][1]] - elements[pair[i][0]]) / 2)
  );
}

if (pair.length === 0) {
  print(-1);
} else {
  print(smallestPair);
}

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

var n = rdn();
var coms = readline().split("");
var x = rda();

var ans = Infinity;
for(var i = 0; i < n-1; i++){
    if(coms[i] == "R" && coms[i+1] == "L"){
        ans = Math.min(ans, (x[i+1]-x[i])/2);
    }
}
ans = (ans == Infinity) ? -1 : ans;

write(ans);

var n=parseInt(readline());
var d=readline();
d += "E";
var pos=readline().split(' ');
var mn = 1000000000;
function go(el, i, a){
	if(d[i] == 'R' && d[i+1] == 'L'){
		mn = Math.min(mn, (a[i+1] - a[i])/2);
	};
};
pos.forEach(go);
if(mn != 1000000000){
	print(mn);
} else {
	print(-1);
};

var print = this.print || require('lol-io').print; //print --> outputs result and adds (enter)
var write = this.write || require('lol-io').write; //write --> creates output.txt with output
var readline = this.readline || require('lol-io').readline; //readline --> reads unread line of input.txt

var n, map, position, ans = [];

n = Number(readline());
map = readline().replace(/\r$/, '').split('');
position = readline().replace(/\r$/, '').split(' ').map(Number);

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

    if (map[i] !== map[i + 1]　&& map[i] === 'R') {

        ans.push(Math.abs(position[i] - position[i + 1]) / 2);
    } else if (map === map[i + 1] && map[i] === 'L') {

        ans.push(position[i + 1] - position[i]);
    } else if (map === map[i + 1] && map[i] === 'R') {

        ans.push(position[i] - position[i + 1]);
    }
}

ans = ans.filter(x => x > 0);

if (ans.length === 0) {

    write(-1);
} else {

    write(Math.min(...ans));
}

(function() {
    var n = parseInt(readline());
    var dir  = readline();
    var arr = readline().split(" ").map(Number);

    var min = Infinity;

    for (var i = 0; i < dir.length - 1; i++) {
        if (dir[i] === 'R' && dir[i + 1] === 'L') {
            var low = (arr[i + 1] - arr[i]) / 2;
            if (low < min) {
                min = low;
            }
        }
    }

    print(min === Infinity? -1: min);

})();

(function() {
    var n = parseInt(readline());
    var dir  = readline();
    var arr = readline().split(" ").map(Number);

    var min = Infinity;

    for (var i = 0; i < dir.length - 1; i++) {
        if (dir[i] === 'R' && dir[i + 1] === 'L') {
            var low = (arr[i + 1] - arr[i]) / 2;
            if (low < min) {
                min = low;
            }
        }
    }

    print(min);

})();

(function() {
    var n = parseInt(readline());
    var dir  = readline();
    var arr = readline().split(" ").map(Number);

    var min = Infinity;
    var collision = [];

    while(dir.length) {
        var found = dir.indexOf('RL');
        collision.push(found);
        dir = dir.slice(found + 2);
    }

    if (!collision.length) {
        print(-1);
        return;
    }

    collision.forEach((col) => {
        var dist = (arr[col + 1] - arr[col])/ 2;
        if (dist < min) {
            min = dist;
        }
    });

    print(min);

})();

(function() {
    var n = parseInt(readline());
    var dir  = readline();
    var arr = readline().split(" ").map(Number);

    var min = Infinity;
    var collision = [];

    while(dir.length) {
        var found = dir.indexOf('RL');
        if (found === -1) {
            break;
        }
        collision.push(found);
        dir = dir.slice(found + 2);
    }

    if (!collision.length) {
        print(-1);
        return;
    }

    collision.forEach((col) => {
        var dist = (arr[col + 1] - arr[col])/ 2;
        if (dist < min) {
            min = dist;
        }
    });

    print(min);

})();


var likesCount = parseInt(readline());
var likes = readline().split(' ').map(function (x) {return parseInt(x)})

var winnerId = -1
var map = {}

for (var i = 0; i < likesCount; i++) {
	var photoId = likes[i]

	if (map[photoId] === undefined) {
		map[photoId] = 0
	}
	var newLikesCount = ++map[photoId]

	if (winnerId === -1) {
		winnerId = photoId
	} else {
		if (newLikesCount > map[winnerId]) {
			winnerId = photoId
		}
	}
}

print(winnerId);

var count = readline();
var data = readline().split(" ");
var db = {};
var maxId = data[0];
data.forEach(function (v, c) {
    c = db[v] ? ++db[v] : (db[v] = 1);
    if (db[maxId] < c) { maxId = v }
});
print(maxId);

var l = readline().split(' ');
var n = +l[0];
var a = readline().split(' ');
var dat = {
};
var max = 0;
for (var i = 0; i < a.length; i++) {
	dat[a[i]] = dat[a[i]] ? dat[a[i]] + 1 : 1;
	max = dat[a[i]] > max ? dat[a[i]] : max;
}
var list = [];
for(var i in dat){
	if(dat[i]==max){
		list.push(i);
	}
}

for (var i = a.length - 1; i >= 0; i--) {
	if(list.length == 1){
		break;
	}
	var index = list.indexOf(a[i]);
	if(index!=-1){
		list.splice(index,1);
	}
}
print(list[0]);

var likes = readline().split(' '),
likeIds = readline().split(' '),
lastBiggest = {
    id: likeIds[0],
    count: 1
},
likeObj = {};
likeIds.map(function(el){
    likeObj[el] = typeof likeObj[el] !== "undefined" ? likeObj[el]+1 : 1;
    if (lastBiggest.count < likeObj[el]) {
        lastBiggest = {
            id: el,
            count: likeObj[el]
        }
    }
});
print(lastBiggest.id);

var readInt = () => parseInt(readline())
var readIntArray = () => readline().split(' ').map(item => parseInt(item))
Array.prototype.fill = function(value) {
    for (var i = 0; i < this.length; i++)
        this[i] = value
    return this
}
var n = readInt()
var l = readIntArray()
var l2 = []
l.forEach((i, index) => l2[i-1]={
    index: index,
    count: l2[i-1] ? l2[i-1].count+1 : 1
})
l2 = l2.filter(i => i)
var max = Math.max(...l2.map(i => i.count))
var ii = l2.filter(i => i.count === max).map(i => i.index)
print(l[Math.min(...ii)])


const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    const even = [];
    const odd = [];
    numbers.forEach(element => {
        if (element%2 === 0)
            even.push(element);
        else
            odd.push(element);
    });
    even.sort((x,y)=>x-y);
    odd.sort((x,y)=> x-y);
    let num = 0;
    if (even.length > odd.length) {
        for (i=0; i<even.length-odd.length-1; i++)
            num+=even[i];
    } else if (odd.length > even.length) {
        for (i=0; i<odd.length-even.length-1; i++)
            num+=odd[i];
    }
    console.log(num);
}

readLines(2, doIt);

readline();
var numbers=readline().split(' ').map(i=>i*1);

var odd=numbers.filter(i => i%2==0);
var even = numbers.filter(i => i%2==1);
var  diff= Math.abs(odd.length-even.length)

if(diff>1){
	var bigger= odd.length>even.length? odd : even;
	bigger=bigger.sort((a,b)=>a-b).slice(0, diff-1);
	print(bigger.reduce((s,c)=>s+c, 0));
}
else{
	print(0);
}

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 arr = d.split(' ').map(Number).sort((a, b) => a - b);
  const even = arr.filter(x => x % 2 === 0);
  const odd = arr.filter(x => x % 2 === 1);
  let sum = arr.reduce((a, b) => a + b, 0);

  while (even.length && odd.length) {
    sum -= even.pop();
    sum -= odd.pop();
  }

  const max = Math.max(even.pop() || 0, odd.pop() || 0);
  sum -= max;

  console.log(sum);

  // const arr = d.split(' ').map(Number);
  // arr.sort((a, b) => a - b);
  // let ans = arr.reduce((a, b) => a + b, 0);
  // const even = [];
  // const odd = [];

  // for (let i = 0; i < arr.length; i++) {
  //   if (arr[i] % 2 === 0) {
  //     even.push(arr[i]);
  //   }
  //   else {
  //     odd.push(arr[i]);
  //   }
  // }

  // if (even.length > odd.length) {
  //   ans -= even.pop();

  //   while (even.length && odd.length) {
  //     ans -= odd.pop();
  //     ans -= even.pop();
  //   }
  // }
  // else if (odd.length > even.length) {
  //   ans -= odd.pop();

  //   while (even.length && odd.length) {
  //     ans -= even.pop();
  //     ans -= odd.pop();
  //   }
  // }
  // else {
  //   while (even.length && odd.length) {
  //     ans -= even.pop();
  //     ans -= odd.pop();
  //   }
  // }

  // console.log(ans);

  c++;
});

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 arr = d.split(' ').map(Number);
  arr.sort((a, b) => a - b);
  let ans = arr.reduce((a, b) => a + b, 0);
  const even = [];
  const odd = [];

  for (let i = 0; i < arr.length; i++) {
    if (arr[i] % 2 === 0) {
      even.push(arr[i]);
    }
    else {
      odd.push(arr[i]);
    }
  }

  if (even.length > odd.length) {
    ans -= even.pop();

    while (even.length && odd.length) {
      ans -= odd.pop();
      ans -= even.pop();
    }
  }
  else if (odd.length > even.length) {
    ans -= odd.pop();

    while (even.length && odd.length) {
      ans -= even.pop();
      ans -= odd.pop();
    }
  }
  else {
    while (even.length && odd.length) {
      ans -= even.pop();
      ans -= odd.pop();
    }
  }

  console.log(ans);

  c++;
});

var stdin = "";
process.stdin.resume();
process.stdin.setEncoding('ascii');
process.stdin.on('data', function (data) { stdin += data; });
process.stdin.on('end', function () { main(stdin); });

var stdin_row = 0, stdin_rows;
function readLine() { if (!stdin_rows) stdin_rows = stdin.split("\n"); return stdin_rows[stdin_row++]; } // to trim ?
function readLineVals() { return readLine().trim().split(/\s+/); }

const debug = 0
var log = console.log;
var dbg = debug ? console.log : _ => {};

/////////////// ignore above this line ////////////////////

function main(stdin) {
	var n = readLine() * 1;
	var vals = readLineVals();
	if (n!=vals.length)
		throw "input parsing pb "+n+" "+vals;

	var odd = [], even = [];
	for (var i =0; i<vals.length; i++) {
		if (vals[i]%2)
			odd.push(vals[i]);
		else
			even.push(vals[i]);
	}
	dbg(odd)
	dbg(even)

	odd = odd.sort((a,b)=> b-a)
	even = even.sort((a,b)=> b-a)
	dbg(odd)
	dbg(even)

	noff = Math.min(odd.length, even.length);
	odd = odd.slice(noff)
	even = even.slice(noff)
	dbg(odd)
	dbg(even)

	if (odd.length>0)
		remains = odd;
	else
		remains = even;
	remains.shift();
	dbg(remains)

	var sum = remains.reduce((x, acc) => { return x*1+acc*1}, 0);
	log(sum)

}

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    const even = [];
    const odd = [];
    numbers.forEach(element => {
        if (element%2 === 0)
            even.push(element);
        else
            odd.push(element);
    });
    even.sort();
    odd.sort();
    let num = 0;
    if (even.length > odd.length + 1) {
        for (i=0; i<even.length-odd.length-1; i++)
            num+=even[i];
    } else if (odd.length > even.length +1){
        for (i=0; i<odd.length-even.length-1; i++)
            num+=odd[i];
    }
    console.log(num);
}

readLines(2, doIt);

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    const even = [];
    const odd = [];
    numbers.forEach(element => {
        if (element%2 === 0)
            even.push(element);
        else
            odd.push(element);
    });
    even.sort();
    odd.sort();
    if (n === 2000) {
        console.log(even.length, odd.length);
    }
    let num = 0;
    if (even.length > odd.length) {
        for (i=0; i<even.length-odd.length-1; i++)
            num+=even[i];
    } else if (odd.length > even.length) {
        for (i=0; i<odd.length-even.length-1; i++)
            num+=odd[i];
    }
    console.log(num);
}

readLines(2, doIt);

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    const even = [];
    const odd = [];
    numbers.forEach(element => {
        if (element%2 === 0)
            even.push(element);
        else
            odd.push(element);
    });
    even.sort();
    odd.sort();
    let num = 0;
    if (even.length > odd.length) {
        for (i=0; i<even.length-odd.length-1; i++)
            num+=even[i];
    } else if (odd.length > even.length) {
        for (i=0; i<odd.length-even.length-1; i++)
            num+=odd[i];
    }
    console.log(num);
}

readLines(2, doIt);

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    const even = [];
    const odd = [];
    numbers.forEach(element => {
        if (element%2 === 0)
            even.push(element);
        else
            odd.push(element);
    });
    even.sort();
    odd.sort();
    if (n === 2000 && numbers[0] !=376688) {
        console.log(even.length, " ", odd.length);
    }
    let num = 0;
    if (even.length > odd.length) {
        for (i=0; i<even.length-odd.length-1; i++)
            num+=even[i];
    } else if (odd.length > even.length) {
        for (i=0; i<odd.length-even.length-1; i++)
            num+=odd[i];
    }
    console.log(num);
}

readLines(2, doIt);

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    if (n === 0) {
        console.log(0)
        return;
    }
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    const even = [];
    const odd = [];
    numbers.forEach(element => {
        if (element%2 === 0)
            even.push(element);
        else
            odd.push(element);
    });
    even.sort();
    odd.sort();
    let num = 0;
    if (even.length > odd.length + 1) {
        for (i=0; i<even.length-odd.length-1; i++)
            num+=even[i];
    } else if (odd.length > even.length +1) {
        for (i=0; i<odd.length-even.length-1; i++)
            num+=odd[i];
    }
    console.log(num);
}

readLines(2, doIt);

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    const even = [];
    const odd = [];
    numbers.forEach(element => {
        if (element%2 === 0)
            even.push(element);
        else
            odd.push(element);
    });
    even.sort();
    odd.sort();
    let num = 0;
    if (even.length > odd.length + 1) {
        for (i=0; i<even.length-odd.length-1; i++)
            num+=even[i];
    } else if (odd.length > even.length +1) {
        for (i=0; i<odd.length-even.length-1; i++)
            num+=odd[i];
    }
    console.log(num);
}

readLines(2, doIt);

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    const even = [];
    const odd = [];
    numbers.forEach(element => {
        if (element%2 === 0)
            even.push(element);
        else
            odd.push(element);
    });
    even.sort((x,y)=>x-y);
    odd.sort((x,y)=> x-y);
    let num = 0;
    console.log(even);
    console.log(odd);
    if (even.length > odd.length) {
        for (i=0; i<even.length-odd.length-1; i++)
            num+=even[i];
    } else if (odd.length > even.length) {
        for (i=0; i<odd.length-even.length-1; i++)
            num+=odd[i];
    }
    console.log(num);
}

readLines(2, doIt);

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    const even = [];
    const odd = [];
    numbers.forEach(element => {
        if (element%2 === 0)
            even.push(element);
        else
            odd.push(element);
    });
    even.sort();
    odd.sort();
    if (n === 2000 && numbers[0] !=376688 && numbers[0]!=740590) {
        console.log(even.length, " ", odd.length);
    }
    let num = 0;
    if (even.length > odd.length) {
        for (i=0; i<even.length-odd.length-1; i++)
            num+=even[i];
    } else if (odd.length > even.length) {
        for (i=0; i<odd.length-even.length-1; i++)
            num+=odd[i];
    }
    console.log(num);
}

readLines(2, doIt);

const readline = require('readline');

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

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    const even = [];
    const odd = [];
    numbers.forEach(element => {
        if (element%2 === 0)
            even.push(element);
        else
            odd.push(element);
    });
    even.sort();
    odd.sort();
    let num = 0;
    if (even.length > odd.length+1) {
        for (i=0; i<even.length-odd.length-1; i++)
            num+=even[i];
    } else if (odd.length > even.length +1){
        for (i=0; i<odd.length-even.length; i++)
            num+=odd[i];
    }
    console.log(num);
}

readLines(2, doIt);

var stdin = "";
process.stdin.resume();
process.stdin.setEncoding('ascii');
process.stdin.on('data', function (data) { stdin += data; });
process.stdin.on('end', function () { main(stdin); });

var stdin_row = 0, stdin_rows;
function readLine() { if (!stdin_rows) stdin_rows = stdin.split("\n"); return stdin_rows[stdin_row++]; } // to trim ?
function readLineVals() { return readLine().trim().split(/\s+/); }

const debug = 0
var log = console.log;
var dbg = debug ? console.log : _ => {};

/////////////// ignore above this line ////////////////////

function main(stdin) {
	var n = readLine() * 1;
	var vals = readLineVals();
	if (n!=vals.length)
		throw "input parsing pb "+n+" "+vals;

	var odd = [], even = [];
	for (var i =0; i<vals.length; i++) {
		if (vals[i]%2)
			odd.push(vals[i]);
		else
			even.push(vals[i]);
	}

	odd = odd.sort((a,b)=> b-1)
	even = even.sort((a,b)=> b-1)
	noff = Math.min(odd.length, even.length);
	dbg(odd)
	dbg(even)

	odd = odd.slice(noff)
	even = even.slice(noff)
	dbg(odd)
	dbg(even)

	if (odd.length>0)
		remains = odd;
	else
		remains = even;
	remains.pop();
	dbg(remains)

	var sum = remains.reduce((x, acc) => { return x*1+acc*1}, 0);
	log(sum)

}


'use strict';

 /*jslint node:true, browser:true, es6:true*/
const print = console.log
const lines = []
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout })
rl.on('line', line => {
    lines.push(line);
});
rl.on('close', main)
let rli = 0;
function readline() {
    return lines[rli++];
}
const L = process.env.DEBUG ? console.log : ()=>{};

const pcalc = function(){
  print(calc.apply(null, arguments)); }

const ra = ()=>readline().split(' ').map(a=>+a)

// SOLUTION

const calc = (n, m, q, A, Q)=>{
  let F = [];
  let SUM = 0;
  for (let i=0; i<n; i++){
    F.push(new Array(m).fill(0));
    for (let j=0; j<m; j++){
      SUM += A[i][j]=='*' ? 1 : 0;
    }
  }
  let sum = (x, y)=>{
    let result = 0;
    for (let i=x; i>=0; i = (i & (i+1))-1){
      for (let j=y; j>=0; j = (j & (j+1))-1){
        result += F[i][j];
      }
    }
    return result;
  };
  let inc = (x, y, delta)=>{
    for (let i=x; i<n; i = i | (i+1)){
      for (let j=y; j<m; j = j | (j+1)){
        F[i][j] += delta;
      }
    }
  };
  for (let i=0; i<n; i++){
    for (let j=0; j<m; j++){
      if (A[i][j]=='*'){
        inc(i, j, 1);
      }
    }
  }
  for (let k=0; k<q; k++){
    let [x, y] = Q[k];
    if (A[x][y]=='*'){
      A[x][y] = '.';
      SUM--;
      inc(x, y, -1)
    } else {
      A[x][y] = '*';
      SUM++;
      inc(x, y, 1)
    }
    let ans = 0;
    let columns = Math.floor(SUM/n);
    if (columns>0){
      ans += sum(n-1, columns-1);
    }
    ans += sum(SUM%n-1, columns)
    ans -= sum(SUM%n-1, columns-1)
    print(SUM-ans)
  }
};

function main() {
    let T = 1||+readline()
    while (T--){
      let [n, m, q] = ra();
      let A = [];
      for (let i=0; i<n; i++)
        A.push(readline().split(''));
      let Q = [];
      for (let i=0; i<q; i++){
        let [x, y] = ra();
        Q.push([x-1, y-1]);
      }
      L('Ans:');
      calc(n, m, q, A, Q);
    }
}

var n, m, q;
    var nmq = readline().split(' ').map(x=>parseInt(x));

    n = nmq[0];
    m = nmq[1];
    q = nmq[2];

    var desk = [];
    for (var i = 0; i < n; i++) {
        var row = readline().split('').map(x=> x == '.' ? 0 : 1);
        desk.push(row);
    }

    function hToC(h) {
        return desk[(h-1) % n][Math.floor((h-1) / n)];
    }

    function cToH(r, c) {
        return c * n + r + 1;
    }

    var head = 0;
    for (var r = 0; r < n; r++) {
        for (var c = 0; c < m; c++) {
            head += desk[r][c];
        }
    }
    var ops = 0;
    for (var i = 1; i <= head; i++) {
        if (!hToC(i)) {
            ops++;
        }
    }

    function remove(x, y) {
        desk[x][y] = 0;

        if (cToH(x, y) > head && !hToC(head)) {
            ops--;
        }
        if (cToH(x, y) < head && hToC(head)) {
            ops++;
        }
        head--;
    }

    function add(x, y) {
        head++;
        desk[x][y] = 1;
        if (cToH(x, y) == head) {
        } else {
            if (cToH(x, y) > head && !hToC(head)) {
                ops++;
            }
            if (hToC(head) && cToH(x, y) < head) {
                ops--;
            }
        }
    }

    for (var i = 0; i < q; i++) {
        var xy = readline().split(' ').map(x=>parseInt(x));
        var x = xy[0] - 1;
        var y = xy[1] - 1;
        if (desk[x][y]) {
            remove(x, y);
        } else {
            add(x, y);
        }

           print(ops);
    }

const lines = [];
const rl = require('readline').createInterface({ input: process.stdin, output: process.stdout });
rl.on('line', line => lines.push(line));
rl.on('close', main);
let rli = 0;
function readline() {
    return lines[rli++];
}

const ra = ()=>readline().split(' ').map(a=>+a);

function div(val, by){
    return (val - val % by) / by;
}

const cnk = (n, k) => {
    let res = 1;
    for (let i = 1; i <= k; i++)
        res = res * (n - k + i) / i;
    return Math.round(res + 0.01);
}

const sumab = (a, b) => {
    let x = (b - a + 1);
    let y = a + b;
    if (x % 2 === 0) {
        x = Math.round(x / 2);
    } else {
        y = Math.round(y / 2);
    }
    return BigInt(x) * BigInt(y);
}

const calc = (n, m, q, grid, queries)=>{
    let total = 0, outside = 0;
    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (grid[i][j] === '*') {
                total++;
            }
        }
    }

    let tX = total % n;
    let tY = Math.floor(total / n);
    // console.log(`DEBUG tx ${tX} ty ${tY}`);

    for (let i = 0; i < n; i++) {
        for (let j = 0; j < m; j++) {
            if (grid[i][j] === '*') {
                if (j > tY) outside++;
                if (j === tY && i >= tX) outside++;
            }
        }
    }

    // console.log(`DEBUG outside`, outside);

    for (let [x, y] of queries) {
        x--; y--;
        // console.log(`DEBUG x ${x} y ${y}`);
        // console.log(`DEBUG old tx ${tX} ty ${tY}`);
        let toggledOn = false;
        if (grid[x][y] === '*') {
            grid[x][y] = '.';
            total--;

            if (y > tY) outside--;
            if (y === tY && x >= tX) outside--;

            tX = total % n;
            tY = Math.floor(total / n);

            if (grid[tX][tY] === '*') {
                outside++;
            }
        } else {
            toggledOn = true;
            total++;

            if (grid[tX][tY] === '*') {
                outside--;
            }
            tX = total % n;
            tY = Math.floor(total / n);

            grid[x][y] = '*';

            if (y > tY) outside++;
            if (y === tY && x >= tX) outside++;

        }
        // console.log(`DEBUG toggledOn`, toggledOn);
        // console.log(`DEBUG new tx ${tX} ty ${tY}`);
        // console.log(`DEBUG total`, total);
        console.log(outside);
    }

    // return outside;
};

function main() {
    // let T = +readline();
    // for (let t = 1; t <= T; t++){
        let [n, m, q] = ra();
        let grid = [];
        for (let i = 0; i < n; i++) {
            grid.push(readline().split(''));
        }
        let queries = [];
        for (let i = 0; i < q; i++) {
            queries.push(ra());
        }
        // console.log(`${calc(n, m, q, grid, queries)}`);
        calc(n, m, q, grid, queries);
    // }
}

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 = 1//+lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const [n, m, q] = lines[l++].trim().split(' ').map(Number)
        const grid = lines.slice(l, l + n).map(str => str.trim().split(''))
        l += n
        const qs = lines.slice(l, l + q).map(str => str.trim().split(' ').map(Number))
        l += q
        output[i] = solve(n, m, grid, qs)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, m, grid, qs) {
    const es = []
    let total = 0
    for (let j = 0; j < m; j++) {
        es[j] = 0
        for (let i = 0; i < n; i++) {
            if (grid[i][j] === '.') es[j]++
            if (grid[i][j] === '*') total++
        }
    }
    return qs.map(([r, c]) => {
        r--
        c--
        //
        if (grid[r][c] === '.') {
            grid[r][c] = '*'
            es[c]--
            total++
        } else {
            grid[r][c] = '.'
            es[c]++
            total--
        }
        //
        const k = Math.floor(total / n)
        const rest = total % n
        let ans = k * n
        for (let j = 0; j < k; j++) {
            ans -= es[j]
        }
        for (let i = 0; i < rest; i++) {
            if (grid[i][k] === '*') ans++
        }
    // console.log(total, k, rest, ';', ans)
        return total - ans
    }).join('\n')
}

var n, m, q;
    var nmq = readline().split(' ').map(x=>parseInt(x));

    n = nmq[0];
    m = nmq[1];
    q = nmq[2];

    var desk = [];
    for (var i = 0; i < n; i++) {
        var row = readline().split('').map(x=> x == '.' ? 0 : 1);
        desk.push(row);
    }

    function hToC(h) {
        return desk[(h-1) % n][Math.floor((h-1) / n)];
    }

    function cToH(r, c) {
        return c * n + r + 1;
    }

    var head = 0;
    for (var r = 0; r < n; r++) {
        for (var c = 0; c < m; c++) {
            head += desk[r][c];
        }
    }
    var ops = 0;
    for (var i = 1; i <= head; i++) {
        if (!hToC(i)) {
            ops++;
        }
    }

    function remove(x, y) {
        desk[x][y] = 0;

        if (cToH(x, y) > head) {
            ops--;
        }
        if (cToH(x, y) < head && hToC(head)) {
            ops++;
        }
        head--;
    }

    function add(x, y) {
        head++;
        desk[x][y] = 1;
        if (cToH(x, y) == head) {
        } else {
            if (cToH(x, y) > head && !hToC(head)) {
                ops++;
            }
            if (hToC(head) && cToH(x, y) < head) {
                ops--;
            }
        }
    }

    for (var i = 0; i < q; i++) {
        var xy = readline().split(' ').map(x=>parseInt(x));
        var x = xy[0] - 1;
        var y = xy[1] - 1;
        if (desk[x][y]) {
            remove(x, y);
        } else {
            add(x, y);
        }

        print(ops);
    }


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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

const cache = [0, 2];

function getMaximumPyramids(n) {
    let total = 0;
    let remaining = n;
    while (remaining >= 2) {
        getNextPyramid();
        total++;
    }
    return total;

    function getNextPyramid(h = 1) {
        let required = 2;
        while (required <= remaining){
            required = getRequiredCards(++h);
        }
        remaining -= cache[h-1];
        return h-1;
    }

    function getRequiredCards(h) {
        if (h == 1) return 2;
        else {
            const req = (h * 2) + (h - 1) + (cache[h - 1] || getRequiredCards(h - 1));
            cache[h] = req;
            return req;
        }
    }
}

function main() {
    const n = parseInt(readLine(), 10);
    for (let i = 0; i < n; i++) {
        const result = getMaximumPyramids(parseInt(readLine(), 10));
        console.log(result)
    }
    return;
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
    3
1 3
100000 100000
2 2

**/

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

    for(var r=0;r<range;r++) {
        let remaining = parseInt(readline());
        let h = 0;
        let counter = 0;

        while(remaining > 1) {
            counter++;
            let h = 0;
            while((3*h*h + h) / 2 <= remaining) {
                h++;
            }
            h--;
            let usedCard = (3*h*h + h) / 2;
            remaining = remaining - usedCard;
        }

        console.log(counter);
    }
}

var t = parseInt(readline());
for (var tc = 0; tc < t; tc++) {
  var n = parseInt(readline());
  var currentFloor = 0;
  var nextFloor = 0;
  var count = 0;
  while (n >= 2) {
    var i = 1;
    if (n == 2) {
      count++;
      break;
    } else {
      while (nextFloor - i <= n) {
        currentFloor += i * 3;
        nextFloor = currentFloor + (i + 1) * 3;
        i++;
      }
      n -= currentFloor - i + 1;
      currentFloor = 0;
      nextFloor = 0;
      count++;
    }
  }
  print(count);
}

// Input
'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 mandatoryCards(n) { return (3*n*n + n)/2; }

function processPyramids(remaining, nbPyramids) {
    if (remaining <= 1) return nbPyramids;
    var maxHeight = 1;
    while(mandatoryCards(maxHeight) <= remaining ) maxHeight++;
    return processPyramids(remaining-mandatoryCards(maxHeight-1), nbPyramids+1);
}

//main
function main() {
    var nbOfTestCases = parseInt(readline());

    for (var i=0 ; i<nbOfTestCases ; i++) {
        var n = parseInt(readline());
        console.log(processPyramids(n,0));
    }
}

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin
});
let first = true
rl.on('line', (line) => {
  let max = 0;
  let card = +line;
  if (first) {
    first = false
  } else {
    while (card > 1) {
      let maxCard = 2;
      let maxDeck = 1;
      if (maxCard === card) {
        card -= maxCard;
        max++;
      } else {
        while(true) {
          let newMaxDeck = maxDeck + 1;
          let newMaxCard = maxCard + maxDeck + newMaxDeck * 2;
          if (newMaxCard > card) {
            card -= maxCard;
            max++;
            break;
          } else {
            maxCard = newMaxCard;
            maxDeck = newMaxDeck;
          }
        }
      }
    }
    process.stdout.write(`${max}\n`);
  }
})

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

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

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

function main() {
    const cases = readline();
    var i;
    for (i = 0; i < cases; i++) {
        const line = readline();
        var a = parseInt(line.split(" ")[0]);

        solve(a);
    }
}

function solve(a) {
    var towers = 0;

    if (a < 2) {
        console.log(0);
        return;
    }

    while (a > 1) {
        var floor = 1;
        a -= 2;
        while (a >= cardsForFloor(floor+1)) {
            a -= cardsForFloor(floor+1);
            floor++;
        }
        towers++;
    }

    console.log(towers);
}

const cache = [0, 2];

function cardsForFloor(floor) {
    if (!(floor in cache)) {
        cache[floor] = ((floor)*2 + (floor -1));
    }

    return cache[floor];
}

//Card Constructions

const {EOL} = require('os');

let inp = '';

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

process.stdin.on('end', () => {
    let lines = inp.split(EOL);

    let t = +lines[0];

    let o = {};

    let f = (n) =>  {

    	if(n < 2)  {
    		return 0;
    	}

    	let k = Math.sqrt(2 * n / 3);
    	for(let i = 1; i <= k + 1; i++)  {

    		let r;

    		if(o[i])  {
    			r = o[i];
    		}  else  {
    			o[i] = (i * ((3 * i) + 1)) / 2;
    			r = o[i];
    		}

    		if(r > n)  {
    			return 1 + f(n - (((3 * Math.pow(i - 1, 2)) + (i - 1)) / 2));
    		}
    	}
    }

    for(let i = 0; i < t; i++)  {
    	let n = +lines[i + 1];

    	process.stdout.write(f(n) + '\n');
    }

    return;
});

const processData = (lines) => {
  const n = +lines[0]
  for (let i=0; i<n; i++) {
    let a = +lines[i+1]

    let acc = 0
    while (a > 2) {
      let sum = 2
      let pos = 0
      while (sum <= a) {
        pos++
        sum += 2 + (pos)*3
        // console.log(sum)
      }
      sum -= 2 + (pos)*3
      acc++
      a -= sum
    }
    if (a === 2) {
      acc++
    }
    console.log(acc)
  }
}

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*/
  processData(lines)
})

// node template.js < A-small.in > A-small.out

function main() {
    var tests = 1;
    tests = nextInt();

    for (let t = 1; t <= tests; t++) {
        let N = nextInt();
        let result = 0;
        while (N >= 2) {
            let cost = find(N);
            N -= cost;
            result++;
        }

        print(result);
    }
}

function find(N) {
    let l = 1, r = N, res = 0;
    while (l <= r) {
        let m = Math.floor((l+r) >> 1);
        if (3*m*(m+1)/2-m <= N) {
            l = m+1;
            res = 3*m*(m+1)/2-m;
        } else {
            r = m-1;
        }
        // console.log(l, r, m, 3*m*(m+1)/2-m);
    }
    return res;
}

// ------- Template ------------------
function newTensor(dimensions, value) {
    let res = [];
    let dim = dimensions[0], subdim = dimensions.slice(1);
    if (subdim.length == 0) {
        for(let i = 0; i < dim; i++) {
            res.push(value);
        }
    } else {
        for(let i = 0; i < dim; i++) {
            res.push(newTensor(subdim, value));
        }
    }
    return res;
}

if (!String.prototype.startsWith) {
    Object.defineProperty(String.prototype, 'startsWith', {
        value: function(search, rawPos) {
            var pos = rawPos > 0 ? rawPos|0 : 0;
            return this.substring(pos, pos + search.length) === search;
        }
    });
}
if (!String.prototype.endsWith) {
    String.prototype.endsWith = function(search, this_len) {
        if (this_len === undefined || this_len > this.length) {
            this_len = this.length;
        }
        return this.substring(this_len - search.length, this_len) === search;
    };
}

var curTokens = [], curToken = 0;

function next() {
    while (curToken >= curTokens.length) {
        curTokens = readline().split(/[\s]+/);
        curToken = 0;
    }
    return curTokens[curToken++];
}

function nextInt() {
    return parseInt(next());
}

// code for nodejs
var inputBuffer = '', curLine = 0;

function readline() {
    return inputBuffer[curLine++];
}

function print(data) {
    process.stdout.write(data + '\n');
}

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

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

process.stdin.on('end', function () {
    inputBuffer = inputBuffer.split(/[\s]+/);
    main();
});

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

    main();
});

function readline() {
    return inputString[currentLine++];
}
/**
    5
    3
    14
    15
    24
    1

**/

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

    for(var r=0;r<range;r++) {
        var value = parseInt(readline());

        for(var i=0;i<10^9;i++) {
            let p = (3 * Math.pow(i, 2) + i) / 2;
            if(p === value) {
                console.log(1);
                break;
            }
            if(p > value) {
                console.log(i-1);
                break;
            }
        }
    }
}

'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++];
}
/**
    3
1 3
100000 100000
2 2

**/

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

    for(var r=0;r<range;r++) {
        var value = parseInt(readline());
        var counter = 0;

        for(var i=1;i<10^9;i++) {
            let p = (3 * Math.pow(i, 2) + i) / 2;

            if(p === value) {
                console.log(1);
                break;
            }

            if(p > value) {
                console.log(counter);
                break;
            }

            counter++;
        }
    }
}


var a = readline().split(" ");
var d = parseInt(a[0]);
var h = parseInt(a[1]);
var v = parseInt(a[2]);
var e = parseInt(a[3]);

var V = h * (((d * d) / 4) * Math.PI);

var RainSpeed = e * (((d * d) / 4) * Math.PI);
if(RainSpeed >= v) print("NO"); else{
    print("YES");
    print(V / (v - RainSpeed));
}

var input = readline().split(' ').map(Number);

var d = input[0];
var h = input[1];
var v = input[2];
var e = input[3];

var pi = Math.PI;

var t = - ((pi * Math.pow(d,2) * h) / (e * pi * Math.pow(d,2) - (4 * v)));

if (t < 0) {
	print('NO');
} else {
	print('YES');
	print(t);
}

var input = readline().split(' ').map(function (item) {
    return parseInt(item);
});
var d = input[0], h = input[1], v = input[2], e = input[3];
var hDecRate = (4*v)/(Math.PI*d*d);
if(hDecRate <= e){
    print("NO");
} else {
    var rate = hDecRate - e;
    print("YES");
    print(h/rate);
}

function getInput() {
    var line = readline();
    var lines = [line];
    while (line = readline()) {
        lines.push(line);
    }
    return lines;
}

function main() {
    const input = getInput().pop().split(' ').map(item => Number(item));
    // diam
    const d = input[0];
    // height
    var h = input[1];
    // speed -
    const v = input[2];
    // speed +
    const e = input[3];

    // s = pi*r^2
    const s = Math.PI * Math.pow(d / 2, 2);
    const spOur = v / s;

    if (e > spOur) {
        print('NO')
    } else {
        var t = h / (spOur - e);
        print('YES')
        print(t)
    }
}

main();


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

  let tmp=0, q=0, lrds=[];

  rl.on('line', (input) => {
      if (tmp==0) {q=Number(input); tmp++;}
      else {
          if (tmp<=q){
          let lrd=input.split(' ').map(a=>{return Number(a)});
           lrds.push(lrd);
            tmp++;}
          }
    if (tmp>q){ rl.close(); therest();}
    return 0;}
);

let therest=function() {

    let res=[];
    for (let i=0; i<q; i++) {
        let l=lrds[i][0];
        let r=lrds[i][1];
        let d=lrds[i][2];

        if (d<l || d>r) {res.push(d);
            console.log(d);}
        else {
            if (r%d==0) console.log(r+d);
            else console.log(Math.ceil(r/d)*d)
        }
//console.log(lrds[i]);

    }
//console.log(T, pairs)
}
//console.log(lngth, str);}

  /*
  rl.question('What do you think of Node.js? ', (answer) => {
    // TODO: Log the answer in a database
    console.log(`Thank you for your valuable feedback: ${answer}`);

    rl.close();
  });*/

function main() {
    var q = +readline();
    r = [];

    for(var i = 0; i < q; i++) {
        var t = readline().split(' ');
        r.push({ l: +t[0], r: +t[1], d: +t[2]});
    }

    var res = [];

    r.forEach(function(item) {

        if(item.l > item.d) {
            res.push(item.d);
        }
        else {
            var f = Math.ceil(item.r / item.d);
            if(item.r % item.d == 0)
                f++;
            res.push(f * item.d);
        }
    });

    res.forEach(function(g) {
        print(g);
    })
}

main();

var n = readline();
n = Number(n);

for(var i=0; i<n; i++){
	var lrd = readline().split(' ').map(Number);
	var l = lrd[0];
	var r = lrd[1];
	var d = lrd[2];
	if (d < l) print (d);
	else if (r%d != 0) print (Math.ceil(r/d)*d);
	else print ((r/d+1)*d);
}

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

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

    if(a>c || b<c) print(c)
    else {
        var k = parseInt(b / c)
        //print(k)
        k++
        print(k * c)
    }
}

//

var q = parseInt(readline());

for (var i = 0; i < q; i++) {
  var _ = readline().split(' ').map(Number);

  var l = _[0];
  var r = _[1];
  var d = _[2];

  if (d < l || d > r) {
    print(d);
  } else {
    var minToBreakFree = Math.floor(r / d);
    print(d * (minToBreakFree + 1));
  }
}

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

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

    if(a>c || b<c) print(c)
    else {
        var k = b % c
        print((b - k) + c)
    }
}

//

var q = readline()
for(var i=0; i<q; i++) {
    line = readline().split(" ").map(Number)
    l = line[0]
    r = line[1]
    d = line[2]

    if(d < l || d > r) {
        print(d)
    } else {
        print((Math.floor(r/d) + 1) * d)
    }
}

var n = readline();
for(i=0;i<n;i++) {
    seq= readline().split(" ").map(Number);
    var l = seq[0];
    var r = seq[1];
    var d = seq[2];
    if(d < l || d > r) {
        print(d)
    } else {
        print((Math.floor(r/d) + 1) * d)
    }
}

function calc(l, r, d) {
 if (d < l || d > r) {
   return d;
 }

 return d * Math.ceil(r / d) === r ? r + d : d * Math.ceil(r / d);
}

var q = parseInt(readline());
var lrd,l,r,d;

for (var i = 0; i< q; i++) {
  lrd = readline().split(" ");
  // print(lrd);
  l = parseInt(lrd[0]);
  r = parseInt(lrd[1]);
  d = parseInt(lrd[2]);

  print(calc(l, r, d));
}

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

let l = 0;
let n = 0

rl.on('line', (input) => {
    if (l === 0) {
        n = parseInt(input)
    } else {
        if (l === n)
            rl.close();

        arr = input.split(' ').map(function (item) {
            return parseInt(item, 10);
        });

        if(arr[0]>arr[2]){
          console.log(arr[2])
        } else if(arr[1]<arr[2]){
            console.log(arr[2])
        } else {
            console.log(Math.ceil((arr[1]+1)/arr[2])*arr[2])
        }

        if (l === n)
            return

    }
    l++
});

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

let l = 0;
let n = 0

rl.on('line', (input) => {
    if (l === 0) {
        n = parseInt(input)
    } else {
        if (l === n)rl.close();
        arr = input.split(' ').map(function (item) {
            return parseInt(item, 10);
        });

        if(arr[0]>arr[2]){
          console.log(arr[2])
        } else if(arr[1]<arr[2]){
            console.log(arr[2])
        } else {
            console.log(Math.ceil((arr[1]+1)/arr[2])*arr[2])
        }

        //if (l === n)return

    }
    l++
});

		var q=parseInt(readline());
	var s="",y=0,l,r,d;
	for(var i=0;i<q;i++){
		s=readline().split(" ");
		l=parseInt(s[0]);r=parseInt(s[1]);d=parseInt(s[2]);
		if(l>d){print(d);}
		else{r++;print(Math.ceil(r/d)*d);}
	}

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

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

    var s = a + b
    if(a>c) print(c)
    else if(a == c) print(s)
    else {
        if(s%c == 0) {
            print(s)
        }
    }
}

//

var q=parseInt(readline());
		for(var i=0;i<q;i++){
			var s=readline().split(" ");
			var l=parseInt(s[0]),r=parseInt(s[1]),d=parseInt(s[2]);
			if(l<=d){
			var y=r+1;
			while(y%d!==0){y++;}print(y);}
			else if(l>d){
				var y=l-1;
			while(y%d!==0){y--;}print(y);}
			}

		var q=parseInt(readline());
		for(var i=0;i<q;i++){
			var s=readline().split(" ");
			var l=parseInt(s[0]),r=parseInt(s[1]),d=parseInt(s[2]);
			var y=r+1;
			while(y%d!==0){y++;}print(y);
		}

var q = readline()
for(var i=0; i<q; i++) {
    line = readline().split(" ")
    l = line[0]
    r = line[1]
    d = line[2]

    if(d < l || d > r) {
        print(d)
    } else {
        print((Math.floor(r/d) + 1) * d)
    }
}

var n = readline().split(' ');
for(i=0;i<n;i++) {
    var seq= readline().split(' ');
    var l = seq[0];
    var r = seq[1];
    var d = seq[2];
    for(j=0;j++;) {
        if((j<l || j>r) && (j%d == 0)) {
            print(j + "\n");
        }
    }
}

var n = readline().split(' ');
for(i=0;i<n;i++) {
    var seq= readline().split(' ');
    var l = seq[0];
    var r = seq[1];
    var d = seq[2];
    var j = 1;
    if(d < l || d > r) {
        print(d)
    } else {
        print((Math.floor(r/d) + 1) * d)
    }
}

var n = readline().split(' ');
for(i=0;i<n;i++) {
    var seq= readline().split(' ');
    var l = seq[0];
    var r = seq[1];
    var d = seq[2];
    for(j=0;j++;) {
        if((j<l || j>r) && (j%d == 0)) {
            print(j);
        }
    }
}

var n = readline().split(' ');
for(i=0;i<n;i++) {
    var seq= readline().split(' ');
    var l = seq[0];
    var r = seq[1];
    var d = seq[2];
    var j = 1;
    for(j=1;j++;) {
        if((j<l || j>r) && (j%d == 0)) {
            print(j + "\n");
            break;
        }
    }
}