A card pyramid of height $1$ is constructed by resting two cards against each other. For $h>1$, a card pyramid of height $h$ is constructed by placing a card pyramid of height $h-1$ onto a base. A base consists of $h$ pyramids of height $1$, and $h-1$ cards on top. For example, card pyramids of heights $1$, $2$, and $3$ look as follows: $\wedge A A$ 

You start with $n$ cards and build the tallest pyramid that you can. If there are some cards remaining, you build the tallest pyramid possible with the remaining cards. You repeat this process until it is impossible to build another pyramid. In the end, how many pyramids will you have constructed?


-----Input-----

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1\le t\le 1000$) — the number of test cases. Next $t$ lines contain descriptions of test cases.

Each test case contains a single integer $n$ ($1\le n\le 10^9$) — the number of cards.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^9$.


-----Output-----

For each test case output a single integer — the number of pyramids you will have constructed in the end.


-----Example-----
Input
5
3
14
15
24
1

Output
1
2
1
3
0



-----Note-----

In the first test, you construct a pyramid of height $1$ with $2$ cards. There is $1$ card remaining, which is not enough to build a pyramid.

In the second test, you build two pyramids, each of height $2$, with no cards remaining.

In the third test, you build one pyramid of height $3$, with no cards remaining.

In the fourth test, you build one pyramid of height $3$ with $9$ cards remaining. Then you build a pyramid of height $2$ with $2$ cards remaining. Then you build a final pyramid of height $1$ with no cards remaining.

In the fifth test, one card is not enough to build any pyramids.

Difficulty: EASY

Solutions:
def num(x):
	return 3 * x ** 2 / 2 + x / 2

def findMaxN(x, left=0, right=26000):
	while left < right:
		mid = (left + right) // 2
		a = num(mid)
		b = num(mid + 1)
		c = num(mid - 1)
		if b > x and a < x:
			return mid
		elif a > x and c < x:
			return mid - 1
		elif a == x:
			return mid
		elif a < x:
			left = mid + 1
		elif a > x:
			right = mid - 1
	return right

def solve():
	cards = int(input())
	cnt = 0
	right = 26000
	while cards >= 2:
		right = findMaxN(cards, right=right)
		(d, cards) = divmod(cards, num(right))
		cnt += d
	print(int(cnt))
nums = int(input())
for _ in range(1, nums + 1):
	solve()


import sys
from collections import Counter
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def card(n):
	return n * (n + 1) + n * (n + 1) // 2 - n

def a():
	ans = ''
	for _ in range(int(inp())):
		(n, m) = read()
		if n == 1 or m == 1:
			ans += 'YES\n'
		elif n == 2 and m == 2:
			ans += 'YES\n'
		else:
			ans += 'NO\n'
	print(ans)

def b():
	ans = ''
	for _ in range(int(inp())):
		n = int(inp())
		s = 0
		while 1 < n:
			i = 1
			while card(i) <= n:
				i += 1
			n -= card(i - 1)
			s += 1
		ans += str(s) + '\n'
	print(ans)
b()


num_inp = lambda : int(input())
arr_inp = lambda : list(map(int, input().split()))
sp_inp = lambda : map(int, input().split())
str_inp = lambda : input()
k = 0
for i in range(int(input())):
	q = int(input())
	while q > 1:
		q = q - ((((1 + 24 * q) ** 0.5 - 1) // 6 * 6 + 1) ** 2 - 1) // 24
		k += 1
	print(k)
	k = 0


t = int(input())
from bisect import bisect_right as br
an = [0, 2]
i = 2
c = an[i - 1] + (i - 1) + 2 * i
while c < 10 ** 9:
	an.append(c)
	i += 1
	c = an[i - 1] + (i - 1) + 2 * i
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		i = br(an, n)
		n = n - an[i - 1]
		ans += 1
	print(ans)


import sys
import math
from itertools import islice, cycle
from collections import Counter, defaultdict
stdin = sys.stdin
t = stdin.readline().strip()
t = int(t)
results = {0: 0, 1: 0, 2: 1}

def smallest_sol(m):
	x = -1 / 2 + math.sqrt(1 / 4 + 6 * m)
	x /= 3
	return math.floor(x)

def solv(n):
	global results
	if n in results:
		return results[n]
	h = smallest_sol(n)
	cards = 3 / 2 * h ** 2 + 1 / 2 * h
	cards = int(cards)
	r = solv(n - cards) + 1
	results[n] = r
	return r
for test_idx in range(t):
	n = stdin.readline().strip()
	n = int(n)
	solv(n)
	print(results[n])


t = int(input())

def f(a):
	return (3 * a + 1) * a // 2

def binSearch(u, l, h):
	if l + 1 >= h:
		return l
	m = (l + h) // 2
	if f(m) <= u:
		return binSearch(u, m, h)
	return binSearch(u, l, m)

def sol():
	n = int(input())
	res = 0
	while n > 0:
		k = binSearch(n, 0, n)
		if k == 0:
			break
		res += 1
		n -= f(k)
	return res
for _ in range(t):
	print(sol())


import math
t = int(input())
for _ in range(t):
	num = int(input())
	i = 1
	count = 0
	while num > 1:
		num = num - (i * 2 + (i - 1))
		i += 1
		if num > 1:
			continue
		elif num < 0:
			num = num + ((i - 1) * 2 + (i - 1 - 1))
			i = 1
			count += 1
		else:
			count += 1
			break
	print(count)


testCases = int(input())
for _ in range(testCases):
	n = int(input())
	pyramids = []
	pyramid = 0
	count = 0
	for index in range(1, n):
		pyramid += index * 2 + index - 1
		pyramids.append(pyramid)
		if pyramid > n:
			break
	pyramids.reverse()
	while n > 1:
		for cards in pyramids:
			if cards <= n:
				n -= cards
				count += 1
				break
	print(count)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def sumi(h):
	return h * (3 * h + 1) // 2
for t in range(int(input())):
	n = int(input())
	cnt = 0
	h = 0
	while True:
		if n == 1 or n == 0:
			break
		h += 1
		if sumi(h) <= n:
			continue
		else:
			cnt += 1
			n -= sumi(h - 1)
			h = 0
	print(cnt)


import bisect
init = 2
temp = 5
dict1 = {}
pyramid = []
while True:
	pyramid.append(init)
	init += temp
	temp += 3
	if init > 10000000001:
		break
for _ in range(int(input())):
	ans = 0
	n = int(input())
	while True:
		closest = bisect.bisect(pyramid, n)
		ans += n // pyramid[closest - 1]
		n = n - pyramid[closest - 1] * (n // pyramid[closest - 1])
		if n == 0 or n == 1:
			break
		elif pyramid[closest - 1] == 2:
			break
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	p = 0
	while n > 1:
		h = 1
		while h * (h + 1) // 2 * 3 - h <= n:
			h += 1
		h -= 1
		p += 1
		n -= h * (h + 1) // 2 * 3 - h
	print(p)


import sys
import math
from bisect import bisect_right
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans

def find_le(a, x):
	i = bisect_right(a, x)
	if i:
		return i - 1
	else:
		return -1
t = int(input())
a = []
for i in range(1, 100000):
	v = i * (i + 1)
	v += i * (i - 1) // 2
	a.append(v)
for tt in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		i = find_le(a, n)
		if a[i] > n:
			i -= 1
		if i == -1:
			break
		n -= a[i]
		ans += 1
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


arr = [2]
for t in range(2, 50000):
	arr.append(arr[-1] + 2 * t + t - 1)
import bisect
t = int(input())
for j in range(t):
	n = int(input())
	count = 0
	x = 1000
	while True:
		x = bisect.bisect(arr, n)
		if x == 0:
			break
		else:
			count += 1
			n -= arr[x - 1]
	print(count)


import sys
readline = sys.stdin.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))

def solve():
	n = ni()
	ans = 0
	while n > 1:
		(ok, ng) = (0, 10 ** 5)
		while ng - ok > 1:
			mid = (ok + ng) // 2
			if mid * (mid + 1) * 3 // 2 - mid <= n:
				ok = mid
			else:
				ng = mid
		n -= ok * (ok + 1) * 3 // 2 - ok
		ans += 1
	print(ans)
T = ni()
for _ in range(T):
	solve()


t = int(input())
dp = [0]

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def f(h):
	return h * (3 * h + 1) // 2
for i in range(1, 25820):
	dp.append(f(i))
while t:
	n = int(input())
	c = 0
	while True:
		x = binarySearchCount(dp, len(dp), n)
		if x <= 1:
			break
		else:
			n -= dp[x - 1]
			c += 1
	print(c)
	t -= 1


height_cards = [0, 2]
max_height = 25830
for i in range(2, max_height):
	height_cards.append(3 * i + height_cards[i - 1] - 1)

def bs(given, left=0, right=max_height):
	while right - left > 1:
		m = (left + right) // 2
		cards_req = height_cards[m]
		if cards_req > given:
			right = m
		else:
			left = m
	return left
t = int(input())
ans = []
for i in range(t):
	cards = int(input())
	res = 0
	while cards > 1:
		cards -= height_cards[bs(cards)]
		res += 1
	ans.append(res)
print(*ans, sep='\n')


numt = int(input())

def num_p(card):
	check = 0
	count = 1
	while True:
		if (3 * count * count + count) / 2 > card:
			card = card - (3 * (count - 1) * (count - 1) + count - 1) / 2
			break
		check = 1
		count = count + 1
	return (check, card)
for uigrf in range(numt):
	card = int(input())
	count = 0
	while True:
		lst = num_p(card)
		card = lst[1]
		if lst[0] == 0:
			break
		else:
			count += 1
	print(count)


import bisect
tc = int(input())
for _ in range(tc):
	card = int(input())
	c_max = card
	dp_max = 0
	dp = [0, 2]
	c_height = 1
	while dp_max < c_max:
		c_height += 1
		dp.append(c_height * dp[1] + c_height - 1 + dp[-1])
		dp_max = dp[-1]
	ans = 0
	while c_max >= 2:
		now = bisect.bisect_left(dp, c_max)
		if dp[now] == c_max:
			c_max -= dp[now]
		else:
			c_max = c_max - dp[now - 1]
		ans += 1
	print(ans)


t = int(input())
for test in range(t):
	n = int(input())
	ans = 0
	if n == 1:
		print(ans)
		continue
	else:
		while n > 0:
			h = int((-1 + (1 + 24 * n) ** 0.5) / 6)
			cards_used = (3 * h * h + h) / 2
			n = n - cards_used
			ans += 1
			if n == 0 or n == 1:
				print(ans)
				break


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	num = 0
	while n >= 2:
		temp = (sqrt(1 + 24 * n) - 1) // 6
		n -= (3 * temp ** 2 + temp) // 2
		num += 1
	print(num)


import sys
import math
from collections import defaultdict

def solve(test):
	n = int(input())
	count = 0
	while n >= 2:
		res = (-1 + int(math.sqrt(1 + 24 * n))) // 6
		n -= res * (3 * res + 1) // 2
		count += 1
	print(count)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


def binarySearch(arr, l, r, x):
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] == x:
			ans = mid
			break
		elif arr[mid] < x:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [2]
	i = 2
	while arr[-1] < n:
		arr.append(arr[-1] + 2 * i + (i - 1))
		i += 1
	l = len(arr)
	ans = 0
	while n > 0:
		temp = binarySearch(arr, 0, l - 1, n)
		if temp == -1:
			break
		else:
			ans += 1
			n -= arr[temp]
	print(ans)


from sys import stdin

def func(n):
	(l, r) = (0, len(ans) - 1)
	while l <= r:
		mid = (l + r) // 2
		if ans[mid] == n:
			return mid + 1
		if ans[mid] > n:
			r = mid - 1
		else:
			l = mid + 1
	return l
ans = []
x = 2
i = 1
m = 2
while x <= 10 ** 9:
	ans.append(x)
	m += 3
	x += m
	i += 1
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	count = 0
	while n > 1:
		count += 1
		x = ans[func(n) - 1]
		n -= x
	print(count)


kl = int(input())
for l in range(kl):
	n = int(input())
	k = 0
	while n > 2:
		kc = 2
		vs = 0
		while kc <= n:
			vs += 1
			kc += vs * 3 + 2
		k += 1
		kc -= vs * 3 + 2
		n -= kc
	if n == 0 or n == 1:
		print(k)
	else:
		print(k + 1)


def main():
	n = int(input())
	st = set()
	st.add(2)
	number = 2
	change = 2
	while number <= n:
		change += 3
		number += change
		st.add(number)
	st = sorted(list(st))
	have = 0
	for i in range(len(st) - 1, -1, -1):
		while n >= st[i]:
			n -= st[i]
			have += 1
	print(have)

def __starting_point():
	t = int(input())
	for i in range(t):
		main()
__starting_point()


t = int(input())
for i in range(t):
	n = int(input())
	i = 0
	count = 0
	while n > 1:
		m = 0
		i = 1
		while m <= n:
			h = m
			m = m + 3 * i - 1
			i += 1
		n = n - h
		count += 1
	print(count)


import math
t = int(input())
s = ''
while t > 0:
	c = int(input())
	cnt = 0
	while c >= 2:
		h = int((math.sqrt(24 * c + 1) - 1) / 6)
		if h >= 1:
			cnt += 1
		c -= int(h * (3 * h + 1) / 2)
	s += str(cnt) + '\n'
	t -= 1
print(s)


t = int(input())
for _ in range(t):
	dp = [2]
	a = int(input())
	i = 1
	while dp[-1] <= a:
		dp.append(dp[i - 1] + i + 2 * (i + 1))
		i += 1
	ans = 0
	dp.reverse()
	for i in range(len(dp)):
		while a - dp[i] >= 0:
			a -= dp[i]
			ans += 1
		else:
			continue
	print(ans)


T = int(input())
for t in range(T):
	n = int(input())

	def f(n):
		if n < 2:
			return 0
		else:
			i = 0
			curr = 0
			while curr <= n:
				i += 1
				curr += 3 * i - 1
			curr -= 3 * i - 1
			return 1 + f(n - curr)
	print(f(n))


import math

def max_height(k):
	return math.floor(1 / 3 * (math.sqrt(6 * k + 1 / 4) - 1 / 2))

def pyramid(k):
	total = 0
	while k >= 2:
		n = max_height(k)
		total += 1
		k -= 2 * n + 3 * (n - 1) * n / 2
	return total
t = int(input())
lst = []
for i in range(t):
	n = int(input())
	lst.append(pyramid(n))
print(*lst, sep='\n')


import sys
input = sys.stdin.readline

def next(arr, target):
	start = 0
	end = len(arr) - 1
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] > target:
			end = mid - 1
		else:
			ans = max(mid, ans)
			start = mid + 1
	return ans
t = int(input())
numcards = 2
d = {}
d[1] = 2
counter = 2
while numcards <= 10 ** 9:
	d[counter] = d[counter - 1] + counter * 2 + (counter - 1)
	numcards = d[counter]
	counter += 1
l = [0]
for i in range(1, 25821):
	l.append(d[i])
for r in range(t):
	n = int(input())
	if n == 1:
		print(0)
	else:
		ans = 0
		while n > 0:
			closest = next(l, n)
			if l[closest] != 0:
				ans += 1
				n -= l[closest]
			else:
				break
		print(ans)


from sys import stdin, stdout
for query in range(int(stdin.readline())):
	cardsleft = int(stdin.readline())
	mylist = [2]
	cards = 2
	count = 1
	for x in range(26000):
		count += 1
		cards = cards + 3 * count - 1
		mylist.append(cards)
	total = 0
	while cardsleft >= 2:
		count = 0
		while mylist[count] <= cardsleft:
			count += 1
		cardsleft -= mylist[count - 1]
		total += 1
	stdout.write(str(total) + '\n')


import sys
import collections
import math
import functools
import itertools
import bisect
import operator
import heapq
import random
true = True
false = False
null = None
tcid = 0
tcmax = 99999999

def compute(val, func):
	return func(val)

def seq(lo, hi, step=1):
	return range(lo, hi + 1, step)

def sround(val, nd):
	return f'{val:.{nd}f}'

def ceil(a, b):
	ans = a // b
	if a % b != 0:
		ans += 1
	return ans

def perr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def line():
	ln = sys.stdin.readline().strip()
	if ln == '':
		sys.exit()
	return ln

def lines(n):
	return [line() for i in range(n)]

def split(ln=None):
	return (ln or line()).split()

def num(str=None):
	str = str or line()
	return float(str) if '.' in str else int(str)

def nums(o=None):
	if o is not None:
		if isinstance(o, int):
			o = lines(o)
		elif isinstance(o, str):
			o = split(o)
	return list(map(num, o or split()))
tcmax = num()

class aaa:

	@functools.lru_cache(null)
	def __getitem__(self, nn):
		ans = nn * (nn + 1) // 2
		return ans * 3 - nn
aa = aaa()
bb = []
cc = 0
while aa[cc] <= 10 ** 9:
	bb.append(aa[cc])
	cc += 1

def mainloop(tcid=1):
	n = num()
	ans = 0
	while true:
		hh = bisect.bisect(aa, n, hi=10 ** 9)
		if aa[hh] > n:
			hh -= 1
		if hh == 0:
			break
		n -= aa[hh]
		ans += 1
	print(ans)
while tcid < tcmax:
	tcid += 1
	mainloop(tcid)


for _ in range(int(input())):
	n = int(input())
	if n >= 1 and n < 7:
		print(n // 2)
	elif n <= 8:
		print(1)
	else:
		c = 0
		r = n
		while r >= 2:
			x = r
			for i in range(1, x):
				d = x - 3 * i
				if d < 2 * (i + 1):
					r = x - 2 * i
					break
				else:
					x = d
			c += 1
		print(c)


for _ in range(int(input())):
	n = int(input())
	c = 0
	y = 0
	while n > 1:
		y = (-1 + (1 + 24 * n) ** 0.5) // 6
		n -= (3 * y + 1) * y // 2
		c += 1
	print(c)


def f(n):
	if n <= 0:
		return 0
	return (3 * n * n + n) // 2

def binser(v):
	aw = 1
	ak = 1000000001
	ans = (aw + ak) // 2
	while aw <= ak:
		mid = (aw + ak) // 2
		r = f(mid)
		if r == v:
			return mid
		elif r < v:
			ans = mid
			aw = mid + 1
		else:
			ak = mid - 1
	return ans

def main():
	tc = int(input())
	for _ in range(tc):
		n = int(input())
		cnt = 0
		while n > 1:
			idx = binser(n)
			cnt += 1
			n = n - f(idx)
		print(cnt)
main()


for _ in range(int(input())):
	n = int(input())
	t1 = n
	ans = 1
	c = 0
	i = 1
	j = 0
	f = 0
	if n == 3 or n == 2:
		print('1')
		continue
	elif n == 1:
		print('0')
		continue
	while t1 > 1:
		card = i * 2 + j
		if t1 >= card:
			t1 -= card
			f = 1
		else:
			i = 0
			j = -1
			ans += 1
		i += 1
		j += 1
	print(ans)


dp = [0] * 30002
dp[1] = 2
for i in range(2, 30002):
	dp[i] = dp[i - 1] + 2 * i + i - 1
for _ in range(int(input())):
	n = int(input())
	ans = 0
	i = 30001
	while i > 0 and n > 0:
		if dp[i] <= n:
			n -= dp[i]
			ans += 1
			i += 1
		i -= 1
	print(ans)


a = 7
b = 8
x = [2]
while a < 10 ** 9:
	x.append(a)
	a += b
	b += 3
t = int(input())
arr = x
n = len(arr)

def find(key):
	left = 0
	right = n
	mid = 0
	while left < right:
		mid = (right + left) // 2
		if arr[mid] == key:
			while mid + 1 < n and arr[mid + 1] == key:
				mid += 1
			break
		elif arr[mid] > key:
			right = mid
		else:
			left = mid + 1
	while mid > -1 and arr[mid] > key:
		mid -= 1
	return mid + 1
while t:
	t -= 1
	n1 = int(input())
	co = 0
	while 1:
		x = find(n1)
		if x == 0:
			break
		co += n1 // arr[x - 1]
		n1 -= n1 // arr[x - 1] * arr[x - 1]
	print(co)


def main_function():
	from sys import stdin
	from sys import stdout
	from bisect import bisect_right
	input = stdin.readline
	print = stdout.write
	t = int(input())
	quantity_stick_per_height = [2]
	current_stick_for_base = 5
	while quantity_stick_per_height[-1] < pow(10, 9) + 1:
		quantity_stick_per_height.append(quantity_stick_per_height[-1] + current_stick_for_base)
		current_stick_for_base += 3
	for _ in range(t):
		n = int(input())
		counter = 0
		while n > 1:
			ix = bisect_right(quantity_stick_per_height, n)
			n -= quantity_stick_per_height[ix - 1]
			counter += 1
		print(f'{counter}\n')
main_function()


import sys
input = sys.stdin.readline
import bisect as bi
I = lambda : list(map(int, input().split()))
a = [2]
i = 1
k = 4
x = 2
while x < 10 ** 9:
	x += i + k
	a.append(x)
	i += 1
	k += 2
for _ in range(int(input())):
	(n,) = I()
	ct = 0
	x = bi.bisect(a, n)
	while n > 1:
		n -= a[x - 1]
		ct += 1
		x = bi.bisect(a, n)
	print(ct)


for i in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
	else:
		count = 0
		while n > 1:
			sum1 = 2
			j = 0
			while n >= sum1:
				sum2 = sum1
				sum1 = (j + 2) * 2 + j + 1 + sum2
				j += 1
			count += 1
			n -= sum2
		print(count)


import sys
input = lambda : sys.stdin.readline().strip()
ipnut = input
dp = [0]
n = 0
while dp[-1] < 1000000000:
	n += 1
	dp.append(n * (3 * n + 1) // 2)
for i in range(int(input())):
	n = int(input())
	k = 0
	while n > 1:
		k += 1
		l = 0
		r = len(dp)
		while r - l > 1:
			m = (r + l) // 2
			if dp[m] <= n:
				l = m
			else:
				r = m
		n -= dp[l]
	print(k)


for i in range(int(input())):
	n = int(input())
	ans = 0
	while n >= 2:
		h = (-1 + (1 + 24 * n) ** (1 / 2)) // 6
		n = n - (1 + 3 * h) * (h / 2)
		ans += 1
	print(ans)


import math
for i in range(int(input())):
	n = int(input())
	ans = 0
	s = set()
	while n >= 2:
		h = math.floor((-1 + (1 + 24 * n) ** 0.5) / 6)
		ans += 1
		n -= (3 * h ** 2 + h) // 2
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	cnt = 0
	while n > 1:
		h = 1
		now = 2
		while n >= now + 2 * (h + 1) + h:
			now += (h + 1) * 2 + h
			h += 1
		n -= now
		cnt += 1
	print(cnt)


t = int(input())
l = []
for i in range(t):
	res = 0
	n = int(input())
	x = n
	while n > 1:
		h = (-1 + (1 + 24 * x) ** 0.5) / 6
		if h % 1 == 0:
			res += 1
			n -= x
			x = n
		else:
			x -= 1
	l.append(res)
for i in l:
	print(i)


t = int(input())
while t > 0:
	n = int(input())
	res = 0
	while n > 1:
		ct = 5
		b = 2
		while n >= b:
			n = n - b
			b = ct
			ct = ct + 3
		res = res + 1
	print(res)
	t -= 1


import math
t = int(input())
for i in range(t):
	k = int(input())
	if k < 2:
		print('0')
	else:
		ct = 0
		while k > 1:
			ct += 1
			n = (math.sqrt(1 + 24 * k) - 1) // 6
			k = k - (3 * n * n + n) // 2
		print(ct)


t = int(input())
inputs = []
for _ in range(t):
	inputs.append(int(input()))
n = 10 ** 6 + 1
possible = [2]
i = 1
j = 2
while possible[-1] <= 10 ** 9:
	i += j
	possible.append(i * 3 - j)
	j += 1
answer = [0] * n
pointer = 0
i = 2
while i < n:
	try:
		if i >= possible[pointer + 1]:
			pointer += 1
	except:
		pass
	answer[i] = 1 + answer[i - possible[pointer]]
	i += 1
for _ in inputs:
	ans = 0
	while _ > 10 ** 6:
		pointer = 0
		while pointer < len(possible) - 1:
			if _ >= possible[pointer + 1]:
				pointer += 1
			else:
				break
		ans += 1
		_ -= possible[pointer]
	print(ans + answer[_])


from sys import stdin
import math

def solve(t):
	x = int((math.sqrt(24 * t + 1) - 1) / 6)
	return x
for j in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		n = n - (3 * solve(n) + 1) * solve(n) // 2
		ans += 1
	print(ans)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def from_file(f):
	return f.readline
N = 10 ** 9 + 1
cards_for_h = [0]
h_cur = 1
while cards_for_h[-1] <= N:
	count = -1 + 3 * h_cur + cards_for_h[-1]
	cards_for_h.append(count)
	h_cur += 1

def binary_search(arr, target):
	left = 0
	right = len(arr)
	while left < right:
		m = left + right >> 1
		if target >= arr[m]:
			left = m + 1
		else:
			right = m
	return left

def solve(n, cards_for_h):
	count = 0
	while n != 0:
		h = binary_search(cards_for_h, n) - 1
		if h == 0:
			break
		n -= cards_for_h[h]
		count += 1
	return count
t = inp()
for _ in range(t):
	n = inp()
	print(solve(n, cards_for_h))


f = lambda x: int(0.5 * (3 * x * x + x))
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while True:
		height = ((1 + 24 * n) ** 0.5 - 1) // 6
		if height == 0:
			break
		n -= f(height)
		ans += 1
	print(ans)


import bisect
start = [2]
for i in range(2, 40000):
	bot = i * 2 + i - 1
	start.append(start[-1] + bot)

def solve(num):
	ans = 0
	while num > 1:
		pos = bisect.bisect_right(start, num)
		num = num - start[pos - 1]
		ans += 1
	return ans
for _ in range(int(input())):
	print(solve(int(input())))


t = int(input())
for _ in range(t):
	n = int(input())
	l = [2]
	j = 5
	while l[-1] < n:
		l.append(l[-1] + j)
		j += 3
	c = 0
	if l[-1] > n:
		l.pop()
	if len(l) == 0:
		print(0)
	else:
		while n > 1:
			for i in range(len(l)):
				if l[i] == n:
					n = 0
					c += 1
					break
				elif l[i] > n:
					n -= l[i - 1]
					c += 1
					break
				elif i == len(l) - 1 and l[i] < n:
					n -= l[-1]
					c += 1
					break
		print(c)


def solve():
	t = int(input())
	for i in range(t):
		ans = 0
		n = int(input())
		while n > 1:
			n2 = 2
			k = 5
			h = 1
			while n2 + k <= n:
				n2 += k
				k += 3
				h += 1
			n = n - n2
			ans += 1
		print(ans)
solve()


for i in range(int(input())):
	n = int(input())
	c = 0
	while n >= 2:
		count = 5
		current = 2
		while n >= current:
			n -= current
			current = count
			count += 3
		c += 1
	print(c)


import bisect
t = int(input())
pyramid_heights = [2]
pyramid_height = 2
addition = 5
while pyramid_height < 1000000000:
	pyramid_height = pyramid_height + addition
	addition += 3
	pyramid_heights.append(pyramid_height)
while t != 0:
	height = int(input())
	ans = 0
	pos = bisect.bisect_left(pyramid_heights, height)
	while height >= 0:
		if height == 0:
			break
		if height < pyramid_heights[0]:
			break
		elif height - pyramid_heights[pos] >= 0:
			height = height - pyramid_heights[pos]
			ans += 1
		else:
			pos -= 1
	print(ans)
	t -= 1


from functools import reduce
import sys

class Read:

	@staticmethod
	def string():
		return input()

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(delimiter=' '):
		return input().split(delimiter)

	@staticmethod
	def list_int(delimiter=' '):
		return list(map(int, input().split(delimiter)))

def main():
	t = Read.int()
	for _ in range(t):
		n = Read.int()
		res = 0
		while n >= 2:
			tmp = 2
			i = 2
			while n >= tmp + (i * 3 - 1):
				tmp += i * 3 - 1
				i += 1
			n -= tmp
			res += 1
		print(res)
main()


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
MAX = 10 ** 9
dp = [0]
a = 2
b = 0
while dp[-1] + a + b <= MAX:
	dp.append(dp[-1] + a + b)
	a += 2
	b += 1
M = len(dp)
for _ in range(INT()):
	N = INT()
	ans = 0
	for i in range(M - 1, 0, -1):
		while dp[i] <= N:
			N -= dp[i]
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	x = int(input())
	counter = 0
	while x > 1:
		counter += 1
		temp = ((1 + 24 * x) ** (1 / 2) - 1) // 6
		x = x - (3 * temp * (temp + 1) // 2 - temp)
	print(counter)


def a(n):
	ans = 24 * n
	ans += 1
	ans = ans ** 0.5
	ans -= 1
	ans /= 6
	return ans // 1
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		n -= a(n) * (3 * a(n) + 1) // 2
		ans += 1
	print(ans)


import math

def ans(k):
	if k < 4:
		return 0
	x = math.floor((-7 + math.sqrt(49 - 12 * (4 - k))) / 6)
	return 1 + ans(k - (3 * x * x + 7 * x + 4))
T = int(input())
for t in range(T):
	n = int(input())
	print(ans(2 * n))


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	while n > 1:
		for c in range(1, pow(10, 5)):
			if n >= c * (3 * c + 1) // 2 and n < (c + 1) * (3 * (c + 1) + 1) // 2:
				n = n - c * (3 * c + 1) // 2
				count += 1
				break
	print(count)


def pyr(n):
	return 3 * int(0.5 * (n + 1) * n) - n

def bs(l, r, n):
	if pyr(r) == n:
		return r
	if l == r - 1:
		return l
	elif pyr((l + r) // 2) >= n:
		return bs(l, (r + l) // 2, n)
	return bs((r + l) // 2, r, n)
for something in range(int(input())):
	n = int(input())
	ans = 0
	while n >= 2:
		bs_res = bs(1, 26000, n)
		n -= pyr(bs_res)
		ans += 1
	print(ans)


def buildingPyramids(n):
	dp = []
	dp.append(2)
	i = 2
	while dp[-1] <= n:
		dp.append(2 * i + dp[-1] + (i - 1))
		i += 1
	del dp[-1]
	count = 0
	dp = dp[::-1]
	i = 0
	while n > 0 and i < len(dp):
		if dp[i] <= n:
			n -= dp[i]
			count += 1
		else:
			i += 1
	return count
t = int(input())
for _ in range(t):
	n = int(input())
	print(buildingPyramids(n))


t = int(input())
while t:
	n = int(input())

	def calc(n, count):
		if n < 2:
			print(count)
		else:
			prev = 2
			next = 7
			i = 2
			while n >= next:
				prev = next
				next = next + (3 * i + 2)
				i = i + 1
			n = n - prev
			count = count + 1
			calc(n, count)
	calc(n, 0)
	t = t - 1


import sys

def main():
	t = int(input())
	for _ in range(t):
		n = int(sys.stdin.readline().strip())
		ans = 0
		while n > 1:
			cnt = 1
			temp = 2
			while n >= temp + cnt + 2 * (cnt + 1):
				temp += cnt + 2 * (cnt + 1)
				cnt += 1
			n -= temp
			ans += 1
		print(ans)
	return
main()


from bisect import bisect_right

def f(x):
	return 3 * (x + 1) * x // 2 - x
t = int(input())
nums = [0]
i = 1
while f(i) <= 10 ** 9:
	nums.append(f(i))
	i += 1
for _ in range(t):
	n = int(input())
	i = bisect_right(nums, n)
	ans = 0
	while i >= 2:
		ans += 1
		n -= nums[i - 1]
		i = bisect_right(nums, n)
	print(ans)


def pyramid_builder(n):
	built = 0
	i = 2
	base = 2
	while base + 2 * i + (i - 1) <= n:
		base = base + 2 * i + (i - 1)
		i += 1
	n -= base
	i -= 1
	if n < 0:
		return built
	else:
		built += 1
	while n > 1:
		if base > n:
			base -= i * 2 + (i - 1)
			i -= 1
		else:
			n -= base
			built += 1
	return built
t = int(input())
for x in range(t):
	print(pyramid_builder(int(input())))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		cnt = 0
		while n > 1:
			i = 0
			while i <= n * n:
				i += 1
				total = i * (i + 1) + i * (i - 1) // 2
				if total > n:
					break
			i -= 1
			n -= i * (i + 1) + i * (i - 1) // 2
			i = 1
			cnt += 1
		print(cnt)
	return

def __starting_point():
	main()
__starting_point()


import math
for _ in range(int(input())):
	n = int(input())
	it = 0
	while True:
		x = math.floor((-1 + math.sqrt(1 + 24 * n)) / 6)
		if x >= 1 and it == 0:
			it += 1
		n -= (4 + 3 * (x - 1)) * x / 2
		if n < 2:
			break
		it += 1
	print(it)


p = [2]
i = 1
while p[-1] <= 1000000000.0:
	p.append(p[-1] + i + (i + 1) * 2)
	i += 1

def search(a, t):
	l = 0
	r = len(a) - 1
	an = 0
	while r - l >= 0:
		mid = (l + r) // 2
		if a[mid] == t:
			an = mid
		if a[mid] < t:
			l = mid + 1
		if a[mid] >= t:
			an = mid
			r = mid - 1
	return an
t = int(input())
for _ in range(t):
	n = int(input())
	if n < 2:
		print(0)
	else:
		ct = 0
		while n >= 2:
			i = search(p, n) - 1
			if p[i + 1] == n:
				ct += 1
				break
			else:
				n -= p[i]
				ct += 1
		print(ct)


def search(num):
	low = 0
	high = len(arr) - 1
	while low < high:
		mid = (low + high) // 2
		if arr[mid] < num:
			low = mid + 1
		else:
			high = mid
	return low

def calc(nu):
	return (3 * nu * nu + nu) // 2
t = int(input())
num = 1
calc = 1
arr = []
while calc <= 10 ** 9:
	calc = (3 * num * num + num) // 2
	arr.append(calc)
	num += 1
for _ in range(t):
	n = int(input())
	left = n
	ans = 0
	while True:
		if left <= 1:
			break
		ind = search(left)
		if arr[ind] == left:
			left -= arr[ind]
			ans += 1
		else:
			left -= arr[ind - 1]
			ans += 1
	print(ans)


t = int(input())
import math
for _ in range(t):
	n = int(input())
	i = 0
	size = 1
	while n > 1 and size > 0:
		size = math.floor((-1 / 2 + math.sqrt(1 / 4 + 6 * n)) / 3)
		n -= size * (size + 1) * 3 / 2 - size
		i += 1
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	num_pyramid = 0
	while n >= 2:
		c = 2
		i = 5
		if n - 2 < 0:
			break
		else:
			while c < n:
				c += i
				if c > n:
					c -= i
					break
				else:
					i += 3
			num_pyramid += 1
			n -= c
	print(num_pyramid)


def main():
	max_int = 10 ** 9 + 1
	dp = [0, 2]
	last_val = 2
	i = 1
	while last_val < max_int:
		last_val = i * 3 + 2 + dp[i]
		dp.append(last_val)
		i += 1
	test_cases = int(input())
	for _ in range(test_cases):
		count = 0
		flag = True
		N = int(input())
		while N >= 2:
			i = 0
			while N >= dp[i]:
				i += 1
			if i > 0:
				N -= dp[i - 1]
			count += 1
		print(count)
main()


from math import sqrt
for _ in range(int(input())):
	n = int(input())
	runs = 0
	while n >= 2:
		x = int((sqrt(1 + 24 * n) - 1) / 6)
		n -= (3 * x ** 2 + x) // 2
		runs += 1
	print(runs)


def check(h, x):
	k = (3 * h * h + h) // 2
	return k <= x
q = int(input())
for i in range(q):
	n = int(input())
	c = 0
	while n > 1:
		r = n
		l = -1
		while r - l > 1:
			m = (r + l) // 2
			if check(m, n):
				l = m
			else:
				r = m
		n -= (3 * l * l + l) / 2
		c += 1
	print(c)


def lower_bound(a, l, r, v):
	ans = r
	r -= 1
	while l <= r:
		mid = (l + r) // 2
		if a[mid] <= v:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	return ans

def init(h):
	for i in range(10000000):
		if i == 0:
			h.append(2)
		else:
			h.append(h[i - 1] + i + 2 * (i + 1))
		if h[i] >= 1000000000:
			break
h = []
init(h)
T = int(input())
for i in range(T):
	n = int(input())
	ans = 0
	while n >= 2:
		n -= h[lower_bound(h, 0, len(h), n)]
		ans += 1
	print(ans)


l = []
x = 0
for i in range(1, 1000000):
	if x < 1000000000.0:
		x = 2 * (i * (i + 1) // 2) + (i - 1) * i // 2
		l.append(x)
	else:
		break

def floor_search(n):
	for i in range(len(l)):
		if n == l[i]:
			return l[i]
		if n < l[i]:
			ci = i - 1
			return l[ci]
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n >= 2:
		n = n - floor_search(n)
		c += 1
	print(c)


t = int(input())
while t:
	t -= 1
	n = int(input())
	l = [2]
	x = 0
	while l[-1] <= n:
		y = 3 * x + 5
		l.append(l[-1] + y)
		x += 1
	c = 0
	for i in range(len(l) - 2, -1, -1):
		while n >= l[i]:
			c += 1
			n -= l[i]
	print(c)


from bisect import bisect_right
t = int(input())
l = [0] * 100000
for i in range(1, 100001):
	l[i - 1] = i * (3 * i + 1) // 2
for _ in range(t):
	n = int(input())
	ans = 0
	while 1:
		idx = bisect_right(l, n)
		if idx == 0:
			break
		else:
			ans += n // l[idx - 1]
			n %= l[idx - 1]
	print(ans)


for i in range(int(input())):
	a = int(input())
	if a < 2:
		print(0)
	else:
		r = 0
		l = [2]
		m = 2
		for k in range(5, a, 3):
			if m > a:
				break
			else:
				m += k
				l.append(m)
		for j in range(len(l) - 1, -1, -1):
			r += a // l[j]
			a = a - l[j] * (a // l[j])
			if a < 2:
				break
		print(r)


a = []
a.append(2)
a.append(7)
i = 1
while True:
	n = a[i] - a[i - 1] + 3 + a[i]
	if n > 10 ** 9:
		break
	else:
		a.append(n)
	i = i + 1
from bisect import bisect_left, bisect_right
for fjll in range(int(input())):
	n = int(input())
	x = 0
	while n > 1:
		m1 = bisect_right(a, n)
		n = n - a[m1 - 1]
		x = x + 1
	print(x)


t = int(input())
ans = []
for i in range(t):
	n = int(input())
	k = 0
	while n >= 2:
		q = int(((1 + 24 * n) ** 0.5 - 1) / 6)
		n = n - q * (q + 1) * 3 // 2 + q
		k += 1
	ans.append(k)
for i in ans:
	print(i)


t = int(input())
for asd in range(t):
	n = int(input())
	out = 0
	while n > 1:
		f = 2
		count = 1
		num = f
		while f <= n:
			count += 1
			num = f
			f = f + (3 * count - 1)
		n = n - num
		out = out + 1
	print(out)


n = int(input())
for _ in range(n):
	n = int(input())
	dp = []
	k = 0
	for i in range(1, int(n // 2) + 1):
		a = (3 * i + 1) * i // 2
		if a <= n:
			dp.append(int(a))
		else:
			break
	i = len(dp) - 1
	c = 0
	while i >= 0 and n > 0:
		if dp[i] <= n:
			n = n - dp[i]
			c += 1
		else:
			i = i - 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	(l, r) = (0, 100005)
	ans = 0

	def cal(x):
		return int((3 * x * x + x) / 2)
	while l <= r and n >= 2:
		if l == r:
			n -= cal(l)
			ans += 1
			(l, r) = (0, l)
		mid = (l + r) // 2
		if cal(mid) > n:
			(l, r) = (l, mid - 1)
		elif cal(mid + 1) > n:
			(l, r) = (mid, mid)
		else:
			(l, r) = (mid + 1, r)
	print(ans)


import bisect
MAX_N = 30000
c = [0] * MAX_N
for i in range(MAX_N - 1):
	c[i + 1] = c[i] + 3 * i + 2

def solve(rem):
	res = 0
	while rem > 0:
		lim_i = bisect.bisect_left(c, rem)
		if c[lim_i] == rem:
			res += 1
			break
		if lim_i - 1 == 0:
			break
		rem -= c[lim_i - 1]
		res += 1
	return res
t = int(input())
for _ in range(t):
	n = int(input())
	print(solve(n))


def pyramid(i):
	return 3 / 2 * i * i + 1 / 2 * i

def solve():
	n = int(input())
	i = 1
	while n >= pyramid(i):
		i += 1
	res = 0
	i -= 1
	while n > 0 and i > 0:
		if n < pyramid(i):
			i -= 1
		else:
			n -= pyramid(i)
			res += 1
	print(res)
t = int(input())
for _ in range(t):
	solve()


from sys import stdin
import math
a = int(stdin.readline())
for b in range(0, a):
	K = int(stdin.readline())
	count = 0
	while K >= 2:
		S = math.floor((math.sqrt(24 * K + 1) - 1) / 6)
		K = K - 3 / 2 * S * S - 1 / 2 * S
		count += 1
	print(count)


from collections import OrderedDict

def card_pyramids(n):
	memo = OrderedDict([(1, 2)])

	def recurse(h):
		nonlocal memo
		if h <= 0:
			return 0
		elif h in memo:
			return memo[h]
		total = 3 * h - 1 + recurse(h - 1)
		memo[h] = total
		return total
	h = 1
	while True:
		req = recurse(h)
		if req <= n:
			memo[h] = req
			h += 1
		else:
			break
	total = 0
	heights = reversed(memo.keys())
	for h in heights:
		req = memo[h]
		if req > n:
			continue
		total += n // req
		n -= n // req * req
	return total
t = int(input())
for _ in range(t):
	n = int(input())
	ans = card_pyramids(n)
	print(ans)


for _ in range(int(input())):
	f = int(input())
	n = int(f ** 0.5 + 1)
	c = 0
	while f >= 2:
		x = (3 * n * n + n) // 2
		if x <= f:
			c += 1
			f -= x
			n = int(f ** 0.5)
		else:
			n -= 1
	print(c)


def f(k):
	return 3 * (k + 1) * k // 2 - k
N = int(input())

def solve(n):
	built = 0
	while n >= 2:
		(lo, hi) = (1, n)
		while hi - lo > 1:
			mid = (hi + lo) // 2
			if f(mid) <= n:
				lo = mid
			else:
				hi = mid
		n -= f(lo)
		built += 1
	return built
for _ in range(N):
	print(solve(int(input())))


def p(n):
	return n * (n + 1) + n * (n - 1) // 2
h = [0]
for i in range(1, 25821):
	h.append(p(i))
t = int(input())
for _ in range(t):
	n = int(input())
	ct = 0
	z = 25820
	while n > 1:
		for i in range(z, 0, -1):
			if h[i] <= n:
				ct += 1
				n -= h[i]
				z = i
				break
	print(ct)


t = int(input())
for tt in range(t):
	x = int(input())
	temp = x
	cc = 0
	while temp > 0:
		start = 0
		end = temp
		ans = 0
		while start <= end:
			mid = start + (end - start) // 2
			xx = mid * (3 * mid + 1) // 2
			if xx <= temp:
				start = mid + 1
				ans = max(ans, mid)
			else:
				end = mid - 1
		if ans == 0:
			break
		temp -= ans * (3 * ans + 1) // 2
		cc += 1
	print(cc)


j = int(input())
a = []
for i in range(j):
	n = int(input())
	s = 0
	k = 0
	x = 0
	while n >= 2:
		while s <= n:
			l = 2 + 3 * x
			s += l
			x += 1
		s -= l
		n -= s
		k += 1
		s = 0
		x = 0
	a.append(k)
for i in a:
	print(i)


maxn = 25830
pirs = [0] * maxn
for k in range(1, maxn - 1):
	pirs[k] = pirs[k - 1] + 2 * k + k - 1

def getmax(n):
	for j in range(maxn):
		if pirs[j] > n:
			return n - pirs[j - 1]
	return 0
T = int(input().strip())
for t in range(T):
	n = int(input().strip())
	res = 0
	while n >= 2:
		res += 1
		n = getmax(n)
	print(res)


from math import *
t = int(input())
m = []
n = []
for i in range(t):
	x = list(map(int, input().split()))
	m.append(x)
for i in range(t):
	x = m[i][0]
	count = 0
	while x > 1:
		hp = floor((-1 + sqrt(1 + 24 * x)) / 6)
		x = x - hp * (3 * hp + 1) / 2
		count = count + 1
	print(count)


from math import sqrt, floor, ceil

def fun(k):
	return (sqrt(1 + 24 * k) - 1) / 6

def solve():
	n = int(input())
	p = fun(n)
	if floor(p) == ceil(p):
		print(1)
	else:
		res = 0
		while n > 1:
			res += 1
			h = floor(p)
			n -= h * (1 + h) + h * (h - 1) / 2
			p = fun(n)
		print(res)
t = int(input())
for _ in range(t):
	solve()


from collections import Counter, defaultdict, deque
import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	mem = [2]
	res = 0
	i = 2
	while mem[-1] <= n:
		mem.append(i * (3 * i + 1) // 2)
		i += 1
	for el in reversed(mem):
		while n >= el:
			n -= el
			res += 1
	print(res)
tt = int(input())
for test in range(tt):
	solve()


from math import sqrt

def PyramidSize(h):
	return int(1.5 * h ** 2 + 0.5 * h)

def PyramidHeight(n):
	return int((-1 + sqrt(1 + 24 * n)) / 6)
t = int(input())
results = []
for i in range(t):
	n = int(input())
	c = 0
	while n > 0 and PyramidHeight(n) > 0:
		c += 1
		h = PyramidHeight(n)
		n -= PyramidSize(h)
	results.append(c)
for i in range(t):
	print(results[i])


def find(val):
	pre = 0
	for i in range(100000):
		y = i * (3 * i + 1) // 2
		if y > val:
			break
		pre = y
	return [val - pre, pre]
T = int(input())
for t in range(T):
	val = int(input())
	count = 0
	p = 1
	while p:
		(val, p) = find(val)
		if val >= 0 and p > 0:
			count += 1
		else:
			break
	print(count)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline().rstrip()
res = ['YES', 'NO']

def bin_search(val):
	(pos, l, r) = (0, 0, 25821)
	while l <= r:
		m = (l + r) // 2
		if a[m] <= val:
			pos = m
			l = m + 1
		else:
			r = m - 1
	return pos
a = []
x = 0
c = 1
while x <= 100000 + 10 ** 9:
	a.append(x)
	x += c - 1 + c * 2
	c += 1
test_case = ii()
while test_case:
	test_case -= 1
	n = ii()
	ans = 0
	while n > 1:
		n -= a[bin_search(n)]
		ans += 1
	print(ans)


input = __import__('sys').stdin.readline
print = __import__('sys').stdout.write

def f(k):
	return int((-1 + (1 + 24 * k) ** 0.5) / 2) + 2
pyramid = [(3 * i ** 2 + i) // 2 for i in range(0, 40000)]
for _ in range(int(input())):
	N = int(input())
	t = 0
	i = min(f(N), 39999)
	while N and i:
		if N >= pyramid[i]:
			tmp = N // pyramid[i]
			t += tmp
			N = N % pyramid[i]
		i -= 1
	print(f'{t}\n')


t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		x = 1
		while x * (3 * x + 1) // 2 < n:
			x += 1
		if x * (3 * x + 1) // 2 > n:
			x -= 1
		n -= x * (3 * x + 1) // 2
		ans += 1
	print(ans)


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	if n == 1:
		print(0)
	elif n < 7:
		print(n // 2)
	else:
		dp = []
		i = 1
		k = 0
		while k < n:
			k = i * (i + 1) + i * (i - 1) // 2
			dp.append(k)
			i += 1
		i -= 2
		if dp[i] > n:
			dp.remove(dp[i])
		su = dp[len(dp) - 1]
		cnt = 1
		x = n - su
		while x >= dp[0]:
			for i in range(n):
				if dp[i] > x:
					x = x - dp[i - 1]
					cnt += 1
					break
				elif dp[i] == x:
					x = x - dp[i]
					cnt += 1
					break
		print(cnt)


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	while True:
		D = 0.25 + 6 * n
		x = (-0.5 + D ** 0.5) // 3
		if x > 0:
			count += 1
		else:
			break
		n -= 0.5 * x + 1.5 * x ** 2
	print(count)


def max_tower(n):
	tower = 2
	step = 5
	while tower <= n:
		tower += step
		step += 3
	else:
		return tower - (step - 3)
for _ in range(int(input())):
	n = int(input())
	counter = 0
	while n >= 2:
		n -= max_tower(n)
		counter += 1
	print(counter)


def next(arr, target, end):
	start = 0
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] > target:
			end = mid - 1
		else:
			ans = mid
			start = mid + 1
	return ans
l = [0, 2]
s = 2
x = 2
i = 1
while i < 25820:
	x += 3
	s += x
	l.append(s)
	i += 1
for j in range(int(input())):
	x = int(input())
	c = 0
	while x > 1:
		x -= l[next(l, x, 25821)]
		c += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	pyr = 0
	if n == 1:
		print(pyr)
	else:
		while n > 1:
			h = int((-1 + (1 + 24 * n) ** 0.5) / 6)
			pyr += 1
			n -= h * (3 * h + 1) / 2
		print(pyr)


t = int(input())

def used_cards(n):
	h = 0
	while n >= h * (h + 1) + h * (h - 1) // 2:
		h += 1
	return (h - 1) * h + (h - 1) * (h - 2) // 2

def max_piramids(n):
	count = 0
	while n != 0 and n != 1:
		n -= used_cards(n)
		count += 1
	return count
for i in range(t):
	n = int(input())
	print(max_piramids(n))


import sys, math, cmath, time
start_time = time.time()
tt = 0

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def solve():
	t = inp()
	a = [2]
	i = 2
	while a[-1] <= 10 ** 9:
		a.append(3 * i - 1 + a[-1])
		i = i + 1
	a.pop()
	a.reverse()
	for tt in range(t):
		n = inp()
		c = 0
		i = 0
		while i < len(a):
			if a[i] <= n:
				c = c + 1
				n = n - a[i]
				if n <= 6:
					c = c + n // 2
					break
			else:
				i = i + 1
		print(c)

def main():
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
	sys.stdout.close()

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


def countPyramids(n):
	if n < 2:
		return 0
	p = 0
	for i in range(1, n):
		p += 2 * i + i - 1
		if p == n:
			return 1
		if p > n:
			p -= 2 * i + i - 1
			return 1 + countPyramids(n - p)
	return 0
t = int(input())
for _ in range(t):
	n = int(input())
	if n < 2:
		print(0)
	else:
		print(countPyramids(n))


import sys
from math import sqrt
sys.setrecursionlimit(10 ** 6)

def dfs(n):
	x = int((-1 + sqrt(1 + 24 * n)) / 6)
	return (3 * x * x + x) // 2

def f(n):
	ret = 0
	while n >= 2:
		ret += 1
		n -= dfs(n)
	return ret
nofkase = int(input())
for kase in range(nofkase):
	n = int(input())
	print(f(n))


def f(x):
	return (3 * x * x + x) / 2

def construct(n):
	if n < 2:
		return 0
	i = 1
	while f(i) < n:
		i += 1
	if f(i) == n:
		return 1
	else:
		return 1 + construct(n - f(i - 1))
t = int(input())
for _ in range(t):
	n = int(input())
	print(construct(n))


from sys import *
from math import *
from bisect import *
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())

	def f(n):
		k = n * (n + 1) + n * (n - 1) // 2
		return k
	ans = 0
	while 1:
		if n <= 1:
			break
		l = 0
		h = n
		x = 0
		while l <= h:
			m = (l + h) // 2
			o = f(m)
			if f(m) > n:
				h = m - 1
			else:
				l = m + 1
				x = f(m)
		n -= x
		ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		ans += 1
		card = 2
		while n >= card:
			n -= card
			card += 3
	print(ans)


cases = int(input())
for i in range(cases):
	total = int(input())
	pyramids = 0
	while total > 1:
		c_need = 2
		n = 2
		while c_need <= total:
			c_need += 3 * n - 1
			n += 1
		c_need -= 3 * (n - 1) - 1
		pyramids += 1
		total -= c_need
	print(pyramids)


def get_closest_binary(num, l):
	if num in l:
		return num
	elif num > l[-1]:
		return l[-1]
	elif num < l[0]:
		return 0
	else:
		m = 0
		ma = len(l) - 1
		while ma - m > 1:
			if num > l[m + (ma - m) // 2]:
				m += (ma - m) // 2
			else:
				ma -= (ma - m) // 2 + 1
		if num > l[ma]:
			return l[ma]
		else:
			return l[m]
all_possible = []
i = 1
n = 0
while n < 10 ** 9:
	n += 3 * i - 1
	all_possible.append(n)
	i = i + 1
t = int(input())
while t:
	t -= 1
	f = int(input())
	c = 0
	while f > 1:
		f = f - get_closest_binary(f, all_possible)
		c = c + 1
	print(c)


def cardsnumber(h):
	return 3 * (h * (h + 1)) // 2 - h

def process(n, answer):
	for i in range(n + 1):
		if n < 2:
			print(answer)
			break
		elif n <= cardsnumber(i):
			answer += 1
			if n == cardsnumber(i):
				n -= cardsnumber(i)
				process(n, answer)
				break
			else:
				n -= cardsnumber(i - 1)
				process(n, answer)
				break
t = int(input())
for i in range(t):
	n = int(input())
	process(n, 0)


A = []
a = 2
dif = 5
while a <= 1000000000:
	A.append(a)
	a += dif
	dif += 3
A.append(a)
t = int(input())
for _ in range(t):
	n = int(input())
	cnt = 0
	while n >= 2:
		i = 0
		while A[i] <= n:
			i += 1
		n -= A[i - 1]
		cnt += 1
	print(cnt)


t = int(input())
arr = []
for i in range(t):
	cards = int(input())
	if cards == 2:
		arr.append(1)
		continue
	elif cards <= 2:
		arr.append(0)
		continue
	pyramids = 0
	while cards >= 2:
		cards_used = 0
		add = 2
		while cards_used <= cards:
			cards_used += add
			add += 3
		cards -= cards_used - add + 3
		pyramids += 1
	arr.append(pyramids)
for i in arr:
	print(i)


import bisect
t = int(input())
l = []
n = 2
l.append(2)
for x in range(2, 25822):
	n += 3 * x - 1
	l.append(n)
for n in range(t):
	a = int(input())
	ans = 0
	while True:
		tallest = bisect.bisect(l, a)
		a = a - l[tallest - 1]
		if a > 0:
			ans += 1
		elif a < 0:
			print(ans)
			break
		else:
			ans += 1


arr = []
arr.append(2)
max = arr[-1]
i = 2
while max < 10 ** 9:
	arr.append(arr[-1] + 3 * i - 1)
	max = arr[-1]
	i += 1

def bs(n):
	l = 0
	r = len(arr) - 1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == n:
			return arr[mid]
		elif arr[mid] < n:
			l = mid + 1
		else:
			r = mid - 1
	if arr[mid] > n:
		return arr[mid - 1]
	return arr[mid]
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n >= 2:
		n = n - bs(n)
		ans += 1
	print(ans)


from math import sqrt
t = int(input())
for _ in range(t):
	n = int(input())
	pyramids = 0
	while n > 1:
		h = (sqrt(1 + 24 * n) - 1) // 6
		cards_used = (3 * h ** 2 + h) // 2
		n -= cards_used
		pyramids += 1
	print(pyramids)


def card(n):
	if n == 1:
		return 0
	else:
		x = 2
		l = [2]
		step = 5
		while x < n:
			x += step
			if x <= n:
				l.insert(0, x)
			step += 3
		c = 0
		for i in l:
			c += n // i
			n = n % i
			if n < 2:
				break
		return c
for _ in range(int(input())):
	n = int(input())
	print(card(n))


def get_primeFactor(n):
	res = [1]
	x = 2
	while x * x <= n:
		while n % x == 0:
			res.append(x)
			n //= x
		x += 1
	if n > 1:
		res.append(n)
	return res

def getFactor(n):
	res = {1}
	x = 2
	while x * x <= n:
		if n % x == 0:
			res.add(x)
			res.add(n // x)
		x += 1
	return res
for _ in range(int(input())):
	n = int(input())
	lo = 1
	hi = n
	ans = 0
	while n > 1:
		while lo < hi:
			mid = (lo + hi) // 2
			if n >= mid * (3 * mid + 1) // 2:
				lo = mid + 1
			else:
				hi = mid
		ans += 1
		n -= (lo - 1) * (3 * (lo - 1) + 1) // 2
		lo = 1
		hi = n
	print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	h = 1
	p = 0
	while h != 0:
		h = int((math.sqrt(1 + 24 * n) - 1) / 6)
		if h == 0:
			break
		else:
			p += 1
		n += -(h * (3 * h + 1) // 2)
	print(p)


t = int(input())
while t:
	t = t - 1
	n = int(input())
	c = 0
	while n > 1:
		k = 2
		while n >= k:
			n = n - k
			k = k + 3
		c = c + 1
	print(c)


for s in [*open(0)][1:]:
	n = int(s)
	x = 0
	while n > 1:
		k = 2
		while n >= k:
			n -= k
			k += 3
		x += 1
	print(x)


def h(n):
	x = 2 * n
	y = 3 * (n - 1) * n
	y //= 2
	return x + y

def main(n):
	if n <= 1:
		return 0
	dp = [h(1)]
	x = 1
	while dp[-1] <= n:
		x += 1
		dp.append(h(x))
	if dp == []:
		return 0
	i = len(dp) - 1
	proc = n
	ans = 0
	while i > -1 and proc:
		if proc < dp[i]:
			i -= 1
		else:
			ans += 1
			proc -= dp[i]
	return ans
n = int(input())
for i in range(n):
	x = int(input())
	print(main(x))


for _ in range(int(input())):
	n = int(input())
	count = 0
	for i in range(10 ** 5):
		if n < 2:
			break
		else:
			count += 1
			height = int((-1 + (1 + 24 * n) ** 0.5) / 6)
			cards_needed = (3 * (height * height) + height) // 2
			n -= cards_needed
	print(count)


from bisect import bisect_left
t = int(input())

def lowerbound(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	else:
		return len(a) - 1
sticks = [0, 2]
i = 2
while i <= 50000:
	x = sticks[i - 1] + 5 + 3 * (i - 2)
	sticks.append(x)
	i += 1
while t > 0:
	n = int(input())
	i = n
	pyramid = 0
	while i > 1:
		pos = next((x for (x, val) in enumerate(sticks) if val > i))
		if sticks[pos] > i:
			pos -= 1
		i -= sticks[pos]
		pyramid += 1
	print(pyramid)
	t -= 1


import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = pow(10, 9) + 7

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def x(i):
	return i * (i + 1) + i * (i - 1) / 2

def solve():
	n = int(inp())
	cnt = 0
	while n > 1:
		i = 1
		while x(i) <= n:
			i += 1
		n = n - x(i - 1)
		cnt += 1
	print(cnt)
testcase(int(inp()))


from bisect import bisect_right
Answers = []
Index = 1
while True:
	Temp = Index - 1
	Need = Temp * (Temp + 1) // 2 * 3 + Index * 2
	Answers.append(Need)
	if Need > 10 ** 9:
		break
	Index += 1
for _ in range(int(input())):
	Count = 0
	N = int(input())
	while N >= 2:
		Index = bisect_right(Answers, N)
		Count += 1
		N -= Answers[Index - 1]
	print(Count)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	card = int(input())
	cnt = 0
	while card > 1:
		tmp = 0
		base = -1
		while tmp <= card:
			base += 3
			tmp += base
		if tmp > card:
			card -= tmp - base
		else:
			card -= tmp
		cnt += 1
	print(cnt)


from math import sqrt

def f(k):
	n = int((-1 + sqrt(1 + 24 * k)) / 6)
	return (3 * n * n + n) // 2
t = int(input())
for _ in range(t):
	n = int(input())
	i = 0
	while n > 1:
		n -= f(n)
		i += 1
	print(i)


t = int(input())
for j in range(t):
	n = int(input())
	c = 0
	while n >= 2:
		d = 1
		while (3 * (d * d) + d) // 2 <= n:
			d += 1
		d -= 1
		n -= (3 * (d * d) + d) // 2
		c += 1
	print(c)


for ii in range(int(input())):
	n = int(input())
	x = n
	aa = 0
	ss = 2
	s = 2
	gg = 2
	while n >= 2:
		while True:
			if ss > n:
				aa += 1
				n = n - gg
				ss = 2
				s = 2
				break
			elif ss == n:
				aa += 1
				n = n - ss
				break
			s += 3
			gg = ss
			ss = ss + s
	print(aa)


from __future__ import division, print_function
import os, sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(arr):
	return collections.Counter(arr)

def main():
	for _ in range(ii()):
		n = ii()
		cou = 0
		sel = 0
		for i in range(n):
			if n <= 1:
				print(cou)
				break
			if n == 2:
				print(cou + 1)
				break
			j = 1
			sel = 2
			while n > sel:
				if sel + (3 * j + 2) > n:
					break
				sel += 3 * j + 2
				j += 1
			n -= sel
			cou += 1
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


T = int(input())
n = [0] * T
for t in range(T):
	n[t] = int(input())

def bign(n):
	if n <= 2:
		return 0
	h0 = int((n * 2) ** 0.5)
	while 1.5 * h0 * h0 + 0.5 * h0 > n:
		h0 -= 1
	k = n - (1.5 * h0 * h0 + 0.5 * h0)
	if k < 2:
		return 0
	return k

def ans(n):
	tos = 1
	if n == 2:
		return 1
	elif n <= 1:
		return 0
	n = bign(n)
	while n != 0:
		tos += 1
		n = bign(n)
	return tos
for t in range(T):
	print(ans(n[t]))


import math
t = int(input())
while t > 0:
	n = int(input())
	count = 0
	while n >= 2:
		h = (-1 + math.sqrt(1 + 24 * n)) // 6
		n -= (3 * h + 1) * h // 2
		count += 1
	print(count)
	t -= 1


c = [0] * 100000
c[1] = 2
for i in range(2, 100000):
	c[i] = c[i - 1] + i - 1 + 2 * i
for _ in range(int(input())):
	n = int(input())
	ans = 0
	if n == 1:
		print(0)
		continue
	while n > 1:
		i = 1
		while True:
			if c[i] >= n:
				break
			else:
				i += 1
		if c[i] == n:
			ans += 1
			n = n - c[i]
			break
		elif c[i] > n:
			ans += 1
			n = n - c[i - 1]
	print(ans)


from collections import Counter
import math
mod = 10 ** 9 + 7
ans = []
for i in range(int(input())):
	n = int(input())
	f = 0
	while n > 1:
		i = 0
		while 1:
			if i * (3 * i + 1) // 2 > n:
				f += 1
				x = i - 1
				n -= x * (3 * x + 1) // 2
				break
			else:
				i += 1
	print(f)


cases = int(input())
for _ in range(cases):
	n = int(input())
	count = 0
	while n > 1:
		r = 2
		f = 2
		while n >= r:
			pr = r
			r += f * 2 + f - 1
			f += 1
		count += 1
		n -= pr
	print(count)


import sys
sys.setrecursionlimit(2000)
from collections import Counter
from functools import reduce
t = [int(val) for val in sys.stdin.readline().split()][0]
for test in range(t):
	n = [int(val) for val in sys.stdin.readline().split()][0]
	count = 0
	while n > 1:
		m0 = 2
		m1 = 7
		c = 3
		while m1 <= n:
			m0 = m1
			m1 = c * (3 * c + 1) // 2
			c += 1
		n -= m0
		count += 1
	print(count)


import sys
import bisect
try:
	sys.stdin = open(sys.path[0] + '\\input.txt', 'r')
	sys.stdout = open(sys.path[0] + '\\output.txt', 'w')
except FileNotFoundError:
	pass
dp = [0, 2]
for i in range(2, 1000001):
	val = dp[-1] + (i - 1) + 2 * i
	dp.append(val)
	if dp[-1] > 10 ** 9:
		break
for tc in range(int(input())):
	n = int(input())
	cnt = 0
	while n > 1:
		pos = bisect.bisect(dp, n)
		if dp[pos] != n:
			pos -= 1
		n -= dp[pos]
		cnt += 1
	print(cnt)


class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi
from math import gcd

def lcm(a, b):
	return a * b // gcd(a, b)
s = 0
of = []
for i in range(1, 30000):
	s += i
	tt = i ** 2
	of += [s * 2 + tt - s]
from bisect import bisect_right, bisect_left
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		next = bisect_left(of, n + 1) - 1
		n -= of[next]
		ans += 1
	print(ans)


def R():
	return map(int, input().split())

def I():
	return int(input())

def S():
	return str(input())

def L():
	return list(R())
from collections import Counter
import math
import sys
from itertools import permutations
import bisect
for _ in range(I()):
	n = I()
	ans = 0
	while int((-1 / 3 + math.sqrt(1 / 9 + 8 * n / 3)) / 2 + 1e-09) != 0:
		ans += 1
		h = int((-1 / 3 + math.sqrt(1 / 9 + 8 * n / 3)) / 2 + 1e-09)
		n -= int(3 / 2 * h ** 2 + h / 2)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	pyramids = 0
	height = 1
	cards = 2
	while cards <= n:
		a = (height + 1) * 2 + height
		if cards + a <= n:
			cards += a
			height += 1
		else:
			n -= cards
			pyramids += 1
			height = 1
			cards = 2
	print(pyramids)


INT_MAX = 10 ** 19 + 7
MOD = 10 ** 12 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]
import bisect
z = 1000000
dpheight = [0] * z
for i in range(1, z):
	dpheight[i] = (3 * i + 1) * i // 2
for _ in range(int(input())):
	cards = int(input())
	ans = 0
	while cards > 1:
		h = bisect.bisect_left(dpheight, cards, 0, z) - 1
		if dpheight[h + 1] == cards:
			h += 1
		cards -= dpheight[h]
		ans += 1
	print(ans)


T = int(input())
for tc in range(T):
	n = int(input())
	count = 0
	while n >= 2:
		h = (-1 + (1 + 24 * n) ** 0.5) // 6
		stack_cards = (3 * h ** 2 + h) // 2
		count += 1
		n = n - stack_cards
	print(count)


import bisect
pyramids = [0]
for i in range(1, 10 ** 5):
	tmp = 2 * i * (i + 1) // 2 + i * (i - 1) // 2
	pyramids.append(tmp)
t = int(input())
for _ in range(t):
	n = int(input())
	cnt = 0
	pos = bisect.bisect_right(pyramids, n) - 1
	while pos != 0:
		cnt += 1
		n -= pyramids[pos]
		pos = bisect.bisect_right(pyramids, n) - 1
	print(cnt)


import math as mt

def sm(k):
	s = k * (4 + (k - 1) * 3) // 2
	return s

def main():
	for _ in range(int(input())):
		n = int(input())
		count = 0
		while n > 1:
			k = (-1 + int(mt.sqrt(1 + 24 * n))) // 6
			n = n - sm(k)
			count += 1
		print(count)
main()


def binary_search(n):
	left = 0
	right = int(n ** (1 / 2))
	while left <= right:
		mid = left + (right - left) // 2
		solve = mid * (3 * mid + 1) // 2
		if solve <= n < (mid + 1) * (3 * mid + 4) // 2:
			return solve
			break
		if solve < n:
			left = mid + 1
		else:
			right = mid - 1
test = int(input())
for _ in range(test):
	n = int(input())
	count = 0
	while n >= 2:
		n -= binary_search(n)
		count += 1
	print(count)


t = int(input())
a = []
use = 0
cnt = 1
while use < 10 ** 9:
	use = (3 * cnt ** 2 + cnt) // 2
	a.append(use)
	cnt += 1
a = [0] + a
import bisect
for i in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		want = bisect.bisect_right(a, n) - 1
		n -= a[want]
		ans += 1
	print(ans)


t = int(input())
for test in range(t):
	n = int(input())
	count = 0
	while n > 1:
		need = 2
		while n >= need:
			n -= need
			need += 3
		count += 1
	print(count)


from bisect import bisect_left
T = int(input())
pyramids = [3 * n * (n - 1) // 2 + 2 * n for n in range(1, 10 ** 5)]
for t in range(T):
	n = int(input())
	ans = 0
	while n >= 2:
		i = bisect_left(pyramids, n + 0.5)
		n -= pyramids[i - 1]
		ans += 1
	print(ans)


t = int(input())
for test_no in range(t):
	x = int(input())
	c = 0
	while x >= 2:
		n = 1
		while int(n * (n + 1) + n * (n - 1) / 2) <= x:
			n += 1
		x -= int(n * (n - 1) + (n - 2) * (n - 1) / 2)
		c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		ans += 1
		base = 2
		while n - base >= 0:
			n -= base
			base += 3
	print(ans)


import math as m
list_lelo = lambda : list(map(int, input().split()))
int_lelo = lambda : int(input())
for i in range(int_lelo()):
	cards = int_lelo()
	count = 0
	while cards >= 2:
		h = (-1 + m.sqrt(1 + 24 * cards)) // 6
		cards -= (3 * h * h + h) // 2
		count += 1
	print(count)


from collections import deque, defaultdict, Counter
from bisect import bisect_left, bisect
import math
p = []

def fun(n):
	return 3 * (n * (n - 1) // 2) + 2 * n

def test_case():
	n = int(input())
	count = 0
	while n > 0:
		ind = bisect(p, n)
		if ind > 0:
			count += 1
		else:
			break
		n -= p[ind - 1]
	return count
new = 0
i = 1
while new <= 10 ** 9:
	tmp = fun(i)
	p.append(tmp)
	i += 1
	new = tmp
for _ in range(int(input())):
	ret = test_case()
	if ret != None:
		print(ret)


import math
for ad in range(int(input())):
	n = int(input())
	c = 0
	while n >= 2.0:
		h = math.floor(((1 + 24 * n) ** 0.5 - 1) / 6)
		n -= h * (3 * h + 1) / 2
		c += 1
	print(c)


import sys

def I():
	return sys.stdin.readline().rstrip()
N = 1000000000
L = 25820
d2 = 1
while d2 <= L:
	d2 *= 2

def sm(n):
	return n * (n + 1) // 2

def tri(n):
	return 2 * sm(n) + sm(n - 1) if n > 0 else 0

def largest(n):
	i = 0
	d = d2
	while d:
		j = i + d
		if j <= L and tri(j) <= n:
			i = j
		d //= 2
	return tri(i)
for _ in range(int(I())):
	n = int(I())
	c = 0
	while n > 1:
		n -= largest(n)
		c += 1
	print(c)


d = [0]
h = 0
while d[-1] <= 1000000000:
	h += 1
	d.append(d[-1] + 3 * h - 1)

def pyr(n):
	global d
	l = 0
	r = len(d)
	while l < r - 1:
		c = (l + r) // 2
		if n < d[c]:
			r = c
		else:
			l = c
	return l
t = int(input())
for qq in range(t):
	n = int(input())
	r = 0
	while n > 1:
		r += 1
		f = pyr(n)
		n -= d[f]
	print(r)


from math import floor as f

def maxn(m):
	n = f(pow(2 * m / 3, 0.5))
	c = (3 * n + 1) * n // 2
	if c > m:
		n = n - 1
		c = (3 * n + 1) * n // 2
	return m - c
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n >= 2:
		n = maxn(n)
		c += 1
	print(c)


n = int(input())
L = [2, 7]
S = 8
for i in range(1, 100000):
	L.append(L[i] + S)
	S += 3
for i in range(0, n):
	o = int(input())
	tot = 0
	while 1:
		I = 0
		V = -1
		J = len(L) - 1
		while I <= J:
			m = (I + J) // 2
			if L[m] > o:
				J = m - 1
			else:
				V = m
				I = m + 1
		if V != -1:
			tot += 1
			o -= L[V]
		else:
			break
	print(tot)


t = int(input())
while t:
	n = int(input())
	if n <= 1:
		print(0)
	else:
		val = 2
		dp = []
		dp.append(val)
		if n <= 1:
			print(0)
		i = 1
		while val < n:
			dp.append(val + (2 + 3 * i))
			val = val + (2 + 3 * i)
			i += 1
		if dp[-1] > n:
			n -= dp[-2]
		else:
			n -= dp[-1]
		count = 1
		while n >= 2:
			for i in range(len(dp)):
				if n <= dp[i]:
					if n == dp[i]:
						count += 1
						n = 0
						break
					else:
						n -= dp[i - 1]
						count += 1
						break
		print(count)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	c = 0
	if n > 1:
		a = 0
		while n > 1:
			b = 1
			p = True
			while p:
				if b * 2 <= n:
					n -= b * 2
					if n < (b + 1) * 2 + b:
						p = False
					else:
						n -= b
				else:
					p = False
				b += 1
			c += 1
		print(c)
	else:
		print('0')


from math import sqrt

def main():
	t = int(input())
	for __ in range(t):
		n = int(input())
		count = 0
		while n >= 2:
			count += 1
			h = int((sqrt(24 * n + 1) - 1) / 6)
			n -= h * (3 * h + 1) // 2
		print(count)
main()


import bisect
t = int(input())
const = [(3 * (i + 1) ** 2 + i + 1) // 2 for i in range(33000)]
for i in range(t):
	n = int(input())
	cnt = 0
	while n >= 2:
		d = bisect.bisect_right(const, n)
		n -= const[d - 1]
		cnt += 1
	print(cnt)


import heapq as hp
import collections
import bisect
import math
import re

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int):
	return sorted(map(func, input().split()))

def ml_unpack(n):
	return [int(input()) for i in range(n)]

def range_n():
	return range(int(input()))

def getint():
	return int(input())

def counter(a):
	d = {}
	for x in a:
		if x in d:
			d[x] += 1
		else:
			d[x] = 1
	return d

def main():
	cards = lambda height: (3 * height + 1) * height // 2
	heights = [0] * 50000
	for i in range(len(heights)):
		heights[i] = cards(i)
	for _ in range_n():
		n = getint()
		ans = 0
		while True:
			if n <= 1:
				break
			k = bisect.bisect(heights, n)
			n -= heights[k - 1]
			ans += 1
		print(ans)
main()


a = [2]
i = 0
while a[i] < 10 ** 9:
	a.append(a[i] + 5 + 3 * i)
	i += 1
for i in range(int(input())):
	am = 0
	n = int(input())
	while n > 1:
		j = 0
		while a[j] <= n:
			j += 1
		n -= a[j - 1]
		am += 1
	print(am)


import bisect
s = []
a = 0
while a < 100000:
	p = a * (3 * a + 1) // 2
	s.append(p)
	a += 1
s = s[1:]
test = [10 ** 9 for i in range(1000)]
n = int(input())
for i in range(n):
	m = int(input())
	ans = 0
	best = 0
	while m > 1:
		p1 = bisect.bisect_left(s, m, lo=0, hi=len(s))
		if s[p1] == m:
			m -= s[p1]
			ans += 1
		else:
			m -= s[p1 - 1]
			ans += 1
	print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
import math
import bisect
abc = 'abcdefghijklmnopqrstuvwxyz'

def main():
	l = []
	s = 0
	for n in range(1, 30000):
		l.append(n * (3 * n + 1) // 2)
	for _ in range(ii()):
		n = ii()
		ans = -1
		while n >= 0:
			c = bisect.bisect(l, n)
			n -= l[c - 1]
			ans += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def binSearch(arr, z):
	start = 0
	end = len(arr) - 1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] > z:
			end = mid - 1
		else:
			start = mid + 1
	return arr[end]
t = int(input())
arr = [0]
inf = 10 ** 9
h = 1
while arr[-1] < inf:
	arr.append(arr[-1] + 3 * h - 1)
	h += 1
for _ in range(t):
	n = int(input())
	count = 0
	while n > 1:
		n -= binSearch(arr, n)
		count += 1
	print(count)


for i in range(int(input())):
	n = int(input())
	res = 0
	while n > 1:
		c = 5
		t = 2
		while n >= t:
			n -= t
			t = c
			c += 3
		res += 1
	print(res)


t = int(input())
p = []
import math
for i in range(t):
	n = int(input())
	c = 0
	while n > 1:
		h = (-1 + math.sqrt(1 + 24 * n)) // 6
		h = int(h)
		n -= int(h * (3 * h + 1) / 2) % (10 ** 9 + 7)
		c += 1
	print(c)


import random
import math
LI = lambda : list(map(int, input().split()))
MI = lambda : map(int, input().split())
yes = lambda : print('Yes')
no = lambda : print('No')
I = lambda : list(input())
J = lambda x: ''.join(x)
II = lambda : int(input())
SI = lambda : input()
t = II()
l = [2]
ma = 10 ** 9
i = 2
while l[-1] <= ma:
	l.append(l[-1] + l[0] * i + i - 1)
	i += 1
l = l[:][::-1]
for q in range(t):
	n = II()
	count = 0
	while n > 1:
		for i in range(len(l)):
			if l[i] <= n:
				count += n // l[i]
				n %= l[i]
				break
	print(count)


for _ in range(int(input())):
	cnt = 0
	n = int(input())
	while n > 1:
		i = 1
		(z, d) = (0, 0)
		while i * (3 * i + 1) <= 2 * n:
			i += 1
		i -= 1
		z = i * (3 * i + 1) // 2
		d = n // z
		cnt += d
		n -= z * d
	print(cnt)


import math

def card_pyramid(n):
	return (3 * n * n + n) / 2

def return_height(k):
	d = math.sqrt(24 * k + 1)
	d -= 1
	d /= 6
	d = int(d)
	return d
t = int(input())
for i in range(t):
	number_of_cards = int(input())
	count = 0
	while number_of_cards > 1:
		height = return_height(number_of_cards)
		required_cards = card_pyramid(height)
		number_of_cards -= required_cards
		count += 1
	print(count)


import math
for i in range(int(input())):
	n = int(input())
	if n < 2:
		print(0)
	elif n >= 2 and n < 7:
		print(math.floor(n / 2))
	else:
		y = 0
		while n >= 7:
			y += 1
			x = math.floor((-1 + math.sqrt(1 + 24 * n)) / 6)
			z = math.floor(x * (3 * x + 1) / 2)
			n = n - z
		if n <= 7 and n >= 2:
			y += math.floor(n / 2)
		print(y)


import sys, math

def compute(n):
	upper = n - 1
	upper = upper * (upper + 1) // 2
	upper = upper * 3
	return upper + n * 2

def binary(n):
	l = 1
	h = n
	m = (l + h) // 2
	while 1:
		x = compute(m)
		r = compute(m + 1)
		z = compute(m - 1)
		if x > n:
			h = m
		if x < n:
			l = m
		if x == n:
			return x
		if z < n < x:
			return z
		if x < n < r:
			return x
		m = (l + h) // 2

def ans(n):
	s = 0
	while n >= 2:
		od = n // binary(n)
		s += od
		n -= binary(n) * od
	return s
t = int(input())
for _ in range(t):
	n = int(input())
	print(ans(n))


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def solve():
	n = int(input())
	ans = 0
	while n != 0 or n != 1:
		temp = bisect.bisect_left(cards, n)
		if temp != 0:
			if n < cards[temp]:
				n -= cards[temp - 1]
			else:
				n -= cards[temp]
		elif n == 2:
			n -= 2
		else:
			break
		ans += 1
	print(ans)
cards = [2]
summ = [2]
j = 1
total = 2
while total <= 10 ** 15:
	summ.append(summ[j - 1] + (j + 1) * 2 + j)
	cards.append(summ[j])
	total += summ[j]
	j += 1
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for i in range(t):
	n = int(input())
	cnt = 0
	while n >= 2:
		val = int((-1 + (24 * n + 1) ** 0.5) / 6)
		sum1 = val * (3 * val + 1) / 2
		n -= sum1
		cnt += 1
	print(cnt)


for _ in range(int(input())):
	x = int(input())
	ans = 0
	while x > 0:
		u = int((24 * x + 1) ** 0.5 - 1) // 6
		l = max(-int((24 * x + 1) ** 0.5 + 1) // 6, 0)
		if u - l <= 0:
			break
		temp = (3 * (u * u) + u) // 2
		if temp > x:
			u -= 1
			x -= (3 * (u * u) + u) // 2
		else:
			x -= temp
		ans += 1
	print(ans)


from math import *

def PLUS_ULTRA(n):
	ret = floor(sqrt(24 * n + 1)) - 1
	ret //= 6
	return ret
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		ans += 1
		x = PLUS_ULTRA(n)
		tmp = 3 * pow(x, 2) + x
		tmp //= 2
		n -= tmp
	print(ans)


def pyra(num):
	return num * (3 * num + 1) // 2

def func(num):
	count = 0
	while num > 2:
		for k in range(int(pow(num, 0.5)) + 2, 0, -1):
			if num - pyra(k) >= 0:
				num -= pyra(k)
				count += 1
				break
	if num == 2:
		count += 1
	return count
tc = int(input())
for _ in range(tc):
	num = int(input())
	print(func(num))


t = int(input())
for i in range(t):
	n = int(input())
	cnt = 0
	while n >= 2:
		closestk = 0
		for k in range(1, 100000):
			if k * (k + 1) + k * (k - 1) // 2 > n:
				closestk = k - 1
				n = n - (closestk * (closestk + 1) + closestk * (closestk - 1) // 2)
				cnt += 1
				break
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	count = 0
	while n >= 2:
		count += 1
		h = ((1 + 24 * n) ** (1 / 2) - 1) // 6
		n -= (3 * h ** 2 + h) // 2
	print(count)


def search(a, x):
	start = 0
	end = len(a)
	while start + 1 < end:
		middle = (start + end) // 2
		if a[middle] < x:
			start = middle
		else:
			end = middle
	if x == a[end] or x > a[end]:
		return end
	return start
t = int(input())
a = [2]
max_n = 10 ** 9
level = 2
out = ''
while a[-1] <= max_n:
	a.append(a[-1] + level - 1 + 2 * level)
	level += 1
while t > 0:
	t -= 1
	n = int(input())
	s = 0
	while n > 0:
		x = search(a, n)
		s += 1
		n -= a[x]
	if n < 0:
		s -= 1
	out += f'{s}\n'
print(out)


import sys
input = sys.stdin.readline
import heapq
import copy
import math

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def pr_list(a):
	print(*a, sep=' ')

def find_permut(hashm, l):
	ans = 1
	total = math.factorial(l)
	for i in hashm:
		if i != 0:
			ans = ans * math.factorial(i)
	return int(total / ans)

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	for test in range(tests):
		n = inp()
		ans = 0
		left = n
		while True:
			if left <= 1:
				break
			i = 1.0
			while i < math.sqrt(left):
				if 0.5 * (3 * i * i + i) > left:
					break
				i = i + 1.0
			i = i - 1
			left = left - 0.5 * (3 * i * i + i)
			left = int(left)
			ans = ans + 1
		print(ans)
	return 0
main()


for _ in range(int(input())):
	n = int(input())
	cnt = 0
	for i in range(30000, 0, -1):
		s = 1.5 * (i * (i + 1)) - i
		while s <= n:
			n -= s
			cnt += 1
	print(cnt)


def next(arr, target):
	start = 0
	end = len(arr) - 1
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] <= target:
			start = mid + 1
		else:
			ans = mid
			end = mid - 1
	return ans
arr = [0] * 50001
for i in range(1, 50001):
	arr[i] = i * (3 * i + 1) // 2
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		h = next(arr, n)
		x = arr[h - 1]
		c += 1
		n -= x
	print(c)


import math
t = int(input())
for i in range(t):
	c = int(input())
	count = 0
	while c > 1:
		s = 1 + 4 * 3 * 2 * c
		x = (math.sqrt(s) - 1) // 6
		count += 1
		c = c - (3 * x ** 2 + x) // 2
	print(count)


import bisect

def main():
	dp = [2]
	i = 1
	curr = 2
	while curr < int(10000000000.0):
		i += 1
		curr = dp[i - 2] + i * 2 + i - 1
		dp.append(curr)
	t = int(input())
	while t:
		t -= 1
		n = int(input())
		score = 0
		x = bisect.bisect_left(dp, n)
		if dp[x] != n:
			x -= 1
		while x >= 0:
			n -= dp[x]
			x = bisect.bisect_left(dp, n)
			if dp[x] != n:
				x -= 1
			score += 1
		print(score)
main()


arr = list((0 for i in range(30000)))
arr[0] = 0
arr[1] = 2
for i in range(2, 30000):
	arr[i] = arr[i - 1] + i + i * 2 - 1
t = int(input())
for i in range(t):
	x = int(input())
	ans = 0
	while x > 1:
		left = 0
		right = 30000
		while right - left > 1:
			mid = (right + left) // 2
			if arr[mid] > x:
				right = mid
			else:
				left = mid
		x -= arr[left]
		ans += 1
	print(ans)


t = int(input())
while t:
	k = 1
	tri = 0
	n = int(input())
	i = 1
	while i <= n:
		if n == 1:
			break
		f = i * (3 * i + 1) // 2
		if f <= n:
			i += 1
			continue
		else:
			f = (i - 1) * (3 * (i - 1) + 1) // 2
			tri += 1
			n = n - f
			i = 1
			if n < 2:
				break
	print(tri)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	if n < 2:
		print(0)
	else:
		i = 1
		A = []
		while True:
			x = (3 * i ** 2 + i) // 2
			if x <= n:
				A.append(x)
			else:
				break
			i += 1
		A.sort(reverse=True)
		j = 0
		i = 0
		while True:
			j += n // A[i]
			n = n % A[i]
			if n <= 1:
				break
			i += 1
		print(j)


t = int(input())
for i in range(t):
	M = int(input())
	answer = 0
	while M >= 2:
		x = (-1 + (24 * M + 1) ** 0.5) / 6
		x = int(x + 1.0)
		while 3 * x * (x + 1) / 2 - x > M:
			x -= 1
		M -= 3 * x * (x + 1) // 2 - x
		answer += 1
	print(answer)


for _ in range(int(input())):
	n = int(input())
	j = 1
	ans = 0
	while n > 0:
		while 2 * j + 3 * (j - 1) * j // 2 < n:
			j += 1
		if n == 1:
			n = 0
		elif 2 * j + 3 * (j - 1) * j // 2 == n:
			ans += 1
			n = 0
		else:
			n -= 2 * (j - 1) + 3 * (j - 2) * (j - 1) // 2
			ans += 1
			j = 1
	print(ans)


n = int(input())
for i in range(n):
	t = int(input())
	count = 0
	j = 1
	while t >= 2:
		j = 1
		while (3 * j * j + j) // 2 <= t:
			j += 1
		count += 1
		j -= 1
		t = t - (3 * j * j + j) // 2
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	h = 1
	pyra = 0
	if n == 1:
		print(0)
	else:
		while n > 1:
			need = h * 2 + (h - 1)
			if need <= n:
				h += 1
				n -= need
			else:
				pyra += 1
				h = 1
		print(pyra + 1)


t = int(input())
for i in range(t):
	n = int(input())
	if n == 1:
		print(0)
	else:
		h = 0
		c = 0
		while n > 1:
			t = 3 * h + 2
			if n >= t:
				n -= t
			else:
				h = -1
				c += 1
			h += 1
		print(c + 1)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		N = int(input())
		ans = 0
		pyra = []
		pyra.append(2)
		i = 1
		while 1:
			x = i * 3 + 2 + pyra[-1]
			i += 1
			if x > N:
				break
			pyra.append(x)
		while pyra:
			x = pyra.pop()
			(q, N) = divmod(N, x)
			ans += q
		print(ans)
main()


dparr = []
dparr.append(2)
for _ in range(int(input())):
	n = int(input())
	count = 0
	while n > 0:
		i = 0
		val = 2
		while val <= n:
			if i < len(dparr):
				val = dparr[i]
				i = i + 1
			else:
				dparr.append(int(1.5 * i * i + 3.5 * i + 2))
				val = dparr[i]
				i = i + 1
		i = i - 2
		if i < 0:
			break
		else:
			n = n - dparr[i]
			count = count + 1
	print(count)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def main():
	t = I()
	rr = []
	ka = [(i + 1) * i // 2 * 3 - i for i in range(10 ** 5)]
	for _ in range(t):
		n = I()
		r = 0
		while n > 1:
			i = bisect.bisect_left(ka, n)
			r += 1
			if ka[i] > n:
				i -= 1
			n -= ka[i]
		rr.append(r)
	return JA(rr, '\n')
print(main())


t = int(input())
for q in range(0, t):
	a = int(input())
	s = 0
	while a > 1:
		g = 1
		while a >= g * 2 + g - 1:
			a -= g * 2 + g - 1
			g += 1
		s += 1
	print(s)


from sys import stdin, stdout
import math
import heapq
t = 1

def aint():
	return int(input().strip())

def lint():
	return list(map(int, input().split()))

def fint():
	return list(map(int, stdin.readline().split()))
from bisect import bisect_right
s = [2]
for h in range(2, 40000):
	s.append(s[-1] + 3 * h - 1)

def main():
	n = aint()
	ans = 0
	while n >= 2:
		i = bisect_right(s, n)
		n -= s[i - 1]
		ans += 1
	print(ans)
t = int(input())
for i in range(t):
	main()


import math
T = int(input())
for t in range(T):
	a = int(input())
	a *= 2
	ans = 0
	while a >= 4:
		v = int(math.sqrt(a // 3))
		s = v * (3 * v + 1)
		while s > a:
			v -= 1
			s = v * (3 * v + 1)
		a -= s
		ans += 1
	print(ans)


import bisect
dp = [0] * 10 ** 5
for i in range(1, 10 ** 5):
	dp[i - 1] = i * (i - 1) // 2 * 3 + 2 * i
for _ in range(int(input())):
	n = int(input())
	c = 0
	if n < 2:
		print('0')
	else:
		while n > 1:
			r = bisect.bisect(dp, n)
			c += 1
			n -= dp[r - 1]
		print(c)


def f(r):
	return r * (3 * r + 1) / 2
for _ in range(int(input())):
	n = int(input())
	h = 1
	r = n
	c = 0
	while r >= 2:
		if f(h) > r:
			c += 1
			r = r - f(h - 1)
			h = 0
		h += 1
	print(c)


from math import floor
from math import sqrt

def Pyramids(k):
	return floor((sqrt(24 * k + 1) - 1) / 6)
T = int(input())
while T:
	k = int(input())
	number_of_pyramids = 0
	while Pyramids(k) > 0:
		temp = Pyramids(k)
		number_of_pyramids += 1
		current = round(temp * (3 * temp + 1) / 2)
		k -= current
	print(number_of_pyramids)
	T -= 1


t = int(input())
for i in range(t):
	n = int(input())
	l = []
	l.append(2)
	i = 0
	while 1:
		l.append(l[i] + (3 * i + 5))
		if l[i] > n:
			break
		i += 1
	countPy = 0
	for i in range(len(l) - 2, -1, -1):
		while n >= l[i]:
			countPy += 1
			n -= l[i]
	print(countPy)


import bisect
t = int(input())
a = [i * (3 * i + 1) // 2 for i in range(10 ** 5)]
for _ in range(t):
	n = int(input())
	cnt = 0
	while n >= a[1]:
		p = bisect.bisect_right(a, n)
		n -= a[p - 1]
		cnt += 1
	print(cnt)


a = int(input())

def maxn(k):
	left = 0
	right = k
	while left < right:
		mid = (left + right) // 2
		if value(mid) < k:
			if value(mid + 1) > k:
				return mid
			left = mid
		elif value(mid) > k:
			right = mid
		else:
			return mid

def value(n):
	return (3 * pow(n, 2) + n) // 2
for i in range(0, a):
	k = int(input())
	count = 0
	while k > 0:
		if maxn(k) == 0:
			break
		k = k - value(maxn(k))
		count = count + 1
	print(count)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def B():
	n = inp()
	for i in range(n):
		num = inp()
		piles = 0
		height = 0
		used = 2
		while num > 1:
			if num - used >= 0:
				used += 5 + height * 3
				height += 1
			else:
				used -= 5 + (height - 1) * 3
				num -= used
				height = 0
				piles += 1
				used = 2
		print(piles)
B()


import math
ult = 10 ** 9 + 1

def bs(l, val):
	low = 0
	hi = len(l) - 1
	ans = 0
	while low <= hi:
		mid = (low + hi) // 2
		if l[mid] <= val:
			ans = mid
			low = mid + 1
		else:
			hi = mid - 1
	return ans

def main():
	l = []
	l.append(0)
	i = 1
	while True:
		nn = l[-1] + 3 * i - 1
		if nn >= ult:
			break
		l.append(nn)
		i += 1
	for q in range(int(input())):
		ans = 0
		val = int(input())
		while True:
			ll = bs(l, val)
			if ll == 0:
				break
			else:
				ans += 1
				val -= l[ll]
		print(ans)
main()


from sys import stdin, stdout
from bisect import bisect_right

def find(arr, N):
	c = 0
	while N > 1:
		k = bisect_right(arr, N) - 1
		N -= arr[k]
		c += 1
	return c

def main():
	r = 0
	arr = [2]
	for i in range(2, 10 ** 6):
		arr.append(arr[-1] + i * 2 + i - 1)
	for _ in range(int(stdin.readline())):
		print(find(arr, int(stdin.readline())))
main()


from sys import stdin, stdout
import collections
import heapq

def read_line():
	return stdin.readline().strip()

def read_int():
	return int(read_line())

def read_arr():
	return read_line().split(' ')

def read_int_arr():
	return [int(x) for x in read_arr()]

class UnionFind:

	def __init__(self):
		self.sets = {}

	def make_set(self, s):
		if s not in self.sets:
			self.sets[s] = s

	def find(self, s):
		if self.sets[s] != s:
			self.sets[s] = self.find(self.sets[s])
		return self.sets[s]

	def union(self, s1, s2):
		(a, b) = (self.find(s1), self.find(s2))
		if a == b:
			return
		self.sets[a] = b

	def gets_sets(self):
		res = collections.defaultdict(list)
		for s in self.sets:
			res[self.find(s)].append(s)
		return res

class SegmentTree:

	def __init__(self, nums, func):
		self.n = len(nums)
		self.func = func
		self.build(nums)

	def build(self, nums):
		self.segtree = [0 for _ in range(self.n)] + nums
		for i in reversed(range(1, self.n)):
			self.segtree[i] = self.func(self.segtree[i * 2], self.segtree[i * 2 + 1])

	def update(self, i, val):
		p = i + self.n
		self.segtree[p] = val
		while p > 1:
			self.segtree[p // 2] = self.func(self.segtree[p], self.segtree[p ^ 1])
			p //= 2

	def queryRange(self, i, j):
		res = 0
		(i, j) = (i + self.n, j + self.n)
		while i <= j:
			if i % 2 == 1:
				res = self.func(res, self.segtree[i])
				i += 1
			if j % 2 == 0:
				res = self.func(res, self.segtree[j])
				j -= 1
			(i, j) = (i // 2, j // 2)
		return res

def main():
	T = read_int()
	for _ in range(T):
		n = read_int()
		dp = [0]
		while dp[-1] < n:
			dp.append(dp[-1] + 3 * (len(dp) - 1) + 2)
		res = 0
		rem = n
		for v in reversed(dp):
			if v == 0:
				break
			if v <= rem:
				res += rem // v
				rem = rem % v
			if rem == 0 or rem == 1:
				break
		print(res)
main()


t = int(input())
for i in range(t):
	n = int(input())
	triangles = 0
	while n > 1:
		h = 0
		j = 1
		while h <= n:
			if h + j * 2 + (j - 1) <= n:
				h += j * 2 + (j - 1)
				j += 1
			else:
				break
		triangles += 1
		n -= h
	print(triangles)


import math

def f(x):
	return int(3 * x * (x + 1) / 2 - x)

def g(x):
	return int((-1 + math.sqrt(1 + 24 * x)) / 6)
T = int(input())
for t in range(T):
	n = int(input())
	result = 0
	while f(g(n)) != 0:
		n -= f(g(n))
		result += 1
	print(result)


for i in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
	else:
		count = 0
		while n > 1:
			h = 1
			while h >= 1:
				if n - 0.5 * h * (3 * h + 1) > 0:
					h += 1
				elif n - 0.5 * h * (3 * h + 1) == 0:
					n -= 0.5 * h * (3 * h + 1)
					count += 1
					break
				else:
					h -= 1
					n -= 0.5 * h * (3 * h + 1)
					count += 1
					break
		print(count)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		ans += 1
		h = (int((1 + 24 * n) ** 0.5) - 1) // 6
		n -= (3 * h + 1) * h // 2
	print(ans)


t = int(input())
H = [0] * 10 ** 5
for i in range(10 ** 5):
	h = i + 1
	H[i] = 3 * h * (h - 1) // 2 + 2 * h
S = set(H)
import bisect
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 0:
		if n in S:
			ans += 1
			break
		else:
			i = bisect.bisect_left(H, n)
			if i == 0:
				break
			else:
				ans += 1
				n -= H[i - 1]
	print(ans)


from bisect import bisect_right
I = input
t = int(I())
a = [2]
n = 1
while a[-1] <= 10000000000.0:
	a.append(a[n - 1] + 5 + 3 * (n - 1))
	n += 1
for _ in range(t):
	n = int(I())
	cnt = 0
	while n > 1:
		i = bisect_right(a, n) - 1
		n -= a[i]
		cnt += 1
	print(cnt)


try:
	k = int(input())
	for i in range(k):
		l = int(input())
		if l == 1:
			print(0)
		else:
			pyr = 0
			while l > 1:
				o = 2
				count = 1
				while o <= l:
					ret = o
					o += 3 * count + 2
					count += 1
				pyr += 1
				l -= ret
			print(pyr)
except Exception:
	pass


num = int(input())
for _ in range(num):
	n = int(input())
	ans = 0
	while n > 0:
		if n < 2:
			break
		i = 0
		h = 1
		while i + 2 * h + 1 * (h - 1) <= n:
			i += 2 * h + 1 * (h - 1)
			h += 1
		ans += 1
		n = n - i
	print(ans)


f = lambda x: (3 * x * x + x) // 2
for _ in [0] * int(input()):
	n = int(input())
	r = 0
	while n > 1:
		r += 1
		x = int(((1 + 24 * n) ** 0.5 - 1) / 6)
		n = n - f(x)
	print(r)


from sys import stdin, stdout
import bisect

def main():
	freq = [2]
	i = 1
	base = [0]
	arr = [2]
	old = 2
	while 1:
		base.append(i + base[i - 1])
		freq.append(freq[i - 1] + 2 + old)
		arr.append(freq[i] + base[i])
		old = old + 2
		if arr[i] >= 10 ** 9:
			break
		i += 1
	for _ in range(int(stdin.readline())):
		n = int(input())
		count = 0
		while 1:
			ind = bisect.bisect_right(arr, n)
			if ind == 0:
				break
			else:
				n = n - arr[ind - 1]
				count += 1
		print(count)
main()


import math
for _ in range(int(input())):
	n = int(input())
	count = 0
	while n >= 2:
		delta = 1 + 24 * n
		k = (-1 + math.sqrt(delta)) // 6
		N = (3 * k ** 2 + k) / 2
		n -= N
		count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	towers = 0
	while n >= 2:
		h = 0
		cards = 0
		while cards < n:
			h += 1
			cards += h * 3
		if cards - h <= n:
			n = n - (cards - h)
		else:
			n = n - (cards - h * 3 - (h - 1))
			h -= 1
		towers += 1
	print(towers)


import sys
from math import sqrt
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def s(d):
	dis = 1 + 4 * 2 * 3 * d
	ds = sqrt(dis)
	return (-1 + ds) / 6

def main():
	c = inp()
	for i in range(c):
		a = inp()
		c = 0
		while a >= 2:
			ans = int(s(a))
			res = [ans + 1, ans, ans - 1]
			for r in res:
				if (3 * r * r + r) // 2 <= a:
					a -= (3 * r * r + r) // 2
					c += 1
					break
		print(c)
main()


for i in range(int(input())):
	n = int(input())
	n = n
	ans = 0
	while n >= 2:
		ch = 2
		deff = 5
		while ch + deff <= n:
			ch += deff
			deff += 3
		ans += 1
		n -= ch
	print(ans)


def f(n):
	return (3 * n ** 2 + n) // 2
for i in range(int(input())):
	n = int(input())
	count = 0
	cond = True
	while cond:
		cond = False
		i = 1
		while f(i) <= n:
			i += 1
			cond = True
		if cond:
			count += 1
		n -= f(i - 1)
	print(count)


def cardsRem(n):
	a = n
	i = 1
	while a >= 3 * i - 1:
		a -= 3 * i - 1
		i += 1
	return a
T = int(input())
for _ in range(T):
	N = int(input())
	output = 0
	while N >= 2:
		N = cardsRem(N)
		output += 1
	print(output)


arr = []
i = 1
k = 0
while k < 10 ** 9:
	k = i * (i + 1) + i * (i - 1) // 2
	arr.append(k)
	i += 1
for T in range(int(input())):
	n = int(input())
	ans = 0
	while n > 0:
		for i in range(1, len(arr)):
			if arr[i] > n:
				n -= arr[i - 1]
				if n >= 0:
					ans += 1
				break
	print(ans)


t = int(input())
a = [2, 7]
for i in range(2, 10 ** 4 * 3):
	a.append(((a[-1] - a[-2] + 1 - i) // 2 + 1) * 2 + i + a[-1])
for _ in range(t):
	n = int(input())
	ans = 0
	for i in range(-1, -30001, -1):
		if a[i] <= n:
			while a[i] <= n:
				ans += 1
				n -= a[i]
	print(ans)


import sys
import math
input = sys.stdin.buffer.readline

def f(k):
	return 2 * k + 3 * (k - 1) * k // 2

def findLargest(n):
	l = 1
	r = n
	while l < r:
		mid = (l + r) // 2
		if f(mid) <= n:
			l = mid + 1
		else:
			r = mid
	return f(l - 1)
for _ in range(int(input())):
	nn = int(input())
	count = 0
	while nn >= 2:
		m = findLargest(nn)
		nn -= m
		count += 1
	print(count)


from bisect import bisect_left
t = int(input())
possibilities = [2]
idx = 2
while possibilities[-1] < 10 ** 9 + 1:
	possibilities.append(possibilities[-1] + 3 * idx - 1)
	idx += 1
for _ in range(t):
	n = int(input())
	ans = 0
	while True:
		bis_idx = bisect_left(possibilities, n)
		if n < possibilities[bis_idx]:
			bis_idx -= 1
		if bis_idx == -1:
			break
		ans += 1
		n -= possibilities[bis_idx]
	print(ans)


from pprint import pprint
import sys
input = sys.stdin.readline

def solve(n):
	(a, b) = (2, 0)
	res = 0
	if n < 2:
		return [False, 0, 0]
	while True:
		if n >= a + b:
			res += 1
			n -= a + b
		else:
			break
		a += 2
		b += 1
	return [True, n, res]
q = int(input())
for _ in range(q):
	n = int(input())
	res = 0
	while True:
		(a, b, c) = solve(n)
		if a is True:
			res += 1
		else:
			break
		n = b
	print(res)


def construct(n):
	h = 1
	global answer
	if n <= 1:
		return 0
	if n == 2:
		answer.append(1)
		return 0
	else:
		while n - (3 * h * h + h) // 2 >= 3 * h + 2:
			h += 1
		answer.append(h)
		construct(n - (3 * h * h + h) // 2)
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	answer = []
	construct(n)
	if n == 1 or n == 0:
		print(0)
	else:
		print(len(answer))


from bisect import *
l = [0]
for i in range(10 ** 5):
	l.append(2 * (i + 1) + i + l[-1])
for _ in range(int(input())):
	ans = 0
	n = int(input())
	while n > 0:
		ind = bisect_left(l, n)
		if l[ind] > n:
			ind -= 1
		n -= l[ind]
		if ind <= 0:
			break
		ans += 1
	print(ans)


f = [0]
i = 1
while f[-1] <= 10 ** 9:
	f.append(f[-1] + 3 * i - 1)
	i += 1
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		for ht in range(len(f)):
			if f[ht] > n:
				ht -= 1
				break
		n -= f[ht]
		ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	p = 0
	f = True
	i = 2
	if n == 2:
		print(1)
		continue
	elif n < 2:
		print(0)
		continue
	while f and n > 1:
		if (3 * i ** 2 + i) // 2 > n:
			i -= 1
			n -= (3 * i ** 2 + i) // 2
			i = 1
			p += 1
		elif (3 * i ** 2 + i) // 2 == n:
			p += 1
			break
		i += 1
	print(p)


t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	tall = 1
	if n >= 2:
		ans += 1
	while n >= 2:
		if n >= 2 + 3 * (tall - 1):
			n -= 2 + 3 * (tall - 1)
			tall += 1
		else:
			tall = 1
			ans += 1
	print(ans)


(base, rec) = ({}, {})

def getrec(height):
	if height == 1:
		return 1
	if height in rec:
		return rec[height]
	rec[height] = getrec(height - 1) + height
	return rec[height]

def getbase(height):
	if height == 1:
		return 0
	if height in base:
		return base[height]
	base[height] = getbase(height - 1) + height - 1
	return base[height]

def getcards(height):
	return getbase(height) + getrec(height) * 2
q = []
for i in range(int(input())):
	q.append(int(input()))
m = max(q)
h = 1
cards = []
while getcards(h) <= m:
	cards.append(getcards(h))
	h += 1
for j in q:
	counter = 0
	card = j
	while card != 0 and card != 1:
		for i in range(len(cards) + 1):
			if i == len(cards) or cards[i] > card:
				card -= cards[i - 1]
				counter += 1
				break
	print(counter)


n = int(input())
for i in range(n):
	ans = 0
	a = int(input())
	while a > 1:
		k = 0
		for j in range(a + 1):
			if (0.5 + 1.5 * j) * j > a:
				k = j - 1
				break
		a -= int((0.5 + 1.5 * k) * k)
		ans += 1
	print(ans)


from math import floor

def roots(a, b, c):
	d = (b ** 2 - 4 * a * c) ** (1 / 2)
	x1 = (-b + d) / (2 * a)
	x2 = (-b - d) / (2 * a)
	return min(x1, x2, key=lambda x: x if x >= 0 else 100000000000)

def sum_ap(a, d, n):
	return int(n / 2 * (2 * a + (n - 1) * d))
t = int(input())
for _ in range(t):
	cards = int(input())
	(a, d) = (2, 3)
	c = 0
	while cards >= 2:
		n = floor(roots(3 / 2, 1 / 2, -cards))
		cards -= sum_ap(a, d, n)
		c += 1
	print(c)


import math
cases = int(input())
for j in range(cases):
	c = int(input())
	l = 0
	if c < 2:
		print(0)
	else:
		while True:
			n = math.floor((math.sqrt(24 * c + 1) - 1) // 6)
			c -= n * (n * 3 + 1) // 2
			l += 1
			if c < 2:
				print(l)
				break


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	while n >= 2:
		h = int(n ** 0.5)
		while 1.5 * h ** 2 + 0.5 * h > n:
			h -= 1
		n -= 1.5 * h ** 2 + 0.5 * h
		count += 1
	print(count)


import math
for _ in ' ' * int(input()):
	n = int(input())
	cnt = 0
	if n == 1:
		print(0)
	else:
		while n > 1:
			h = int(math.sqrt(1 + 24 * n) - 1) // 6
			cnt += 1
			n -= 3 * (h * (h + 1) // 2) - h
		print(cnt)


for tt in range(int(input())):
	x = int(input())
	cnt = 0
	if x == 1:
		print('0')
		continue
	while x > 1:
		s = ps = 0
		i = 1
		while s <= x:
			ps = s
			s = i * (2 + (i - 1)) + (i - 1) * i // 2
			i += 1
		x -= ps
		cnt += 1
	print(cnt)


import sys
T = int(sys.stdin.readline().strip())
cache = [2]
L = 1
for t in range(T):
	n = int(sys.stdin.readline().strip())
	while cache[-1] < n:
		L += 1
		cache.append(L * (L + 1) + L * (L - 1) // 2)
	l = 0
	r = L
	while l < r - 1:
		m = (l + r) // 2
		if cache[m] <= n and (m + 1 == L or cache[m + 1] > n):
			l = m
			break
		if cache[m] < n:
			l = m
		else:
			r = m
	cnt = 0
	while l >= 0 and n > 1:
		if n >= cache[l]:
			n -= cache[l]
			cnt += 1
		else:
			l -= 1
	print(cnt)


def f(n):
	v = 24 * n + 1
	return int((-1 + v ** 0.5) // 6)

def g(h):
	return h * (3 * h + 1) // 2
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		n -= g(f(n))
		c += 1
	print(c)


import collections

def inp():
	return int(input())

def linp():
	return [int(i) for i in input().split()]
cards = [2]
i = 2
while cards[-1] <= 10 ** 9:
	cards.append(i * 2 + i - 1 + cards[-1])
	i += 1
T = inp()
ans = []
for t in range(T):
	n = inp()
	a = 0
	m = len(cards) - 1
	while n >= 2:
		(l, r) = (0, m + 1)
		while l < r - 1:
			m = (l + r) // 2
			if cards[m] > n:
				r = m
			else:
				l = m
		a += 1
		n -= cards[l]
	ans.append(a)
for a in ans:
	print(a)


import bisect

def precumput(n):
	dp = [0 for i in range(n + 1)]
	for i in range(1, n + 1):
		dp[i] = i * (i + 1) + i * (i - 1) // 2
	return dp

def read():
	t = int(input())
	dp = precumput(100001)
	for i in range(t):
		n = int(input())
		ndx = bisect.bisect_left(dp, n)
		ans = 0
		while ndx > 0:
			if n >= dp[ndx]:
				n = n - dp[ndx]
				ans += 1
				ndx = bisect.bisect_left(dp, n)
			else:
				ndx -= 1
		print(ans)
read()


def solution():
	n = int(input())
	ans = 0
	while n > 1:
		m = 1
		while (3 * m * m + m) // 2 <= n:
			m += 1
		m -= 1
		n -= (3 * m * m + m) // 2
		ans += 1
	print(ans)
for _ in range(int(input())):
	solution()


import math
for t in range(int(input())):
	n = int(input())
	count = 0
	while True:
		l = (math.sqrt(1 + 24 * n) - 1) / 6
		l = math.floor(l)
		if l > 0:
			count += 1
			used = 3 * (l * (l + 1) // 2) - l
			used = math.ceil(used)
			n -= used
		else:
			break
	print(count)


g = []

def generate():
	i = 0
	g.append(0)
	while True:
		i += 1
		n = i * (3 * i + 1) // 2
		g.append(n)
		if n > 1000000000.0:
			break
	return
generate()
for i in range(int(input())):
	n = int(input())
	ans = 0
	while True:
		if n < 2:
			break
		for i in range(1, len(g), 1):
			if g[i] > n:
				n = abs(g[i - 1] - n)
				ans += 1
				break
	print(ans)


import os, sys
from math import *
lim = 26000
arr = [3 * i * (i + 1) // 2 - i for i in range(lim)]

def bisect(v):
	(l, r) = (0, lim - 1)
	while l + 1 < r:
		mid = (l + r) // 2
		if arr[mid] <= v:
			l = mid
		else:
			r = mid
	return l
t = int(input())
for nc in range(t):
	n = int(input())
	ct = 0
	while n > 1:
		n -= arr[bisect(n)]
		ct += 1
	print(ct)


for _ in range(int(input())):
	a = int(input())
	ans = 2
	cnt = 0
	x = 0
	while a >= 2:
		k = ans
		ans = ans + 5 + 3 * x
		x = x + 1
		if ans > a:
			cnt = cnt + 1
			a = a - k
			x = 0
			ans = 2
			continue
	print(cnt)


from math import sqrt, floor

def inverse(n):
	return (sqrt(1 + 24 * n) - 1) / 6

def normal(n):
	return n * (3 * n + 1) / 2
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		n -= normal(floor(inverse(n)))
		c += 1
	print(c)


z = 5
k = [2]
for i in range(5, 10 ** 6, 3):
	if k[-1] > 10 ** 9:
		break
	else:
		k.append(k[-1] + i)
for _ in range(int(input())):
	p = int(input())
	count = 0
	while p >= 2:
		for i in range(len(k)):
			if k[i] <= p:
				z = k[i]
		if k[0] <= p:
			count += 1
		p -= z
	print(count)


from bisect import bisect_left
from collections import defaultdict
Hash = defaultdict(lambda : -1)

def BinarySearch(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1
L = []
for i in range(1, 10 ** 5 - 1):
	L.append((3 * i ** 2 + i) // 2)
	Hash[(3 * i ** 2 + i) // 2] = i - 1
for _ in range(int(input())):
	N = int(input())
	count = 0
	while N >= 2:
		count += 1
		if Hash[N] != -1:
			N = N - L[Hash[N]]
		else:
			x = BinarySearch(L, N)
			N = N - L[x]
	print(count)


from bisect import bisect_left as bl
for t in range(int(input())):
	n = int(input())
	l = []
	for i in range(int(n ** 0.5) + 3):
		l.append(i ** 2 + i + i * (i - 1) // 2)
	ans = 0
	while n > 1:
		ind = bl(l, n)
		if l[ind] != n:
			ind -= 1
		n -= l[ind]
		ans += 1
	print(ans)


n = int(input())
a = []
for i in range(n):
	a.append(int(input()))
h = 1
k = 0
for i in range(n):
	while a[i] > 1:
		while 0.5 * (h + 1) * (3 * (h + 1) + 1) <= a[i]:
			h += 1
		a[i] -= 0.5 * h * (3 * h + 1)
		k += 1
		h = 1
	a[i] = k
	k = 0
for i in range(n):
	print(a[i])


t = int(input())
for i in range(t):
	n = int(input())
	if n < 2:
		print(0)
	else:
		a = 2
		d = 5
		flag = 0
		while flag == 0:
			if a == n:
				break
			elif a > n:
				d = d - 3
				a = a - d
				break
			else:
				a = a + d
				d = d + 3
				continue
		count = 0
		while n >= 2 and a >= 2:
			if n >= a:
				count = count + n // a
				n = n % a
				d = d - 3
				a = a - d
			elif n == 0:
				break
			elif n > 0:
				d = d - 3
				a = a - d
		print(count)


numTest = int(input())
for _ in range(numTest):
	cardNum = int(input())
	totalPyramids = 0
	while True:
		baseHeight = 1
		baseCards = 2
		if cardNum < baseCards:
			break
		else:
			while True:
				preHeight = baseHeight
				preCards = baseCards
				baseHeight = baseHeight + 1
				baseCards = baseCards + baseHeight - 1 + baseHeight * 2
				if baseCards > cardNum:
					baseHeight = preHeight
					baseCards = preCards
					break
			cardNum = cardNum - baseCards
			totalPyramids = totalPyramids + 1
	print(totalPyramids)


a = [2]
for i in range(1, 100000):
	a += [a[i - 1] + 3 * i + 2]
t = int(input())
while t:
	t -= 1
	n = int(input())
	c = 0
	while n >= 2:
		l = 0
		h = 99999
		while l <= h:
			res = l + (h - l) // 2
			if a[res] == n or (a[res] >= n and a[res - 1] < n):
				break
			elif n > a[res]:
				l = res + 1
			else:
				h = res - 1
		if a[res] == n:
			n = 0
			c += 1
			break
		else:
			n -= a[res - 1]
			c += 1
			h = n
			l = 0
	print(c)


arr = [2]
h = 1
t = int(input())
for i in range(t):
	n = int(input())
	while arr[-1] <= n:
		h += 1
		arr.append(arr[-1] + h * 2 + h - 1)
	cnt = 0
	i = len(arr) - 1
	while i >= 0:
		if arr[i] <= n:
			cnt += n // arr[i]
			n = n % arr[i]
		i -= 1
	print(cnt)


import sys

def input(itr=iter(sys.stdin.readlines())):
	return next(itr).rstrip('\n\r')
import bisect
cost = [0]
i = 1
while cost[-1] < int(1000000000.0):
	cost.append(cost[-1] + i * 3 - 1)
	i += 1
t = int(input())
for _ in range(t):
	n = int(input())
	pyramids = 0
	h = len(cost)
	while n >= 2:
		h = bisect.bisect_left(cost, n, hi=h)
		if cost[h] > n:
			h -= 1
		(s, n) = divmod(n, cost[h])
		pyramids += s
	print(pyramids)


t = int(input())
for i in range(t):
	n = int(input())
	k = 0
	le = 1
	while n > 1:
		if n - le * 3 + 1 >= 0:
			n = n - le * 3 + 1
			le += 1
		else:
			le = 1
			k += 1
	if le > 1:
		k += 1
	print(k)


def smallest(n, count):
	if n < 2:
		return count
	else:
		temp = 0
		i = 0
		while temp <= n - 3 * i - 2:
			temp = temp + (3 * i + 2)
			i += 1
		count += 1
		return smallest(n - temp, count)
for _ in range(int(input())):
	N = int(input())
	print(smallest(N, 0))


k = 0
for i in range(int(input())):
	q = int(input())
	while q > 1:
		q = q - ((((1 + 24 * q) ** 0.5 - 1) // 6 * 6 + 1) ** 2 - 1) // 24
		k += 1
	print(k)
	k = 0


test = int(input())
for i in range(test):
	cards = int(input())
	count = 1
	pyramid = 0
	if cards == 1:
		print('0')
	else:
		while cards >= 2:
			if cards >= count * 2 + count - 1:
				cards -= count * 2 + count - 1
				count += 1
				if cards < 2:
					pyramid += 1
			else:
				pyramid += 1
				count = 1
		print(pyramid)


from math import *
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	cnt = 0
	while n > 1:
		r1 = (-1 + sqrt(1 + 24 * n)) // 6
		val = r1 * (r1 + 1) + r1 * (r1 - 1) // 2
		n -= val
		cnt += 1
	print(cnt)


from bisect import bisect_right
a = [i * (3 * i + 1) // 2 for i in range(1, 50000)]
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n >= a[0]:
		ind = bisect_right(a, n) - 1
		n -= a[ind]
		c += 1
	print(c)


from math import sqrt as sqr

def jav(x):
	return (sqr(1 + 24 * x) - 1) / 6
s = []
for inii in range(int(input())):
	g = 0
	n = int(input())
	while jav(n) >= 1:
		g += 1
		n -= (pow(jav(n) // 1, 2) * 3 + jav(n) // 1) / 2
	s.append(g)
for i in s:
	print(i)


from math import sqrt, trunc
for _ in range(int(input())):
	(n, res) = (int(input()), 0)
	while n > 1:
		h = int((sqrt(1 + 24 * n) - 1) / 6)
		cards_count = h * (3 * h + 1) >> 1
		pyramides_count = n // cards_count
		res += pyramides_count
		n -= pyramides_count * cards_count
	print(res)


from collections import defaultdict as dc
from heapq import *
import math
import bisect
import sys
from collections import deque as dq
from heapq import heapify, heappush, heappop
mod = 10 ** 9 + 7

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p

def read_mat():
	n = inp()
	a = []
	for i in range(n):
		a.append(line())
	return a

def digit(n):
	s = str(n)
	p = 0
	for i in s:
		p += int(i) ** 2
	return p
p = []

def mat():
	x = 2
	z = 2
	p.append(x)
	while x <= 10 ** 9:
		x = x + 2 * z + (z - 1)
		p.append(x)
		z += 1
	return p
p = mat()
ans = 0

def solve(n):
	ans = 0
	while n > 0:
		if n < 2:
			break
		x = bisect.bisect(p, n) - 1
		n = n - p[x]
		ans += 1
	return ans
for test in range(inp()):
	n = inp()
	l = solve(n)
	print(l)


t = int(input())
cards = [int(input()) for _ in range(t)]
pyramid = [2]
h = 2
next = pyramid[-1] + (h - 1) + 2 * h
while next <= 10 ** 9:
	next = pyramid[-1] + (h - 1) + 2 * h
	pyramid.append(next)
	h += 1
for n in cards:
	if n < 2:
		print(0)
		continue
	ans = 0
	while n >= 2:
		for i in range(len(pyramid)):
			if pyramid[i] > n:
				use = pyramid[i - 1]
				ans += 1
				n -= use
				break
	print(ans)


for _ in range(int(input())):
	a = int(input())
	k = 0
	while a > 1:
		p = int(((24 * a + 1) ** 0.5 - 1) / 6)
		a -= p * (3 * p + 1) // 2
		k += 1
	print(k)


import bisect
test_cases = int(input())
precompute = [2]

def handle():
	n = int(input())
	count = 0
	while precompute[-1] < n:
		precompute.append(precompute[-1] + (3 * (len(precompute) + 1) - 1))
	while n > 1:
		index = bisect.bisect_left(precompute, n)
		count += 1
		if precompute[index] == n:
			return count
		else:
			n -= precompute[index - 1]
	return count
for _ in range(test_cases):
	print(handle())


(i, prev) = (0, 0)
a = []
for i in range(1, 90001):
	v = i - 1 + i * 2 + prev
	a.append(v)
	prev = v
for _ in range(int(input())):
	n = int(input())
	ans = 0
	i = len(a) - 1
	while i >= 0:
		if a[i] <= n:
			while a[i] <= n:
				n -= a[i]
				ans += 1
		i -= 1
	print(ans)


A = []
x = 0
i = 1
while x <= 10 ** 11:
	x += 3 * i - 1
	A.append(x)
	i += 1
for i in range(int(input())):
	n = int(input())
	ans = 0
	k = int(n ** 0.5) + 1
	while n >= 0 and k >= 0:
		if n < A[k]:
			k -= 1
		else:
			n -= A[k]
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	l = []
	l.append(2)
	i = 2
	while i * 3 - 1 + l[-1] <= n:
		l.append(i * 3 - 1 + l[-1])
		i += 1
	i = len(l) - 1
	x = 0
	while n > 0 and i >= 0:
		if n >= l[i]:
			x += n // l[i]
			n = n - l[i] * (n // l[i])
		i -= 1
	print(x)


t = int(input())
dp = [0] * 10 ** 5
dp[1] = 2
for i in range(2, 10 ** 5):
	dp[i] = dp[i - 1] + 3 * (i - 1) + 2
import bisect
for _ in range(t):
	n = int(input())
	c = 0
	while n >= 2:
		r = dp[bisect.bisect_right(dp, n) - 1]
		n -= r
		c += 1
	print(c)


import math
a = []
for i in range(int(input())):
	n = int(input())
	D = math.sqrt(1 + 24 * n)
	h = (-1 + D) / 6
	cnt = 0
	if h < 1:
		a.append(0)
	else:
		while True:
			D = math.sqrt(1 + 24 * n)
			h = (-1 + D) / 6
			nh = int(h)
			n = n - (3 * nh * nh + nh) / 2
			cnt += 1
			if n < 2:
				break
		a.append(cnt)
for i in a:
	print(i)


import math
from collections import Counter, deque
L = lambda : list(map(int, input().split()))
M = lambda : map(int, input().split())
I = lambda : int(input())
IN = lambda : input()
mod = 10 ** 9 + 7

def s(a):
	print(' '.join(list(map(str, a))))
x = 2
li = []
i = 5
while x < pow(10, 10):
	li.append(x)
	x += i
	i += 3

def search(li, a):
	for i in range(len(li)):
		if li[i] > a:
			return li[i - 1]
for _ in range(I()):
	n = I()
	count = 0
	while n >= 2:
		count += 1
		n -= search(li, n)
	print(count)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		i = int(((1 + 4 * 3 * 2 * n) ** 0.5 - 1) / 6)
		n -= i * (i + 1) // 2 * 3 - i
		ans += 1
	print(ans)


l = [0] * 25825
for h in range(1, 25825):
	l[h] = h * (3 * h + 1) / 2
t = int(input())
for _ in range(t):
	n = int(input())
	count = 0
	while n >= 2:
		h = 0
		while l[h] <= n:
			h += 1
		count += 1
		n -= l[h - 1]
	print(count)


x = 2
y = x
z = []
while y <= 10 ** 9 + 1000000:
	z.append(y)
	x += 3
	y += x
for i in range(int(input())):
	a = int(input())
	q = 0
	while a > 1:
		l = 0
		r = len(z) - 1
		while l != r:
			m = (l + r) // 2
			if a > z[m]:
				l = m + 1
			else:
				r = m
		if a == z[l]:
			a -= z[l]
		else:
			a -= z[l - 1]
		q += 1
	print(q)


import math
counter = int(input())
for i in range(counter):
	num = int(input())
	count = 0
	while num >= 2:
		temph = int(math.sqrt(0.5 * num))
		summ = int(3 / 2 * temph ** 2 + temph / 2)
		nexth = temph + 1
		nextsum = int(3 / 2 * nexth ** 2 + nexth / 2)
		while nextsum <= num:
			temph = nexth
			summ = nextsum
			nexth += 1
			nextsum = int(3 / 2 * nexth ** 2 + nexth / 2)
		if temph > 0:
			count += 1
		num = num - summ
	print(count)


from math import *
import os, sys
from io import BytesIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

def lol(n):
	return (1 + n) * n // 2 * 3 - n
s = 0
for _ in range(1, int(input()) + 1):
	n = int(input())
	ans = 0
	r = 10 ** 9 + 10
	while n > 1:
		l = 1
		ans += 1
		while r - l > 1:
			m = (r + l) // 2
			if lol(m) > n:
				r = m
			else:
				l = m
		n -= lol(l)
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	count = 0
	while n >= 2:
		i = (-1 + math.sqrt(1 + 24 * n)) / 6
		i = math.floor(i)
		c = (3 * i * i + i) / 2
		c = math.floor(c)
		n -= c
		count += 1
	print(count)


try:
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		while n >= 2:
			ans = ans + 1
			use = 2
			while n >= use:
				n = n - use
				use = use + 3
		print(ans)
except:
	pass


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right

def main():
	i = 2
	a = [-1, 2]
	while a[-1] < 10 ** 9:
		a.append(a[-1] + (i - 1) + i * 2)
		i += 1
	for i in range(int(input())):
		n = int(input())
		ind = bisect_right(a, n)
		cnt = 0
		while ind >= 2:
			n -= a[ind - 1]
			cnt += 1
			ind = bisect_right(a, n)
		print(cnt)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


(t, p) = (int(input()), [])
for i in range(t):
	(n, x) = (int(input()), 0)
	l = ((1 + 24 * n) ** 0.5 - 1) // 6
	while l != 0:
		x += 1
		n -= 1.5 * l ** 2 + 0.5 * l
		l = ((1 + 24 * n) ** 0.5 - 1) // 6
	p.append(str(x))
print('\n'.join(p))


t = int(input())

def search(l, r, ele):
	if l > r:
		return -1
	mid = (l + r) // 2
	val = mid * (3 * mid + 1) // 2
	if val == ele:
		return val
	if val > ele:
		return search(l, mid - 1, ele)
	return max(val, search(mid + 1, r, ele))
while t > 0:
	n = int(input())
	ct = 0
	while n > 0:
		maxPy = search(1, 1000000000, n)
		if maxPy > 0:
			n -= maxPy
			ct += 1
		else:
			break
	print(ct)
	t -= 1


t = int(input())
a = []
s = 1
c = 2
while s <= 10 ** 9 + 1:
	a.append(s + 1)
	s += c * 2 + (c - 1)
	c += 1
for test in range(t):
	n = int(input())
	import bisect
	ans = 0
	while True:
		x = bisect.bisect_left(a, n)
		if x < len(a) and a[x] == n:
			n -= a[x]
			ans += 1
		elif x != 0:
			n -= a[x - 1]
			ans += 1
		else:
			break
	print(ans)


t = int(input())
a = [0]
tmp = 0
count = 1
while tmp <= 10 ** 9:
	tmp += count
	a.append(tmp)
	count += 1
b = [a[i] * 2 + a[i - 1] for i in range(1, len(a))]
import bisect
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		id = bisect.bisect_right(b, n)
		n -= b[id - 1]
		ans += 1
	print(ans)


from sys import stdin
from bisect import bisect

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
c = 0
i = 1
p = []
while c <= 10 ** 9:
	c += i * 2 + i - 1
	p.append(c)
	i += 1
t = iinput()
while t:
	t -= 1
	n = iinput()
	c = 0
	while n > 1:
		x = bisect(p, n)
		n -= p[x - 1]
		c += 1
	print(c)


a = 2
c = 5
b = [2]
while a + c <= 10 ** 9 + 1000000:
	b.append(a + c)
	a = a + c
	c = c + 3
u = int(input())
for _ in range(u):
	x = int(input())
	k = 0
	while x > 1:
		l = 0
		r = len(b) - 1
		while l != r:
			m = (r + l) // 2
			if b[m] < x:
				l = m + 1
			else:
				r = m
		if x == b[l]:
			x -= b[l]
		else:
			x -= b[l - 1]
		k += 1
	print(k)


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline().split()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
hts = []

def build_arr():
	n = 2
	diff = 5
	while n <= 10 ** 9:
		hts.append(n)
		n += diff
		diff += 3
test = int_input()
build_arr()
for _ in range(test):
	n = int_input()
	count = 0
	for i in range(len(hts) - 1, -1, -1):
		if hts[i] <= n:
			count += n // hts[i]
			n = n % hts[i]
	print(count)


import math
import bisect

def solve(n):
	cnt = 0
	ind = bisect.bisect_left(dp, n)
	while n > 1:
		ind = bisect.bisect_left(dp, n)
		if n < dp[ind]:
			ind -= 1
		cnt += 1
		n -= dp[ind]
	print(cnt)
t = int(input())
dp = [0, 2]
cnt = 0
for i in range(2, int(math.sqrt(1000000000.0))):
	dp.append(dp[i - 1] + i * 2 + (i - 1))
for _ in range(t):
	n = int(input())
	solve(n)


import sys
from os import path
if path.exists('C:/Users/prana/Desktop/sublime/input.txt'):
	sys.stdin = open('C:/Users/prana/Desktop/sublime/input.txt', 'r')
	sys.stdout = open('C:/Users/prana/Desktop/sublime/output.txt', 'w')
import math

def solve():
	n = input()
	n = int(n)
	count = 0
	while n >= 2:
		p = (n * 2 // 3) ** 0.5
		x = math.floor(p)
		while (3 * x ** 2 + x) // 2 > n:
			x -= 1
		count += 1
		n = n - (3 * x ** 2 + x) // 2
	print(count)
T = 1
T = int(input())
for _ in range(1, T + 1):
	solve()


for _ in range(int(input())):
	s = int(input())
	ct = 0
	while s > 1:
		l = 0
		r = s
		ans = 0
		while l <= r:
			mid = (l + r) // 2
			if mid * (3 * mid + 1) // 2 <= s:
				ans = mid
				l = mid + 1
			else:
				r = mid - 1
		s -= ans * (3 * ans + 1) // 2
		if ans > 0:
			ct += 1
		else:
			break
	print(ct)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scan_int = lambda : int(input())
scan_string = lambda : input().rstrip()
read_list = lambda : list(read())
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(beauty, s, n, count):
	pass
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect

def solve():
	n = int(input())
	s = 0
	c = 0
	i = int(n ** 0.5) + 1
	while i > 0:
		twos = i * (i + 1)
		ones = i * (i - 1) // 2
		if twos + ones > n:
			i -= 1
			continue
		else:
			s += twos + ones
			n -= twos + ones
			i = int(n ** 0.5) + 1
			c += 1
	print(c)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for i in range(scan_int()):
	solve()


pref = [2]
for i in range(2, 30000):
	pref.append(i * 3 - 1)
	pref[-1] += pref[-2]
t = int(input())
for uuu in range(t):
	n = int(input())
	cnt = 0
	while n > 1:
		l = 0
		r = 30000
		while r - l > 1:
			mid = (r + l) // 2
			if pref[mid] > n:
				r = mid
			else:
				l = mid
		n -= pref[l]
		cnt += 1
	print(cnt)


import math
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		x = (-1 + math.sqrt(1 + 4 * 3 * 2 * n)) // 6
		n -= (3 * x * x + x) // 2
		c += 1
	print(c)


p = dict()
p[1] = 2

def get_max_p(num):
	counter = int()
	total = 0
	i = 0
	while True:
		d = 0
		i += 1
		d = total + 2 * i + (i - 1)
		if num - d >= 0:
			counter += 1
			total = d
		else:
			return total

def main():
	for _ in range(int(input())):
		n = int(input())
		counter = 0
		while n > 0:
			total = get_max_p(n)
			n -= total
			if total == 0:
				break
			counter += 1
		print(counter)
main()


poss = [2]
i = 2
while poss[-1] <= 1000000000:
	poss.append(poss[-1] + 2 * i + i - 1)
	i += 1
for f in range(int(input())):
	n = int(input())
	m = 0
	i = 0
	while poss[i + 1] <= n:
		i += 1
	n -= poss[i]
	if n >= 0:
		m += 1
	while n > 1:
		while poss[i] > n:
			i -= 1
		n -= poss[i]
		m += 1
	print(m)


from math import floor
t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		k = floor((-1 + (1 + 24 * n) ** (1 / 2)) / 6)
		n -= k * (k + 1) + (k - 1) * k / 2
		ans += 1
	print(ans)


from bisect import bisect
f = []

def form(n):
	return n * (n + n + n + 1) // 2
for i in range(1, 10 ** 5):
	if form(i) > 1000021510:
		break
	f.append(form(i))
for i in range(int(input())):
	n = int(input())
	c = 0
	while n >= 2:
		ele = f[bisect(f, n) - 1]
		c += 1
		n -= ele
	print(c)


for i in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		next = 5
		curr = 2
		while n >= curr:
			n -= curr
			curr = next
			next += 3
		ans += 1
	print(ans)


t = int(input())
i = 0
inter = 2
h = 0
h_saves = []
while i != t:
	test = int(input())
	if test >= 2:
		while test >= 2:
			if test >= inter:
				test -= inter
				inter += 3
			else:
				inter = 2
				h += 1
		h += 1
	h_saves.append(h)
	h = 0
	inter = 2
	i += 1
print('')
for el in h_saves:
	print(el)


T = int(input())
for _ in range(T):
	numMatches = int(input())
	numPyramids = 0
	i = 1
	while numMatches > 1:
		while 3 * i * (i + 1) // 2 - i <= numMatches:
			i += 1
		numMatches -= 3 * i * (i - 1) // 2 - (i - 1)
		i = 1
		numPyramids += 1
	print(numPyramids)


import getopt
import sys
import math

def height(cards):
	return (math.sqrt(24 * cards + 1) - 1) / 6

def cards(h):
	return (3 * h * h + h) // 2
onlyCase = -1
verbose = False
try:
	(opts, args) = getopt.getopt(sys.argv[1:], 'vc:', ['case='])
except getopt.GetoptError as err:
	print(str(err))
	sys.exit(2)
for (o, a) in opts:
	if o in ('-c', '--case'):
		onlyCase = int(a)
	elif o == '-v':
		verbose = True
	else:
		sys.exit()
ncases = int(input())
for c in range(1, ncases + 1):
	N = int(input())
	if onlyCase != -1 and onlyCase != c:
		continue
	count = 0
	while N >= 2:
		f = height(N)
		c = cards(math.floor(f))
		N = N - c
		count += 1
	print(count)


for i in range(int(input())):
	a = int(input())
	b = int(pow(a, 1 / 2))
	c = []
	c.append(2)
	for j in range(2, b + 1):
		c.append(j * 2 + (j - 1) + c[-1])
	count = 0
	c.reverse()
	while a > 1:
		for k in range(len(c)):
			if a >= c[k]:
				a = a - c[k]
				count += 1
				break
	print(count)


import sys
input = sys.stdin.readline

def f(x):
	return (3 * x ** 2 + x) // 2 > N

def bsearch(mn, mx, func):
	idx = (mx + mn) // 2
	while mx - mn > 1:
		if func(idx):
			(idx, mx) = ((idx + mn) // 2, idx)
			continue
		(idx, mn) = ((idx + mx) // 2, idx)
	return idx
(t,) = map(int, input().split())
for _ in range(t):
	(N,) = map(int, input().split())
	c = 0
	while True:
		i = bsearch(-1, 10 ** 5, f)
		if i == 0:
			break
		N -= (3 * i ** 2 + i) // 2
		c += 1
	print(c)


test_cases = int(input())
for test_case in range(test_cases):
	n = int(input())
	c = 0
	while n > 1:
		c += 1
		full = 0
		full_multiplier = 0
		bottom = 2
		i = 0
		while True:
			n1 = n - i
			i = bottom + full
			if i > n:
				break
			bottom += 2
			full_multiplier += 1
			full += full_multiplier * 3
		n = n1
	print(c)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, **kwargs):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	for _ in range(int(input())):
		n = int(input())
		count = 0
		for i in range(10 ** 5):
			if n < 2:
				break
			count += 1
			height = int((-1 + (1 + 24 * n) ** 0.5) / 6)
			cards_needed = (3 * (height * height) + height) // 2
			n -= cards_needed
		print(count)
main()


from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	cn = 0
	while n > 1:
		cn += 1
		m = 2
		c = 2
		while m <= n:
			m += c + 3
			c = c + 3
		n -= m - c
	stdout.write(str(cn) + '\n')


from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def solve():
	a = [2, 7, 15]
	s = 15
	k = 4
	while s < 1000000007:
		s += k * 2 + (k - 1)
		a.append(s)
		k += 1
	for _ in range(ii()):
		n = ii()
		ans = 0
		while n >= 2:
			x = bisect_left(a, n)
			if a[x] > n:
				x -= 1
			ans += n // a[x]
			n %= a[x]
		print(ans)
solve()


for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n:
		x = 0
		while (x + 1) * (3 * x + 4) <= n * 2:
			x += 1
		if x:
			k = n // (x * (3 * x + 1) // 2)
			ans += k
			n -= k * x * (3 * x + 1) // 2
		else:
			break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	total = 0
	i = 0
	while n > 1:
		if 2 * (i + 1) + i <= n:
			n -= 2 * (i + 1) + i
			i += 1
		else:
			total += 1
			i = 0
		if n <= 1:
			total += 1
	print(total)


def f(h):
	return int(h / 2 * (3 * h + 1))

def how_many(n):
	if n == 2:
		return 1
	elif n == 1:
		return 0
	for i in range(1, 26000):
		fi = f(i)
		if fi > n:
			high = i - 2
			less = f(i - 1)
			total = n // less
			n -= n // less * less
			break
		elif fi == n:
			return 1
	z = high
	while True:
		if n == 1 or n == 0:
			return total
		fz = f(z)
		if n % fz == 0:
			total += n // fz
			return total
		elif fz < n:
			times = n // fz
			total += times
			n -= fz * times
		z -= 1

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		print(how_many(n))
main()


import os
import bisect

def get_sizes():
	s = [0]
	i = 1
	while s[-1] <= int(1000000000.0):
		s.append(s[-1] + (i - 1) * 3 + 2)
		i += 1
	return s
SIZES = get_sizes()[1:]

def g(n, p=0):
	if n < 2:
		return p
	b = SIZES[bisect.bisect_right(SIZES, n) - 1]
	return g(n - b, p + 1)

def pp(input):
	n_test = int(input())
	for t in range(n_test):
		n = int(input())
		print(g(n))
if 'paalto' in os.getcwd():
	from string_source import string_source
	s1 = string_source('5\n3\n14\n15\n24\n1\n')
	pp(s1)
else:
	pp(input)


import math
t = int(input())

def tri(n):
	return n * (3 * n + 1) // 2
for _ in range(t):
	n = int(input())
	ans = 0
	for i in range(30000, 0, -1):
		x = tri(i)
		while n >= x:
			n -= x
			ans += 1
	print(ans)


for t in range(int(input())):
	n = int(input())
	r = 0
	while n >= 2:
		d = int((-1 + (1 + 4 * 3 * 2 * n) ** 0.5) / 6)
		n -= d * (d + 1) // 2 * 3 - d
		r += 1
	print(r)


card_count = lambda n: (3 * n ** 2 + n) // 2
t = int(input())

def level_search(cards):
	level = 0
	(low, high) = (1, 10 ** 5)
	while low <= high:
		mid = (low + high) // 2
		if card_count(mid) < cards:
			if card_count(mid + 1) > cards:
				level = mid
				break
			else:
				low = mid + 1
		elif card_count(mid) > cards:
			if card_count(mid - 1) < cards:
				level = mid - 1
				break
			else:
				high = mid - 1
		else:
			level = mid
			break
	return cards - card_count(level)
for i in range(t):
	cards = int(input())
	p_count = 0
	while cards > 1:
		cards = level_search(cards)
		p_count += 1
	print(p_count)


from sys import stdin
from bisect import bisect_left as bl

def solve():
	return

def main():
	inp = stdin.readline
	d = []
	k = 0
	for i in range(1, 50000):
		k += 3 * i - 1
		d.append(k)
	for _ in range(int(inp())):
		ans = 0
		h = len(d)
		n = int(inp())
		while True:
			k = bl(d, n, 0, h)
			if d[k] == n:
				ans += 1
				break
			if k == 0:
				break
			ans += 1
			n -= d[k - 1]
		print(ans)
main()


import math
t = int(input())
for x in range(t):
	s = int(input())
	count = 0
	b = 1 / 3
	h = int(-b + math.sqrt(b ** 2 + 8 * s / 3) / 2) + 1
	while s > 1:
		i = int((3 * h ** 2 + h) / 2)
		if s - i < 0:
			h -= 1
		else:
			s -= i
			count += 1
	print(count)


import bisect
l = [0, 2]
x = 5
while l[-1] <= 10 ** 9:
	l.append(l[-1] + x)
	x += 3
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		i = bisect.bisect_right(l, n)
		k = n - l[i - 1]
		c += 1
		n = k
	print(c)


def Pyramid(n):
	return 3 * n * (n + 1) // 2 - n

def Solve():
	n = int(input())
	count = 0
	while n >= 2:
		for i in range(1, 100000):
			if Pyramid(i + 1) > n:
				count += 1
				n -= Pyramid(i)
				break
	print(count)
T = int(input())
for i in range(T):
	Solve()


A = [2, 7, 15, 26, 40, 57, 77, 100]
for i in range(int(input())):
	n = int(input())
	while A[len(A) - 1] < n:
		A.append(A[len(A) - 1] + 3 * len(A) + 2)
	ans = 0
	while n >= 2:
		k = 0
		while k < len(A) and A[k] <= n:
			k += 1
		n = n - A[k - 1]
		ans += 1
	print(ans)


import math
t = int(input())
for i in range(t):
	n = int(input())
	counter = 0
	while n > 1:
		h = math.floor((-1 + (1 + 24 * n) ** (1 / 2)) / 6)
		n -= h * (h + 1) + (h - 1) * h / 2
		counter += 1
	print(counter)


t = int(input())
while t > 0:
	n = int(input())
	if n == 1:
		print(0)
	else:
		i = 1
		count = 2
		while count < n:
			i += 1
			count += 2 * i + (i - 1)
		if count == n:
			print(1)
		elif count > n:
			num = 1
			count -= 2 * i + (i - 1)
			rem = n - count
			while rem > 1:
				i = 1
				count = 2
				while count < rem:
					i += 1
					count += 2 * i + (i - 1)
				num += 1
				if count == rem:
					rem = 0
				else:
					count -= 2 * i + (i - 1)
					rem = rem - count
			print(num)
	t -= 1


import math
t = int(input())
for hh in range(0, t):
	n = int(input())
	temp = n
	finalcount = 0
	while temp > 1:
		ans = int(math.sqrt(1 + 24 * temp))
		ans -= 1
		ans = ans // 6
		height_k_wale = ans * (3 * ans + 1) // 2
		cnt1 = temp // height_k_wale
		finalcount += cnt1
		temp = temp % height_k_wale
	print(finalcount)


for _ in range(int(input())):
	n = int(input())
	c = []
	while n > 1:
		t = int((-1 + (1 + 24 * n) ** (1 / 2)) // 6)
		c.append(t)
		n -= (3 * t ** 2 + t) // 2
	print(len(c))


x = 2
l = []
i = 5
while x < pow(10, 10):
	l.append(x)
	x += i
	i += 3

def search(l, a):
	for i in range(len(l)):
		if l[i] > a:
			return l[i - 1]
for _ in range(int(input())):
	n = int(input())
	a = n
	p = 0
	while a >= 2:
		p += 1
		a -= search(l, a)
	print(p)


import bisect
n = int(1000000000.0)
sm = []
lines = 0
for i in range(1, n + 1):
	x = i * (i + 1) + lines
	lines += i
	if x > n:
		break
	sm.append(x)
t = int(input())
for _ in range(t):
	m = int(input())
	k = 0
	while True:
		f = bisect.bisect_right(sm, m)
		if f == 0:
			break
		k += 1
		m -= sm[f - 1]
	print(k)


import math

def get_root_floor(y):
	a = 1.5
	b = 0.5
	c = -y
	delta = b ** 2 - 4 * a * c
	root = math.sqrt(delta)
	x1 = (-b + root) / (2 * a)
	return math.floor(x1)
turns = int(input())
in_data = []
for i in range(0, turns):
	in_data.append(int(input()))
for cards in in_data:
	count_tri = 0
	while cards >= 2:
		m = get_root_floor(cards)
		cards -= (3 * m ** 2 + m) / 2
		count_tri += 1
	print(count_tri)


arr = []
diff = 5
arr.append(2)
i = 0
while arr[i] <= 1000000000.0:
	arr.append(arr[i] + diff)
	diff += 3
	i += 1
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	pos = 0
	for i in range(0, len(arr)):
		if arr[i] > n:
			break
		pos = i
	ans = 0
	for i in range(pos, -1, -1):
		ans += n // arr[i]
		n = n % arr[i]
		if n == 0:
			break
	print(ans)


from sys import stdin, stdout

def input():
	a = stdin.readline()
	if a[-1] == '\n':
		a = a[:-1]
	return a

def print(*argv, end='\n', sep=' '):
	n = len(argv)
	for i in range(n):
		if i == n - 1:
			stdout.write(str(argv[i]))
		else:
			stdout.write(str(argv[i]) + sep)
	stdout.write(end)
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}
from math import floor

def solve(n):
	cnt = 0
	left = n
	while left > 1:
		if 24 * left + 1 >= 0:
			val = floor(((24 * left + 1) ** 0.5 - 1) / 6)
			left -= val * (3 * val + 1) / 2
			cnt += 1
	return cnt
for _ in range(int(input())):
	n = int(input())
	print(solve(n))


import math
t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	while n >= 2:
		n1 = int(math.sqrt(1 + 2 * 4 * 3 * n) - 1) // 6
		c += 1
		a = n1 * (n1 + 1) + n1 * (n1 - 1) // 2
		n = n - a
	print(c)


import sys
import math

def ints():
	return list(map(int, sys.stdin.readline().strip().split()))

def bs(arr, l, r, x):
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return r
c = [0]
(val, j) = (0, 1)
while c[-1] < 10 ** 9 + 1:
	val += j
	c.append(3 * val - j)
	j += 1
T = int(input())
while T:
	T -= 1
	n = int(input())
	ans = 0
	while n > 1:
		n -= c[bs(c, 0, len(c) - 1, n)]
		ans += 1
	print(ans)


t = int(input())

def tallest(x):
	if x < 2:
		return 0
	s = 2
	(base, ind2) = (2, 0)
	flagger = s
	while s < x:
		base += 2
		ind2 += 1
		flagger = s
		s = s + base + ind2
	if s == x:
		return s
	return flagger
for _ in range(t):
	n = int(input())
	ans = 0
	while n >= 2:
		z = tallest(n)
		n -= z
		if z > 1:
			ans += 1
	print(ans)


def c(n):
	if n < 2:
		return 0
	else:
		i = 1
		while n >= i * 2 + (i - 1):
			n = n - (i * 2 + (i - 1))
			i += 1
		return 1 + c(n)

def solution(t):
	for i in range(t):
		n = int(input())
		print(c(n))
solution(int(input()))


t = int(input())
h = []
for i in range(t):
	p = int(input())
	h.append(p)

def pyr_amid(n):
	i = 0
	p = 0
	if n == 0 or n == 1:
		return 0
	else:
		while p <= n:
			s = p
			p = (3 * i ** 2 + i) / 2
			i += 1
	count = 1 + pyr_amid(n - s)
	return count
for i in range(len(h)):
	k = pyr_amid(h[i])
	print(k)


n = int(input())
for i in range(n):
	k = 0
	m = int(input())
	while m >= 2:
		h = int((-1 + (1 + 24 * m) ** 0.5) / 6)
		m -= h * (3 * h + 1) / 2
		k += 1
	print(k)


t = int(input())
for _ in range(t):
	a = int(input())
	if a == 1:
		print(0)
	else:
		final = 0
		while a > 1:
			ans = 2
			prev = ans
			temp = 5
			while ans <= a:
				prev = ans
				ans = ans + temp
				temp += 3
			final += a // prev
			a = a % prev
		print(final)


n = int(input())
from math import *
for x in range(n):
	t = int(input())
	xy = ceil(t ** 0.5)
	counter = 0
	while xy > 0:
		if t >= xy * (3 * xy + 1) // 2:
			t -= xy * (3 * xy + 1) // 2
			counter += 1
		else:
			xy -= 1
	print(counter)


t = int(input())
while t:
	l = [2]
	i = 0
	val = int(input())
	while l[-1] < val:
		l.append(l[i] + 3 * i + 5)
		i += 1
	count = 0
	i = len(l) - 1
	while val > 1:
		if l[i] <= val:
			count += 1
			val = val - l[i]
		else:
			i -= 1
	print(count)
	t = t - 1


def f(x):
	S = 0
	for i in range(1, 100000):
		s = i * 2 + i - 1
		S += s
		if S > x:
			return S - s
t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		ans += 1
		n -= f(n)
	print(ans)


import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
nn = [int(input()) for i in range(t)]
N = max(nn)
c = [2]
for i in range(2, 100000):
	if c[-1] > N:
		break
	c.append(c[-1] + i * 3 - 1)
c = c[::-1]
for n in nn:
	res = 0
	for x in c:
		res += n // x
		n = n % x
		if n == 0:
			break
	print(res)


import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right

def find(a):
	if a < 2:
		return 0
	else:
		valx = (-0.5 + math.sqrt(0.25 + 6 * a)) // 3
		val = (3 * valx * valx + valx) // 2
		return 1 + find(a - val)
t = int(input())
for _ in range(t):
	n = int(input())
	print(find(n))


def pyramid(n):
	if n < 2:
		return 0
	level = 1
	total_cards = 0
	while True:
		cards_used = 2 * level + (level - 1)
		total_cards += cards_used
		if total_cards > n:
			total_cards -= cards_used
			break
		if total_cards == n:
			break
		level += 1
	return 1 + pyramid(n - total_cards)
t = int(input())
for v in range(t):
	n = int(input())
	ans = pyramid(n)
	print(ans)


import math

def calc(s):
	n1 = (-1 + math.sqrt(1 + 24 * s)) / 6
	n2 = (-1 - math.sqrt(1 + 24 * s)) / 6
	n = max(n1, n2)
	return n
t = int(input())
for i in range(0, t):
	s = int(input())
	n = 5
	x = 0
	while s >= 2:
		n = calc(s)
		if n == int(n):
			x += 1
			break
		else:
			n = int(n)
			s1 = int(n * (3 * n + 1) / 2)
			x += 1
			s = s - s1
	print(x)


import bisect
a = [2]
j = 2
while a[-1] <= 1000000000:
	a.append(a[-1] + 3 * j - 1)
	j = j + 1
t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	while n >= 2:
		p = bisect.bisect(a, n)
		n = n - a[p - 1]
		c = c + 1
	print(c)


import math
import sys
input = sys.stdin.readline
r1 = lambda : int(input())
rk = lambda : map(int, input().split())
rls = lambda : list(rk())
ls = [0] * 1000000
x = 2
ls[0] = x
i = 0
while ls[i] < 1000000000:
	x += 3
	i += 1
	ls[i] = ls[i - 1] + x
N = 25819
test = r1()
while test:
	test -= 1
	n = r1()
	ans = 0
	for i in range(N, -1, -1):
		if n <= 1:
			break
		if n >= ls[i]:
			a = n // ls[i]
			n = n - a * ls[i]
			ans += a
	print(ans)


for i in range(int(input())):
	n = int(input())
	h = 0
	k = 0
	while 1:
		j = k
		j = 3 / 2 * (h + 1) * (h + 1) + 1 / 2 * (h + 1)
		if j <= n:
			h += 1
			k = 3 / 2 * h * h + 1 / 2 * h
		else:
			break
	ans = 0
	while n > 1:
		if n // k > 0:
			ans += n // k
			n = n % k
		h -= 1
		k = 3 / 2 * h * h + 1 / 2 * h
	print(int(ans))


def find(n):
	low = 0
	high = len(l) - 1
	while low < high:
		mid = (low + high) // 2
		if l[mid] > n:
			high = mid - 1
		elif l[mid] < n:
			low = mid + 1
		else:
			return n
	if l[low] > n:
		return l[low - 1]
	else:
		return l[low]
l = [2]
for i in range(1, 100000):
	l.append((i + 1) * 2 + 3 * ((i + 1) * i) // 2)
for nt in range(int(input())):
	n = int(input())
	count = 0
	while n > 1:
		n -= find(n)
		count += 1
	print(count)


import math as m
for _ in range(int(input())):
	n = int(input())
	a = 0
	while n >= 2:
		a += 1
		x = (-1 + int(m.sqrt(1 + 24 * n))) // 6
		n -= x * (3 * x + 1) // 2
	print(a)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007

def main():
	arr = [0 for i in range(50001)]
	arr[0] = 2
	sm = arr[0] + 3
	for i in range(1, 50001):
		arr[i] = arr[i - 1] + sm
		sm += 3
	for t in range(I()):
		n = I()
		tmp = n
		c = 0
		while n >= 2:
			x = bisect_right(arr, n)
			n -= arr[x - 1]
			c += 1
		print(c)
main()


t = int(input())
for i in range(t):
	n = int(input())
	if n < 2:
		print(0)
	else:
		house = 0
		flag = False
		ost = int()
		while True:
			if flag == True:
				n = ost
			else:
				flag = True
			cards = 2
			h = 2
			while True:
				cards = 1.5 * h ** 2 + 0.5 * h
				if cards == n:
					house += 1
					break
				elif cards > n:
					h -= 1
					house += 1
					break
				h += 1
			ost = n - (1.5 * h ** 2 + 0.5 * h)
			if ost <= 1:
				break
		print(house)


z = [2]
for i in range(2, 100000):
	z += [2 * i + (i - 1) + z[-1]]
for _ in ' ' * int(input()):
	a = int(input())
	i = 0
	while a > z[i]:
		i += 1
	s = 0
	while i >= 0:
		while z[i] <= a:
			a -= z[i]
			s += 1
		i -= 1
	print(s)


def f(n):
	return int(3 * n * (n + 1) / 2 - n)

def cards(n):
	if n <= 1:
		return 0
	elif n == 2:
		return 1
	i = 1
	while True:
		if f(i) <= n:
			i += 1
		else:
			return 1 + cards(n - f(i - 1))

def main():
	T = int(input())
	for t in range(T):
		n = int(input())
		print(cards(n))
main()


for _ in range(int(input())):
	n = int(input())
	cnt = 0
	s = 0
	while 1:
		k = 1
		while s + k * (3 * k + 1) // 2 <= n:
			k += 1
		k -= 1
		if not k:
			break
		s += k * (3 * k + 1) // 2
		cnt += 1
	print(cnt)


import math
for _ in range(int(input())):
	n = int(input())
	flag = True
	c = 0
	while flag:
		if n >= 2:
			h = math.floor((-1 + math.sqrt(1 + 24 * n)) / 6)
			n = n - h * (3 * h + 1) / 2
			c += 1
		else:
			flag = False
	print(c)


import math
for _ in range(int(input())):
	n = int(input())
	used = 0
	rem = n
	count = 0
	h = 1
	while rem >= 2 and h >= 1:
		h = (-1 + math.sqrt(1 + 24 * rem)) / 6
		h = int(h)
		used = (3 * h ** 2 + h) / 2
		rem = rem - used
		count += 1
	print(count)


import sys
import math
from collections import defaultdict as ddict
from collections import deque
import heapq
from queue import Queue
from bisect import bisect_left
fast_inp = lambda : sys.stdin.readline().split('\n')[0]
read_list = lambda : fast_inp().split(' ')
read_listi = lambda : list(map(int, fast_inp().split(' ')))
read_listf = lambda : list(map(float, fast_inp().split(' ')))
read_int = lambda : int(fast_inp())
read_float = lambda : float(fast_inp())
read = lambda : fast_inp()
DEBUG = True

def debug(**kwargs):
	if not DEBUG:
		return
	print('*' * 20)
	for (k, v) in kwargs.items():
		print(f'\t{k}:{v}\t')
	print('*' * 20)
dp1 = [3, 9]
dp2 = [2, 7]
i = 3
while dp1[-1] < int(1000000000.0) + 100:
	dp1.append(dp1[-1] + 3 * i)
	dp2.append(dp1[-1] - i)
	i += 1

def solve() -> None:
	n = read_int()
	res = 0
	while n >= 2:
		res += 1
		x = bisect_left(dp2, n)
		if dp2[x] > n:
			x -= 1
		elif dp2[x] == n:
			break
		n -= dp2[x]
	print(res)
t = read_int()
for _ in range(t):
	solve()


import math

def helper(n):
	k = (-1 + math.sqrt(1 + 24 * n)) / 6
	a = math.floor(k)
	return int(a)
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	count = 0
	while n >= 2:
		f = helper(n)
		n -= (3 * f * f + f) / 2
		count += 1
	print(count)

def helper(n):
	k = (-1 + math.sqrt(1 + 24 * n)) / 6
	a = math.floor(k)
	return int(a)


t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	k = 0
	c = 0
	if n == 1:
		print('0')
	else:
		while n > 0:
			x = 0
			for j in range(1, n):
				x = x + 2 * j
				y = (j - 1) * j // 2
				if x + y == n:
					ans += 1
					c = 1
					break
				if x + y > n:
					ans += 1
					break
			if c == 1:
				break
			n = n - (x - 2 * j) - (j - 2) * (j - 1) // 2
			if n < 2:
				break
		print(ans)


def find_largest_smaller_than_number(list, number):
	start_index = 0
	final_index = len(list) - 1
	mid_index = start_index + (final_index - start_index) // 2
	while True:
		if number == list[mid_index]:
			return 0
		elif number < list[mid_index]:
			final_index = mid_index
			mid_index = start_index + (final_index - start_index) // 2
		elif number > list[mid_index]:
			start_index = mid_index
			mid_index = start_index + (final_index - start_index) // 2
		if start_index == mid_index:
			return number - list[mid_index]
HEIGHT = 30000
counts = [0] * (HEIGHT + 1)
counts[1] = 2
for i in range(2, HEIGHT + 1):
	counts[i] = counts[i - 1] + i * 2 + i - 1
for i in range(int(input())):
	number = int(input())
	counter = 0
	while number != 0 and number != 1:
		remaining = find_largest_smaller_than_number(counts, number)
		counter += 1
		number = remaining
	print(counter)


def findIndex(n):
	li = []
	i = 1
	h = 0
	s = 0
	while n >= s:
		s = i * 2 + 3 * h
		li.append(s)
		h += i
		i += 1
	return li
t = int(input())
for i in range(t):
	n = int(input())
	indx = []
	indx = findIndex(n)
	l = len(indx)
	count = 0
	i = l - 1
	while n > 1:
		while i >= 0:
			if indx[i] <= n:
				n = n - indx[i]
				count += 1
				i += 1
			i -= 1
	print(count)


import math

def formula(n):
	return n * (n + 1) + n * (n - 1) // 2
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	sqrt = math.floor(math.sqrt(n))
	c = 0
	for i in range(sqrt, 0, -1):
		if formula(i) <= n:
			x = n // formula(i)
			c += x
			n -= formula(i) * x
	print(c)


for _ in range(int(input())):
	n = int(input())
	res = 0
	while n > 1:
		k = 2
		while n >= k:
			n -= k
			k += 3
		res += 1
	print(res)


def power(x, n):
	res = 1
	while n != 0:
		if n & 1 == 1:
			res = res * x
		x = x * x
		n >>= 1
	return res
l = []
for i in range(1, int(1.4 * 18450)):
	l.append((3 * power(i, 2) + i) // 2)
for i in range(int(input())):
	n = int(input())
	count = 0
	while n > 1:
		i = 0
		while 1:
			if l[i] > n:
				n = n - l[i - 1]
				count += 1
				break
			i += 1
	print(count)


new_dict = {}
for i in range(int(input())):
	n = int(input())
	x = n
	cards = 0
	i = 1
	p = 0
	t = 0
	while x > 1:
		k = 2 + (i - 1) * 3
		if cards + k > x:
			p += 1
			x = x - cards
			if x in new_dict:
				p += new_dict[x]
				break
			cards = 0
			i = 1
		else:
			cards += k
			i += 1
		t += 1
	new_dict[n] = p
	print(p)


from sys import stdin, stdout
input = stdin.buffer.readline
t = int(input())
a = []
a.append(2)
val = 0
i = 1
while i < 26000:
	a.append(a[i - 1] + a[0] + 3 * i)
	i += 1
l = len(a)
while t > 0:
	n = int(input())
	ans = 0
	i = l - 1
	while i >= 0:
		if n >= a[i]:
			n -= a[i]
			ans += 1
		else:
			i -= 1
	print(ans)
	t -= 1


def bnsrh(h, m):
	l = 0
	r = len(h) - 1
	ans = 0
	while l <= r:
		mid = l + (r - l) // 2
		if h[mid] > m:
			ans = mid
			r = mid - 1
		else:
			l = mid + 1
	return m - h[ans - 1]
h = [0] * 77500
for i in range(77500):
	h[i] = int(i * (3 * i + 1) / 2)
t = int(input())
for i in range(t):
	n = int(input())
	result = 0
	while n > 1:
		n = bnsrh(h, n)
		result += 1
	print(result)


import math

def solve(c):
	a = 1.5
	b = 0.5
	c = -c
	d = b ** 2 - 4 * a * c
	sol = (-b + math.sqrt(d)) / (2 * a)
	return sol
t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	level = int(solve(n))
	while level > 0:
		count += 1
		n -= 1.5 * level ** 2 + 0.5 * level
		level = int(solve(n))
	print(count)


t = int(input())

def F(h, n):
	return h * (3 * h + 1) <= 2 * n

def b_search(n):
	l = 1
	r = n
	ans = -1
	while l <= r:
		mid = l + (r - l) // 2
		if F(mid, n):
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	ret = ans * (3 * ans + 1) // 2
	return ret
for _ in range(t):
	n = int(input())
	cnt = 0
	while n > 1:
		cnt += 1
		n -= b_search(n)
	print(cnt)


def foo(n):
	k = 2
	f = 2
	while n >= 3 + f + k:
		k += 3
		f += k
	n -= f
	return n
t = int(input())
for fk in range(t):
	n = int(input())
	q = 0
	while n >= 2:
		n = foo(n)
		q += 1
	print(q)


import math
for _ in range(int(input())):
	n = int(input())
	count = 0
	while n > 1:
		D1 = 0.25 + 4 * 1.5 * n
		r1 = (-0.5 + D1 ** 0.5) / 3
		if r1 != int(r1):
			r1 = r1 - 1
		r1 = math.ceil(r1)
		r1 = int(abs(r1))
		count += 1
		n = n - math.floor(1.5 * r1 ** 2 + 0.5 * r1)
	print(count)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		m = 2
		k = 5
		while m + k <= n:
			m += k
			k += 3
		n -= m
		ans += 1
	print(ans)


import math
from collections import defaultdict, Counter

def main():
	cards = int(input())
	total = 0
	while cards >= 2:
		h = 1
		while h * (3 * h + 1) // 2 <= cards:
			c = h * (3 * h + 1) // 2
			h += 1
		cards -= c
		total += 1
	print(total)
t = int(input())
for _ in range(t):
	main()


count = int(input())
row = []
for _ in range(count):
	row.append(int(input()))

def foobar(number):
	if number < 2:
		return 0
	x = -1 + (1 + 24 * number) ** 0.5
	x = int(x / 6)
	spent_cards = 2 * x + 3 * (x * (x - 1)) // 2
	left_cards = number - spent_cards
	return 1 + foobar(left_cards)
for _ in row:
	print(foobar(_))


import math
from sys import stdin, stdout
from heapq import heapify, heappop, heappush
from collections import Counter
T = int(stdin.readline())
for i in range(T):
	N = int(stdin.readline())
	np = 0
	if N < 2:
		print(0)
		continue
	while N >= 2:
		l = 1
		r = int(math.sqrt(N)) + 1
		while l <= r:
			m = l + (r - l) // 2
			if m * (m + 1) + m * (m - 1) // 2 <= N:
				ans = m
				l = m + 1
			else:
				r = m - 1
		np += 1
		N = N - (ans * (ans + 1) + ans * (ans - 1) // 2)
	print(np)


import math
t = int(input())
for _ in range(t):
	cards = int(input())
	total = 0
	while cards > 1:
		height = math.floor((-1 + math.sqrt(1 + 12 * 2 * cards)) / 6)
		cards -= height * (3 * height + 1) // 2
		total += 1
	print(total)


def bsearch(n):
	start = 1
	end = n
	valid = 0
	while start <= end:
		mid = (start + end + 1) // 2
		ca = mid * (mid + 1) + (mid - 1) * mid // 2
		if ca <= n:
			valid = ca
			start = mid + 1
		else:
			end = mid - 1
	return valid
for _ in range(int(input())):
	n = int(input().strip())
	c = 0
	while n > 1:
		c += 1
		n -= bsearch(n)
	print(c)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = int(inp())
	ans = 0
	nextNumber = 2
	height = 0
	while True:
		if n >= nextNumber:
			n -= nextNumber
			nextNumber += 3
			height += 1
		if n < nextNumber:
			nextNumber = 2
			if height > 0:
				ans += 1
			if n < 2:
				break
	print(ans)


n = int(input())
ltot = []
for k in range(1, n + 1):
	ltot.append(int(input()))
for i in range(len(ltot)):
	cards = ltot[i]
	j = 1
	count = 0
	ltemp = []
	while j >= 1:
		fom = (3 * j * j + j) // 2
		if fom > cards:
			if len(ltemp) != 0:
				count += 1
				sub = ltemp[-1]
				cards = cards - sub
				ltemp = []
				j = 1
			else:
				break
		else:
			ltemp.append(fom)
			j += 1
		if cards <= 0:
			break
	print(count)


def read_int():
	n = int(input())
	return n

def read_ints():
	ints = [int(x) for x in input().split(' ')]
	return ints

def gen_height_map():
	ht_step = 5
	hmap = [2]
	val = hmap[0]
	while val <= pow(10, 9):
		val += ht_step
		hmap.append(val)
		ht_step += 3
	return hmap

def get_height(hmap, n):
	i = 0
	ht = hmap[i]
	while ht <= n:
		i += 1
		ht = hmap[i]
	i -= 1
	rem = n - hmap[i]
	return rem

def solve(hmap, n):
	if n < 2:
		return 0
	cnt = 1
	rem = get_height(hmap, n)
	while rem >= 2:
		cnt += 1
		rem = get_height(hmap, rem)
	return cnt
t = read_int()
hmap = gen_height_map()
for case in range(t):
	n = read_int()
	sol = solve(hmap, n)
	print(sol)


ar = []
ar.append(2)
i = 2
while ar[-1] < 10 ** 9:
	ar.append(ar[-1] + 3 * i - 1)
	i += 1
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n >= 2:
		j = 0
		while ar[j + 1] <= n:
			j += 1
		ans += 1
		n -= ar[j]
	print(ans)


import math

def main():
	n = int(input())
	if n == 1:
		return 0
	else:
		loda = 0
		while n > 1:
			tem1 = math.sqrt(1 + 24 * n)
			mxh = math.floor((tem1 - 1) / 6)
			recrd = mxh * (3 * mxh + 1) // 2
			n = n - recrd
			loda += 1
		return loda
t = int(input())
while t:
	t -= 1
	print(main())


t = int(input())
for _ in range(t):
	n = int(input())
	comb = 0
	combs = []
	count = 0
	q = 1
	while comb < n:
		comb += 3 * q - 1
		combs.append(comb)
		q += 1
	combs.sort(reverse=True)
	for i in combs:
		while n >= i:
			if n - i >= 0:
				n -= i
				count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	cnt = 0
	while n > 1:
		i = 0
		while i * (3 * i + 1) // 2 <= n:
			i += 1
		i -= 1
		cnt += 1
		n -= i * (3 * i + 1) // 2
	print(cnt)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	for _ in range(int(input())):
		n = int(input())
		count = 0
		for i in range(10 ** 5):
			if n < 2:
				break
			count += 1
			height = int((-1 + (1 + 24 * n) ** 0.5) / 6)
			cards_needed = (3 * (height * height) + height) // 2
			n -= cards_needed
		print(count)
main()


import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_left

def solution(n):
	if n == 1:
		write(0)
		return
	arr = []
	(i, prev) = (1, 0)
	cur = i * (i + 1) // 2 * 2 + prev
	while cur <= n:
		cur = i * (i + 1) // 2 * 2 + prev
		arr.append(cur)
		prev = i * (i + 1) // 2
		i += 1
	if arr[bisect_left(arr, n)] == n:
		write(1)
		return
	(res, idx) = (0, bisect_left(arr, n))
	while idx > 0 and arr[idx - 1] < n:
		res += 1
		n -= arr[idx - 1]
		idx = bisect_left(arr, n)
		if arr[idx] == n:
			res += 1
			break
	write(res)

def main():
	for _ in range(r_int()):
		n = r_int()
		solution(n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


for _ in range(int(input())):
	n = int(input())
	count = 0
	lis = []
	for h in range(1, int(n ** (1 / 2) + 1)):
		lis.append((3 * h + 1) * h // 2)
	while n > 1:
		for i in range(len(lis) - 1, -1, -1):
			if n >= lis[i]:
				n -= lis[i]
				count += 1
				break
	print(count)


from bisect import bisect_left
cards = [(3 * i * i + i) / 2 for i in range(1, 100000)]
t = int(input())
while t:
	n = int(input())
	ans = 0
	while n > 1:
		index = bisect_left(cards, n)
		sub = cards[index]
		if sub > n:
			sub = cards[index - 1]
		n -= sub
		ans += 1
	print(ans)
	t -= 1


from collections import defaultdict, Counter
from functools import lru_cache
from heapq import heappush, heappop
from math import gcd, floor, ceil, sqrt
from sys import stdin, stdout

def ilist():
	return [int(x) for x in stdin.readline().strip().split(' ')]

def iint():
	return int(stdin.readline().strip())

def istr():
	return stdin.readline().strip()

def solve(n):
	res = 0
	while True:
		h = (sqrt(24 * n + 1) - 1) / 6
		h = int(h)
		if h == 0:
			break
		res += 1
		n -= h * (3 * h + 1) // 2
	return res
t = iint()
for _ in range(t):
	n = iint()
	print(solve(n))


import math

def tallest_sum(n):
	if n <= 1:
		return 0
	h = math.floor(math.sqrt(2 / 3 * n + 1 / 36) - 1 / 6 + 1e-07)
	return 1 + tallest_sum(n - int(1.5 * h ** 2 + 0.5 * h))
t = int(input())
for _ in range(t):
	n = int(input())
	print(tallest_sum(n))


def findlargestpyramid(x):
	tempx = 0
	tempval = 1
	while True:
		triangle = 1.5 * tempval ** 2 + 0.5 * tempval
		if triangle > x:
			break
		tempx = triangle
		tempval += 1
	return tempx

def findnumberofpyramids(x):
	count = 0
	while True:
		if x < 2:
			return count
		a = findlargestpyramid(x)
		count += 1
		x -= a
a = int(input())
for _ in range(a):
	s = int(input())
	print(findnumberofpyramids(s))


arr = []
arr.append(2)
len = 1
while arr[len - 1] < 1000000000.0:
	arr.append(arr[len - 1] + (3 * len + 2))
	len += 1

def binarySearchCount(key):
	left = 0
	right = len
	mid = 0
	while left < right:
		mid = (right + left) // 2
		if arr[mid] == key:
			while mid + 1 < len and arr[mid + 1] == key:
				mid += 1
			break
		elif arr[mid] > key:
			right = mid
		else:
			left = mid + 1
	while mid > -1 and arr[mid] > key:
		mid -= 1
	return mid
t = int(input())
while t > 0:
	inp = int(input())
	count = 0
	while inp >= 2:
		temp = binarySearchCount(inp)
		inp -= arr[temp]
		count += 1
	print(count)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 2:
		used = 2
		extra = 5
		while used + extra <= n:
			used += extra
			extra += 3
		n -= used
		ans += 1
	if n == 2:
		ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n >= 2:
		t1 = 5
		t2 = 2
		while n >= t2:
			t2 += t1
			t1 += 3
		n -= t2 - (t1 - 3)
		c += 1
	print(c)


def gen(set, max):
	k = 5
	n = 2
	while n <= max:
		set.add(n)
		n += k
		k += 3

def find(n, set):
	rem = 0
	ans = 0
	while n >= 2:
		if n in set:
			ans += 1
			n = rem
			rem = 0
		else:
			n -= 1
			rem += 1
	return ans

def main():
	t = int(input())
	tests = []
	m = 0
	while t:
		n = int(input())
		m = max(m, n)
		tests.append(n)
		t -= 1
	s = set()
	gen(s, m)
	for test in tests:
		print(find(test, s))
main()


for i in range(int(input())):
	n = int(input())
	ct = 0
	while n > 1:
		w = int(n ** 0.5)
		while w > 0:
			if (3 * w * w + w) / 2 <= n:
				break
			else:
				w -= 1
		qw = (3 * w * w + w) / 2
		n -= qw
		ct += 1
	print(ct)


import bisect
a = []
y = 1
j = 0
for i in range(100000):
	t = y * (y + 1) // 2
	sum1 = t * 2
	g = y
	g -= 1
	t = g * (g + 1) // 2
	a.append(sum1 + t)
	y += 1
	if sum1 + t > 10 ** 9:
		break
t = int(input())
for ii in range(t):
	n = int(input())
	sum1 = 0
	while n > 1:
		index = bisect.bisect_right(a, n)
		index -= 1
		sum1 += 1
		n -= a[index]
	print(sum1)


def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = int(input())
for k in range(t):
	n = int(input())
	x = 2
	j = 5
	c = 0
	y = 0
	while 1:
		if n < 2:
			break
		if x >= n:
			if x == n:
				c += 1
				break
			c += 1
			n = n - y
			x = 2
			j = 5
		else:
			y = x
			x = x + j
			j = j + 3
	print(c)


n = int(input())
var = [0] * n
for i in range(0, n):
	var[i] = int(input())
for i in range(0, n):
	count = 0
	a = ((24 * var[i] + 1) ** 0.5 - 1) / 6
	if a >= 1:
		count += 1
		while var[i] >= 2:
			a = int(a)
			var[i] = var[i] - ((a + 1) * a + a * (a - 1) / 2)
			a = ((24 * var[i] + 1) ** 0.5 - 1) / 6
			if a >= 1:
				count += 1
	print(count)


def construct(n):
	if n == 1:
		return [0, 1]
	elif n == 2:
		return [1, 0]
	cards = n - 2
	nodes = 2
	edges = 2
	while True:
		needed = nodes * 2 + (nodes - 1)
		if needed <= cards:
			cards -= needed
		else:
			return [1, cards]
		nodes += 1
t = int(input())
for i in range(t):
	n = int(input())
	counter = 0
	while n > 1:
		result = construct(n)
		if result[0]:
			counter += 1
		n = result[1]
	print(counter)


def reduce_cards(x):
	d = (1 + 4 * 3 * 2 * x) ** (1 / 2)
	a1 = (-1 + d) / 6
	a2 = (-1 - d) / 6
	if int(max(a1, a2)) <= 0:
		return -1
	reduced = x - cards_consumed(int(max(a1, a2)))
	if reduced >= 0:
		return reduced
	return -1

def cards_consumed(x):
	return x * 2 + (x - 1) * x / 2 * 3

def main_handler(number_of_cards):
	ctr = 0
	while True:
		temp = reduce_cards(number_of_cards)
		if temp >= 0:
			number_of_cards = temp
			ctr += 1
		else:
			break
	return ctr
TEST_CASES = int(input())
for _ in range(TEST_CASES):
	number_of_cards = int(input())
	output = main_handler(number_of_cards)
	print(output)


for i in range(int(input())):
	n = int(input())
	dic = {}
	i = 1
	dic[i] = 2
	while True:
		i += 1
		p = dic[i - 1] + 3 * i - 1
		if p <= n:
			dic[i] = p
		else:
			break
	count = 0
	i = len(dic)
	while i > 0:
		if n - dic[i] >= 0:
			n = n - dic[i]
			count += 1
		elif n - dic[i] >= 0:
			continue
		else:
			i -= 1
	print(count)


from math import inf, sqrt, floor, ceil
from collections import Counter, defaultdict, deque
from heapq import heappush as hpush, heappop as hpop, heapify as h
from operator import itemgetter
from itertools import product
from bisect import bisect_left, bisect_right
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n >= 2:
		h = floor((-1 + sqrt(1 + 24 * n)) // 6)
		n -= h * (3 * h + 1) // 2
		ans += 1
	print(ans)


import math

def solve(n):
	count = 0
	while n > 1:
		k = (-1 + math.sqrt(1 + 24 * n)) // 6
		n -= k * (k + 1) + k * (k - 1) / 2
		count += 1
	return count
for _ in range(int(input())):
	print(solve(int(input())))


t = int(input())

def get_n(h):
	return 3 / 2 * h ** 2 + 1 / 2 * h
for _ in range(t):
	n = int(input())
	cnt = 0
	while n > 0:
		prev_n = 0
		for h in range(1, int(100000.0)):
			cur_n = get_n(h)
			if cur_n <= n:
				prev_n = cur_n
			else:
				n = n - prev_n
				if prev_n != 0:
					cnt += 1
				break
		if prev_n == 0:
			break
	print(cnt)


c = int(input())
for i in range(c):
	n = int(input())
	need = 2
	h = 0
	built = []
	count = 0
	while n >= need:
		h += 1
		n -= need
		need = 2 + 3 * h
		if h == 1:
			used = 2
		else:
			used = 2 * h + int(h * (h - 1) / 2) * 3
		built.append(used)
	if len(built) >= 1:
		count += 1
	for j in range(-1, -(len(built) + 1), -1):
		ele = built[j]
		while n >= ele:
			count += 1
			n -= ele
	r = int(n / 2)
	print(count + r)


rr = lambda : input().strip()
rri = lambda : int(rr())
rrm = lambda : [int(x) for x in rr().split()]
from math import gcd
from sys import stdin, stdout

def sol():
	n = rri()
	res = 0
	while n > 1:
		k = 1
		while int(k * (3 * k + 1) / 2) <= n:
			k += 1
		k -= 1
		n -= int(k * (3 * k + 1) / 2)
		res += 1
	print(res)
	return
T = rri()
for _ in range(T):
	sol()


import math, sys
input = sys.stdin.readline

def inp():
	return int(input())
t = inp()
while t > 0:
	n = inp()
	c = 0
	while n > 1:
		x = 2
		while x <= n:
			n -= x
			x += 3
		c += 1
	print(c)
	t -= 1


t = int(input())
while t:
	n = int(input())
	c1 = 0
	while n > 0:
		i = 1
		c = 0
		a1 = 0
		a = 0
		while 1:
			if a == 0:
				a = i * (i + 1)
				a1 = a
				b = c + i - 1
				a += b
				c = b
				if a == n:
					c1 += 1
					n -= a
					break
				elif a > n:
					n = 0
					break
				else:
					i += 1
			else:
				a1 = a
				a = i * (i + 1)
				b = c + i - 1
				a += b
				c = b
				if a == n:
					c1 += 1
					n -= a
					break
				elif a > n:
					c1 += 1
					n -= a1
					break
				else:
					i += 1
	print(c1)
	t -= 1


import math, sys
import heapq
from fractions import Fraction
from collections import Counter, defaultdict

def li():
	return list(map(int, sys.stdin.readline().split()))

def ls():
	return list(map(int, list(input())))

def la():
	return list(input())

def ii():
	return int(input())

def dic(x):
	return defaultdict(lambda : x)

def isPrime(n):
	i = 2
	if n == 1:
		return False
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			return False
		i = i + 1
	return True

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def LCM(a, b):
	return a * b / gcd(a, b)
t = int(input())
for _ in range(t):
	n = ii()
	count = 0
	while n > 1:
		a = (math.sqrt(1 + 24 * n) - 1) // 6
		n -= (3 * a ** 2 + a) // 2
		count += 1
	print(count)


import math
t = int(input())
for z in range(t):
	n = int(input())
	a = 1.5
	b = 0.5
	c = n
	count = 0
	while c > 1:
		d = b ** 2 + 4 * a * c
		x = math.floor((-b + math.sqrt(d)) / (2 * a))
		c = n - (1.5 * x ** 2 + 0.5 * x)
		count += 1
		n = c
	print(count)


def Pyramids(n):
	a = 0
	t = 0
	preva = 0
	while 1:
		a = t * (3 * t + 1) / 2
		if a > n:
			temp = n - preva
			break
		preva = t * (3 * t + 1) // 2
		t = t + 1
	return temp
t = int(input())
res = 0
for i in range(t):
	res = 0
	n = int(input())
	if n <= 1:
		print(0)
		continue
	while 1:
		temp = Pyramids(n)
		if temp > 1:
			res = res + 1
			n = temp
		else:
			print(res + 1)
			break


import bisect
t = int(input())
c = 2
delta = []
delta.append(2)
for i in range(10 ** 6):
	c += 3
	temp = delta[-1]
	delta.append(temp + c)
for test in range(t):
	n = int(input())
	ans = 0
	while n >= 2:
		loc = bisect.bisect_right(delta, n)
		n -= delta[loc - 1]
		ans += 1
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
testcases = int(input())
for j in range(testcases):
	n = int(input())
	pyramids = 0
	rem = n
	bef = 2
	while rem > 0:
		for s in range(math.ceil(math.sqrt(n)) + 1):
			cur = 3 / 2 * s ** 2 + 7 / 2 * s + 2
			if cur <= rem:
				bef = cur
			elif cur > rem:
				break
		rem -= bef
		if rem >= 0:
			pyramids += 1
	print(pyramids)


T = int(input())
dp = {1: 2}
for _ in range(T):
	N = int(input())
	x = N
	count = 0
	while x >= 2:
		b = 1
		a = 3
		c = -2 * x
		d = (b * b - 4 * a * c) ** 0.5
		z = int((d - b) / (2 * a))
		x -= int(3 * (z * z + z) / 2 - z)
		count += 1
	print(count)


import math

def height_from_number(n):
	return math.floor((-1 + math.sqrt(1 + 24 * n)) / 6)

def number_from_height(h):
	return h * (3 * h + 1) // 2
t = int(input())
for _ in range(t):
	k = int(input())
	count = 0
	high = height_from_number(k)
	while high >= 1:
		if k >= 2:
			k -= number_from_height(high)
			count += 1
			high = height_from_number(k)
		else:
			break
	print(count)


from sys import stdin, gettrace
from math import sqrt
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		n = int(input())
		count = 0
		while n > 1:
			count += 1
			h = int((-1 + sqrt(1 + 24 * n)) / 6)
			n -= (3 * h * h + h) // 2
		print(count)
	q = int(input())
	for _ in range(q):
		solve()
main()


for T in range(1, int(input()) + 1):
	N = int(input())
	ans = 0
	i = 30000
	while N > 1:
		x = (3 * i * i + i) // 2
		if N >= x:
			ans += 1
			N -= x
		else:
			i -= 1
	print(ans)


from bisect import bisect_left

def fun(arr, k):
	g = bisect_left(arr, k)
	if g == 0:
		return -1
	if arr[g] == k:
		return g
	g -= 1
	if g == 0:
		return -1
	return g
m = 100000
arr = []
arr.append(0)
arr.append(2)
p = 2
for i in range(2, m):
	t = p + 2 * i + (i - 1)
	arr.append(t)
	p = t
	if p >= 1000000000:
		break
tc = int(input())
for zzz in range(tc):
	k = int(input())
	g = 0
	ans = 0
	while True:
		g = fun(arr, k)
		if g == -1:
			break
		else:
			k -= arr[g]
			ans += 1
	print(ans)


from typing import List

def pyramid():
	n = int(input())
	aux = n
	respuesta = 1
	altura = 1
	if n < 2:
		respuesta = 0
	while aux >= 2:
		aux = aux - 2 * altura - altura + 1
		if aux < 0:
			aux = aux + 2 * altura + altura - 1
			altura = 1
			respuesta = respuesta + 1
		else:
			altura = altura + 1
	print(respuesta)
t = int(input())
for i in range(t):
	pyramid()


import math
import cmath
t = int(input(''))
for i in range(t):
	n = int(input())
	num = 0
	while n > 1:
		num += 1
		d = 24 * n + 1
		x = int(math.floor((-1 + math.sqrt(d)) / (2 * 3)))
		n = n - int((3 * x * x + x) / 2)
	print(num)


def p(n):
	h = (-1 + (1 + 24 * n) ** 0.5) / 6
	return int(h)
t = int(input())
for i in range(t):
	c = 0
	n = int(input())
	while n > 1:
		x = p(n)
		c += 1
		n -= (3 * x * x + x) / 2
	print(c)


x = 2
last = 2
arr = [2]
while last <= 1000000000:
	x += 3
	last += x
	arr.append(last)
from sys import stdin, stdout
for testcases in range(int(stdin.readline())):
	n = int(stdin.readline())
	if n == 1:
		print(0)
	else:
		count = 0
		while n > 1:
			low = 0
			high = len(arr)
			found = False
			while low < high:
				mid = low + (high - low) // 2
				if arr[mid] == n:
					n -= arr[mid]
					count += 1
					found = True
					break
				elif arr[mid] > n:
					high = mid
				else:
					low = mid + 1
			if found == False:
				n -= arr[low - 1]
				count += 1
		print(count)


import bisect
T = int(input())
x = 0
a = []
for i in range(1, 100000):
	x += i * 3
	a.append(x - i)
for _ in range(T):
	n = int(input())
	b = bisect.bisect_left(a, n)
	an = n
	ans = 0
	for i in range(b + 1):
		ans += an // a[b - i]
		an = an % a[b - i]
	print(ans)


import bisect
dp = [0]
i = 1
maxm = 10 ** 9
while dp[-1] <= maxm:
	dp.append(dp[-1] + 3 * i - 1)
	i += 1
for _ in range(int(input())):
	n = int(input())
	t = 0
	while n > 0:
		ind = bisect.bisect(dp, n)
		if dp[ind] == n:
			t += 1
			n = 0
		elif ind == 0 and dp[ind] > n:
			break
		elif dp[ind - 1] <= n and ind > 1:
			t += 1
			n -= dp[ind - 1]
		else:
			break
	print(t)


from bisect import bisect_right
t = int(input())
tri = []
i = 1
a = 0
while a <= 10 ** 9:
	a = (3 * i ** 2 + i) // 2
	tri.append(a)
	i += 1
for i in range(t):
	res = 0
	piece = int(input())
	while piece > 1:
		idx = bisect_right(tri, piece)
		piece -= tri[idx - 1]
		res += 1
	print(res)


from bisect import bisect_right
t = int(input())
numbers = [i * (3 * i + 1) // 2 for i in range(1, 50000)]
for _ in range(t):
	n = int(input())
	left = 0
	right = len(numbers)
	count = 0
	while n >= numbers[0]:
		idx = bisect_right(numbers, n) - 1
		n -= numbers[idx]
		count += 1
	print(count)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
tmp = []
i = 2
j = 2
while i < int(1000000000.0):
	tmp.append(i)
	j += 2
	i += j + j // 2 - 1
for _ in range(int(input())):
	n = int(input())
	m = len(tmp)
	res = 0
	while n > 1:
		x = tmp[bisect.bisect_right(tmp, n) - 1]
		res += 1
		n -= x
	print(res)


from sys import stdin, stdout
from bisect import bisect_left, bisect_right
arr = [2]
for i in range(1, 3 * 10 ** 4):
	arr.append(arr[-1] + i * 3 + 2)
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	ctr = 0
	while n >= 2:
		t1 = bisect_left(arr, n)
		t2 = bisect_right(arr, n)
		if t1 == t2:
			n -= arr[t1 - 1]
			ctr += 1
		else:
			n -= arr[t1]
			ctr += 1
	stdout.write(str(ctr) + '\n')


for _ in range(int(input())):
	n = int(input())
	dp = {}
	dp[0] = 0
	i = 0
	while True:
		if dp[i] <= n:
			dp[i + 1] = dp[i] + 2 * (i + 1) + i
		else:
			left = n - dp[i]
			break
		i += 1
	left = n
	ans = 0
	p = list(dp.values())
	l = len(p)
	while left > 1:
		for i in range(l):
			if left >= p[i]:
				continue
			else:
				left = left - p[i - 1]
				ans += 1
				break
	print(ans)


from bisect import bisect_left
l = [2]
i = 2
s = 0
while s < 1000000000.0:
	s = 2 * i + (i - 1) + l[i - 2]
	l.append(s)
	i += 1
t = int(input())
for _ in range(t):
	n = int(input())
	i = 0
	nb = 0
	while i >= 0 and n > 1:
		i = bisect_left(l, n)
		if l[i] != n:
			i -= 1
		nb += 1
		if i >= 0:
			n = n - l[i]
	print(nb)


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
s = set()
t = 2
i = 1
z = []
while t <= 1000000000:
	t = (3 * i * i + i) // 2
	i += 1
	s.add(t)
	z.append(t)
for _ in range(int(input())):
	n = int(input())
	count = 0
	while n >= 2:
		if n in s:
			count += 1
			break
		else:
			f = 2
			for i in z:
				if i > n:
					n = n - f
					count += 1
					break
				f = i
	print(count)


for _ in range(int(input())):
	n = int(input())
	op = 0
	while n > 1:
		i = 1
		si = 0
		while i * (3 * i + 1) // 2 <= n:
			si = i * (3 * i + 1) // 2
			i += 1
		n = n - si
		op += 1
	print(op)


test = int(input())
for _ in range(test):
	x = int(input())
	ans = 0
	while x > 1:
		for i in range(1, x + 1):
			req = 3 * i * (i + 1) // 2 - i
			if req >= x:
				if req == x:
					x = x - req
				else:
					x = x - prev
				ans += 1
				break
			prev = req
	print(ans)


for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
	elif n == 2:
		print(1)
	else:
		c = 0
		i = 1
		while n >= 2:
			i = 1
			while 2 * i <= n:
				if n >= 3 * i + 2 * (i + 1):
					n -= 3 * i
				else:
					n -= 2 * i
					break
				i += 1
			c += 1
		print(c)


def main():
	import sys, math
	from collections import defaultdict as dd, deque

	def data():
		return sys.stdin.readline().strip()

	def mdata():
		return list(map(int, data().split()))
	out = sys.stdout.write
	INF = int(1000000000.0)
	mod = int(1000000000.0) + 7
	for t in range(int(data())):
		n = int(data())
		cnt = 0
		t = 0
		while n:
			t = int((1 + 24 * n) ** 0.5 - 1) // 6
			n -= (3 * t * t + t) // 2
			if t == 0:
				break
			cnt += 1
		out(str(cnt) + '\n')
main()


def build_series():
	serie = [2, 7]
	current = 7
	variation = 5
	while current <= 10 ** 9:
		variation += 3
		current = current + variation
		serie.append(current)
	return serie

def main():
	serie = build_series()
	T = int(input())
	for i in range(1, T + 1):
		result = 0
		n = int(input())
		while n > 1:
			for (index, j) in enumerate(serie):
				if j > n:
					result += 1
					n = n - serie[index - 1]
					break
		print(result)
main()


import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(str(val) + '\n')

def binary(cards, n):
	start = 0
	end = len(cards) - 1
	while end > start:
		mid = (start + end) // 2
		if cards[mid] == n:
			n = 0
			return n
		if cards[mid] > n:
			end = mid - 1
		elif cards[mid] < n:
			start = mid + 1
	if cards[start] > n:
		n -= cards[start - 1]
	elif cards[start] <= n:
		n -= cards[start]
	return n

def yo():
	cards = [2 * x + 3 * (x - 1) * x // 2 for x in range(1, 3 * 10 ** 4)]
	for _ in range(int(input().strip())):
		n = int(input().strip())
		placed = 0
		if n == 1:
			print(0)
		else:
			while not (n == 0 or n == 1):
				n = binary(cards, n)
				placed += 1
			print(placed)
yo()


try:

	def BinarySearch(a, x, n):
		l = 0
		h = n
		if a[n] < x:
			return n
		while l <= h:
			mid = (l + h) // 2
			if a[mid] == x:
				return mid
			elif a[mid] < x:
				if arr[mid + 1] > x:
					return mid
				else:
					l = mid + 1
			elif arr[mid - 1] < x:
				return mid - 1
			else:
				h = mid - 1
	t = int(input())
	while t:
		t -= 1
		n = int(input())
		arr = list()
		arr.append(0)
		temp = 0
		count = 0
		i = 1
		while n > 1:
			temp = arr[i - 1] + (3 * i - 1)
			if temp > n:
				count += 1
				n -= arr[-1]
				i -= 1
				break
			arr.append(temp)
			i += 1
		while n > 1:
			j = BinarySearch(arr, n, i)
			count += 1
			n -= arr[j]
		print(count)
except Exception:
	pass


import math
n = int(input())
for i in range(n):
	total = int(input())
	counter = 0
	while total > 1:
		x = int(math.floor((total / 1.5) ** 0.5) - 1)
		for j in range(x, x + 3):
			if (j + 1) * j * 1.5 - j <= total:
				best = j
				used = int((j + 1) * j * 1.5 - j)
		counter += 1
		total -= used
	print(counter)


l = [2, 7]
for _ in range(int(input())):
	n = int(input())
	i = 1
	c = 0
	if n == 1:
		print(0)
	elif n == 2:
		print(1)
	else:
		s = n
		k = 0
		while s > 1:
			while s - k - i * 2 > 0:
				k = k + i * 3
				i += 1
			c += 1
			if s - k - i * 2 == 0:
				break
			else:
				s = s - k + (i - 1) * 3 - (i - 1) * 2
				i = 1
				k = 0
		print(c)


import math
t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	while n > 1:
		h = math.floor(((24 * n + 1) ** 0.5 - 1) / 6)
		x = (3 * h * h + h) / 2
		j = n // x
		c += j
		n = n - j * x
	print(int(c))


import math
for i in range(int(input())):
	n = int(input())
	i = 0
	if n == 1:
		print(0)
	else:
		while n > 1:
			i += 1
			d = int(math.sqrt(1 + 24 * n) - 1) // 6
			n -= 3 * (d * (d + 1) // 2) - d
		print(i)


t = int(input())
for q in range(t):
	n = int(input())
	if n < 2:
		print(0)
		continue
	h = 1
	count = 0
	while True:
		if n < 2:
			count += 1
			break
		if n < h * 2 + (h - 1):
			h = 1
			count += 1
			continue
		else:
			n -= h - 1
			n -= h * 2
			h += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	if n < 2:
		print(0)
	else:
		count = 0
		while n >= 2:
			ini = 2
			add = 5
			while ini <= n:
				ini += add
				add += 3
			ini -= add - 3
			n -= ini
			count += 1
		print(count)


def construct_pyramid(x):
	s = 2
	h = 2
	while s <= x:
		best = s
		s += 3 * h - 1
		h += 1
	return x - best

def main():
	d = {}
	t = int(input())
	for _ in range(t):
		x = int(input())
		pyramids = 0
		while x >= 2:
			rest = construct_pyramid(x)
			x = rest
			pyramids += 1
		print(pyramids)
main()


MOD = 10 ** 9 + 7

def main():
	test = int(input())
	arr = []
	value = 2
	update = 5
	while value <= 10 ** 9:
		arr.append(value)
		value += update
		update += 3
	arr.reverse()
	for iteration in range(test):
		n = int(input())
		count = 0
		for i in arr:
			while n >= i:
				count += 1
				n -= i
		print(count)
main()


for _ in range(int(input())):
	py = 0
	n = int(input())
	if n == 1:
		print(0)
	else:
		while n > 1:
			h = int((-1 + (1 + 24 * n) ** 0.5) / 6)
			n = n - (3 * h ** 2 + h) / 2
			py += 1
		print(py)


a = [0] * 100000
for i in range(1, 100000):
	a[i] = int(i * i * 1.5 + 0.5 * i)
for i in range(int(input())):
	n = int(input())
	count = 0
	while n >= 2:
		x = 0
		while a[x] <= n:
			x += 1
		n -= a[x - 1]
		count += 1
	print(count)


for test in range(int(input())):
	n = int(input())
	lt = []
	s = 0
	i = 1
	while True:
		lt.append(i * (i + 1) + i * (i - 1) // 2)
		if lt[i - 1] > n:
			break
		i += 1
	j = 0
	while True:
		if lt[j] > n:
			if n != 1:
				s += 1
			n = n - lt[j - 1]
			j = -1
		j += 1
		if n < 2:
			break
	print(s)


def h_to_n(h):
	return (3 * h * h + h) // 2

def n_to_h(n):
	h = ((1 + 24 * n) ** 0.5 - 1) // 6
	return h
t = int(input())
for tt in range(t):
	n = int(input())
	pyramid_count = 0
	while True:
		if n_to_h(n) == 0:
			break
		n -= h_to_n(n_to_h(n))
		pyramid_count += 1
	print(pyramid_count)


from math import sqrt

def cards_for_h(h):
	return h * (h + 1) + (h - 1) * h // 2

def get_root(x):
	ac = sqrt(x * 24)
	return (-1 + ac) / 6
for i in range(int(input())):
	pyramids = 0
	cards_given = int(input())
	while cards_given > 1:
		h = round(get_root(cards_given))
		removable = cards_for_h(h)
		if removable > cards_given:
			cards_given = cards_given - cards_for_h(h - 1)
			pyramids += 1
		else:
			cards_given -= removable
			pyramids += 1
	print(pyramids)


import math
t = int(input())
for i in range(t):
	k = int(input())
	n = c = 0
	while k >= 2:
		n = math.floor(((1 + 24 * k) ** 0.5 - 1) / 6)
		k = k - (3 * n * n + n) / 2
		c = c + 1
	print(c)


x = 0
i = 1
a = []
while x < 10 ** 9:
	x = i * (i - 1) / 2 * 3 + 2 * i
	a.append(int(x))
	i += 1
a.reverse()
for _ in range(int(input())):
	n = int(input())
	sol = 0
	for i in range(len(a)):
		while n - a[i] >= 0:
			n -= a[i]
			sol += 1
	print(sol)


t = int(input())
for _ in range(t):
	n = int(input())
	counter = 0
	while n >= 2:
		root = ((1 + 24 * n) ** 0.5 - 1) // 6
		n -= (3 * root ** 2 + root) // 2
		counter += 1
	print(counter)


import math
t = int(input())
for w in range(1, t + 1):
	m = int(input())
	ans = 0
	while m >= 2:
		h = int((int(math.sqrt(24 * m + 1)) - 1) // 6)
		if h != 0:
			ans += 1
		m -= 2 * h + int(3 * h * (h - 1) // 2)
		if m < 2:
			break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	while n >= 2:
		d = (1 + 8 * 3 * n) ** (1 / 2)
		layers = (d - 1) // 6
		n -= (3 * layers ** 2 + layers) / 2
		count += 1
	print(count)


import collections
from math import sqrt
import bisect

def pyramid(h):
	for h in range(1, int(MAX_N)):
		pyramid_card_counts[h] = int(h ** 2 * 3 / 2 + h * 1 / 2)

def solve(n):
	ans = 0
	while n >= pyramid_card_counts[1]:
		index = bisect.bisect(pyramid_card_counts, n)
		if index == 0:
			break
		pyramid_cards = pyramid_card_counts[index - 1]
		count = n // pyramid_cards
		ans += count
		n -= pyramid_cards * count
	return ans
MAX_N = int(sqrt(10 ** 9) + 1)
pyramid_card_counts = [0 for _ in range(MAX_N + 1)]
pyramid(MAX_N)
t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	print(solve(n))


t = int(input())
while t != 0:
	a = int(input())
	x = 2
	y = 2
	count = 0
	while a >= 2:
		while True:
			if x < a:
				y = y + 3
				z = x
				x = x + y
				continue
			else:
				if x == a:
					z = a
				a = a - z
				count = count + 1
				x = 2
				y = 2
				break
	print(count)
	t = t - 1


from math import sqrt

def f(k):
	return int((sqrt(24 * k + 1) - 1) / 6)

def p(n):
	return (3 * n * n + n) / 2

def solve():
	final = 0
	n = int(input())
	while n >= 2:
		n -= p(f(n))
		final += 1
	print(final)
t = int(input())
for tt in range(1, t + 1):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	tot = 0
	while n >= 2:
		k = 2 * n
		s = int((k / 3) ** (1 / 2))
		while s / 2 + 3 / 2 * s * s < n:
			s += 1
		while s / 2 + 3 / 2 * s * s > n:
			s -= 1
		n -= int(s / 2 + 3 / 2 * s * s)
		tot += 1
	print(tot)


x = [2]
i = 1
while x[i - 1] <= 10 ** 9:
	x.append(x[i - 1] + 3 * (i + 1) - 1)
	i += 1
for i in range(int(input())):
	t = int(input())
	cnt = 0
	for p in range(25819, -1, -1):
		if x[p] <= t:
			cnt += t // x[p]
			t = t % x[p]
	print(cnt)


def pregen(x=25852):
	return [n * (3 * n + 1) // 2 for n in range(1, x)]

def solve(n):
	ans = 0
	while n > 1:
		n -= arr[binsearch_pos(n)]
		ans += 1
	return ans

def binsearch_pos(n):
	(l, r) = (0, len(arr))
	for i in range(50):
		m = (r + l) // 2
		if arr[m] > n:
			r = m
		else:
			l = m
	return l
arr = pregen()
t = int(input())
while t:
	t -= 1
	print(solve(int(input())))


for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		tmp = 2
		i = 1
		while tmp + 2 + 3 * i <= n:
			tmp += 2 + 3 * i
			i += 1
		n -= tmp
		ans += 1
	print(ans)


def bs(val):
	l = 0
	r = 1000000000
	best = 0
	while l <= r:
		mid = (l + r) // 2
		req = mid * (mid + 1) + (mid - 1) * mid // 2
		if req <= val:
			best = mid
			l = mid + 1
		else:
			r = mid - 1
	if best != 0:
		return best
	else:
		return 0

def solve():
	n = int(input())
	ans = 0
	while n > 0:
		retval = bs(n)
		if retval == 0:
			break
		ans += 1
		subval = retval * (retval + 1) + (retval - 1) * retval // 2
		n -= subval
	print(ans)
	return
t = 1
t = int(input())
while t > 0:
	t -= 1
	solve()


from sys import stdout, stdin
from math import sqrt
import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	n = int(input())
	count = 0
	while 1:
		a = -1 + sqrt(1 + 4 * 6 * n)
		a = a // 6
		if a == 0:
			break
		count += 1
		n = n - (3 * a * a + a) // 2
		if n <= 6:
			count += n // 2
			break
	print(int(count))


cards = [(1, 1, 2)]
for _ in range(30000):
	(p, lp, c) = cards[-1]
	lpn = lp + 1
	pn = p + lpn
	cn = c + lp + 2 * lpn
	cards.append((pn, lpn, cn))

def solve(n):
	sol = 0
	for i in range(len(cards) - 1, -1, -1):
		while n >= cards[i][2]:
			n -= cards[i][2]
			sol += 1
	return sol
t = int(input())
for _ in range(t):
	n = int(input())
	print(solve(n))


import math
test = int(input())
for tes in range(test):
	n = int(input())
	cnt = 0
	if n == 0 or n == 1:
		print(0)
		continue
	while True:
		sq = math.sqrt(1 + 24 * n) - 1
		h = sq // 6
		n = n - h * (3 * h + 1) / 2
		cnt += 1
		if n == 1 or n == 0:
			break
	print(cnt)


def solve(n):
	if n == 1:
		return 0
	if n == 2:
		return 1
	val = 2
	l = [2]
	plus = 5
	while val <= n:
		val += plus
		l.append(val)
		plus += 3
	l = l[::-1]
	count = 0
	i = 0
	while n > 0 and i < len(l):
		while l[i] <= n:
			n -= l[i]
			count += 1
		i += 1
	return count
t = int(input())
for we in range(t):
	n = int(input())
	print(solve(n))


t = int(input())
for i in range(0, t):
	n = int(input())
	cards = 2
	dp = [2]
	h = 2
	while cards <= n:
		cards += h * 2 + 1 * (h - 1)
		if cards <= n:
			dp.append(cards)
			h += 1
	res = 0
	low = 0
	high = len(dp)
	flag = 1
	while low < high and n > 1:
		mid = (low + high) // 2
		if dp[mid] == n:
			n -= dp[mid]
			res += 1
			if n <= 1:
				break
			low = 0
			high = mid
		elif n > dp[mid]:
			low = mid + 1
		elif n < dp[mid]:
			high = mid
		if high == low:
			n -= dp[high - 1]
			res += 1
			high = low
			low = 0
	print(res)


for _ in range(int(input())):
	n = int(input())
	result = 0
	while n >= 2:
		summary = 0
		count = 2
		height = 0
		while n >= summary + count:
			summary += count
			count += 3
			height += 1
		result += 1
		n -= summary
	print(result)


t = int(input())
while t > 0:
	n = int(input())
	count = 0
	p = 1
	while (3 * p * p + p) / 2 < n:
		p += 1
	while n > 1:
		while (3 * p * p + p) / 2 > n:
			p -= 1
		n -= (3 * p * p + p) / 2
		count += 1
	print(count)
	t -= 1


import bisect
n = 1
x = 2
cards_req = [2]
while x < 10 ** 9:
	n += 1
	x = n * (3 * n + 1) // 2
	cards_req.append(x)
t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n > 1:
		i = bisect.bisect_left(cards_req, n + 1)
		if i > 0:
			n -= cards_req[i - 1]
			c += 1
	print(c)


from sys import stdin, stdout
temp = [0, 1]
num = [0]
for i in range(2, 25900):
	num.append(2 * temp[-1] + temp[-2])
	temp.append(temp[-1] + i)
for test in range(int(stdin.readline())):
	n = int(stdin.readline())
	if n <= 1:
		stdout.write('0\n')
	else:
		count = 0
		while n > 1:
			for i in range(len(num)):
				if n == num[i]:
					count = count + 1
					n = n - num[i]
					break
				elif n < num[i]:
					count = count + 1
					n = n - num[i - 1]
					break
		stdout.write(str(count) + '\n')


t = int(input())
for _ in range(t):
	n = int(input())
	if n < 2:
		print(0)
		continue
	pyramids = 0
	arr = [2]
	i = 0
	card_count = 2
	base_count = 1
	while arr[i] <= n:
		arr.append(arr[i] + 2 * card_count + base_count)
		card_count += 1
		base_count += 1
		i += 1
	ptr = len(arr) - 2
	pyramids += 1
	n = n - arr[ptr]
	while n >= 2:
		ptr = 0
		while ptr + 1 < len(arr) and arr[ptr + 1] <= n:
			ptr += 1
		pyramids += 1
		n = n - arr[ptr]
	print(pyramids)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n >= 2:
		ans += 1
		(l, h) = (1, 10 ** 5)
		tans = -1
		while l <= h:
			mid = (l + h) // 2
			temp = (3 * mid * mid + mid) // 2
			if temp > n:
				h = mid - 1
			else:
				tans = temp
				l = mid + 1
		n = n - tans
	print(ans)


from sys import stdin
from bisect import bisect_left as bl
a = [2]
y = 4
z = 1
for i in range(1000000):
	a.append(a[-1] + y + z)
	y += 2
	z += 1
	if a[-1] > 10 ** 9:
		break
n = int(stdin.readline().strip())
for i in range(n):
	x = int(stdin.readline().strip())
	flag = True
	ans = 0
	while flag:
		y = bl(a, x)
		flag = False
		for j in range(y, y - 2, -1):
			if j >= 0 and j < len(a) and (a[j] <= x):
				flag = True
				x -= a[j]
				ans += 1
				break
	print(ans)


import math
import sys
input = sys.stdin.readline
arr = [2]

def binarySearch(l, r, x):
	if r >= l:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return arr[mid]
		elif arr[mid] > x:
			return binarySearch(l, mid - 1, x)
		else:
			if mid + 1 <= len(arr) - 1:
				if arr[mid] < x and arr[mid + 1] > x:
					return arr[mid]
			return binarySearch(mid + 1, r, x)
	else:
		return -1
arr1 = [2]
arr2 = [0]
for i in range(1, 100000):
	arr1.append(arr1[-1] + 2 * (i + 1))
	arr2.append(arr2[-1] + i)
	arr.append(arr1[i] + arr2[i])
t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	while n > 0:
		now = binarySearch(0, len(arr) - 1, n)
		if now == -1:
			break
		else:
			n -= now
			ans += 1
	print(ans)


def read_int():
	return int(input().strip())

def read_ints():
	return list(map(int, input().strip().split(' ')))

def count_cards(height):
	return height * (height + 1) + (height - 1) * height // 2

def solve():
	n = read_int()
	height = 0
	while count_cards(height + 1) <= n:
		height += 1
	count = 0
	while height > 0:
		if count_cards(height) > n:
			height -= 1
		else:
			count += 1
			n -= count_cards(height)
	return count
T = read_int()
for _ in range(T):
	print(solve())


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	if 2 <= n:
		a = [2]
	else:
		print(0)
		continue
	h = 1
	ans = 0
	lena = 1
	while True:
		x = a[-1] + 3 * h + 2
		if x <= n:
			a.append(x)
			lena += 1
		else:
			break
		h += 1
	ans += 1
	n = n - a[-1]
	while n >= 2:
		flag = 0
		for i in range(lena):
			if a[i] > n:
				key = i - 1
				flag = 1
				break
		if flag == 1:
			n -= a[key]
		else:
			n -= a[-1]
		ans += 1
	print(ans)


import math
t = int(input())
for _ in range(t):
	m = int(input())
	ans = 0
	a = 0
	while m > 1:
		a = (-1 + (1 + 24 * m) ** 0.5) / 6
		a = math.floor(a)
		ans += 1
		m -= (3 * a ** 2 + a) / 2
	print(ans)


def fun(val):
	i = 0
	j = len(arr) - 1
	while i <= j:
		mid = (i + j) // 2
		if arr[mid] == val:
			return mid
		if arr[mid] < val:
			i = mid + 1
		if arr[mid] > val:
			j = mid - 1
	return min(i, j)
n = int(input())
arr = [0, 2]
for i in range(2, 10 ** 9):
	if 2 * i + arr[i - 1] + i - 1 <= 10 ** 9:
		arr.append(2 * i + arr[i - 1] + i - 1)
	else:
		break
for i in range(n):
	N = int(input())
	c = 0
	while fun(N):
		idx = fun(N)
		N = N - arr[idx]
		c = c + 1
	print(c)


from math import sqrt

def main():
	n = int(input())
	res = 0
	while n >= 0:
		found = False
		for h in range(int(sqrt(n)) + 1, 0, -1):
			total_cards = 1.5 * h * h + 0.5 * h
			if n - total_cards >= 0:
				res += 1
				found = True
				n -= total_cards
				break
		if not found:
			break
	print(res)
t = int(input())
for i in range(t):
	main()


t = int(input())
for u in range(t):
	n = int(input())
	j = 0
	while n >= 2:
		tm = 0
		prev = 0
		i = 0
		while tm <= n:
			prev = tm
			tm += 2 * (i + 1) + i
			i += 1
		n -= prev
		j += 1
	print(j)


import sys

def read_int():
	return int(sys.stdin.readline())

def read_ints():
	return list(map(int, sys.stdin.readline().split()))
t = read_int()

def buildPyramid(card):
	if card < 2:
		return (0, 0)
	used = 2
	poverh = 1
	while card - used >= 3 * (poverh + 1) - 1:
		used += 3 * (poverh + 1) - 1
		poverh += 1
	return (poverh, card - used)
for j in range(t):
	n = read_int()
	lost = n
	pyramids = 0
	while lost > 1:
		(p, lost) = buildPyramid(lost)
		pyramids += 1
	print(pyramids)


t = int(input())
for tt in range(t):
	n = int(input())
	m = 0
	while n > 1:
		k = 2
		while n - k >= 0:
			n = n - k
			k = k + 3
		m += 1
	print(m)


def cardConstructions(n):
	count = 0
	i = int(n ** 0.5)
	if n == 2 or n == 3:
		return 1
	elif n == 1:
		return 0
	else:
		while n >= 2:
			if n - (3 * (1 / 2) * i ** 2 + 1 / 2 * i) >= 0:
				count += 1
				n = n - (3 * (1 / 2) * i ** 2 + 1 / 2 * i)
				i = int(n ** 0.5)
			else:
				i -= 1
		return count
for i in range(int(input())):
	n = int(input())
	print(cardConstructions(n))


t = int(input())
for i in range(t):
	a = int(input())
	j = 0
	count = 1
	sum = 0
	z = 0
	while a >= 2:
		z = z + (3 * count - 1)
		if a >= z:
			count = count + 1
		else:
			a = a - (z - (3 * count - 1))
			count = 1
			sum = sum + 1
			z = 0
	print(sum)


t = int(input())
a = [2]
c = 5
i = 1
while a[-1] < 1000000000:
	a.append(a[i - 1] + c)
	i += 1
	c += 3
for i10 in range(t):
	n = int(input())
	p = 0
	while n >= 2:
		l = 0
		r = len(a)
		while l + 1 != r:
			m = (l + r) // 2
			if a[m] > n:
				r = m
			else:
				l = m
		n -= a[l]
		p += 1
	print(p)


t = int(input())
arr = []
for i in range(1, 25821):
	x = i * (3 * i + 1) // 2
	arr.append(x)
for _ in range(t):
	n = int(input())
	count = 0
	end = len(arr)
	while n > 1:
		start = 0
		e = end
		while start <= e:
			mid = (start + e) // 2
			if arr[mid] <= n:
				start = mid + 1
			else:
				e = mid - 1
		n = n - arr[e]
		end = start
		count += 1
	print(count)


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	count = 0
	for i in range(30000, 0, -1):
		s = int(i * (3 * i + 1) / 2)
		while s <= n:
			count += 1
			n -= s
	print(count)


from bisect import bisect_right

def pyramid(h):
	return 3 * (h * (h + 1) // 2) - h
p = [pyramid(h) for h in range(1, 26000)]
t = int(input())
for _ in range(t):
	n = int(input())
	i = 0
	while n >= 2:
		i += 1
		b = p[bisect_right(p, n) - 1]
		n -= b
	print(i)


import math
t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	while True:
		f = int((-1 + math.sqrt(1 + 24 * n)) / 6)
		n = n - (2 * f + 3 * f * (f - 1) / 2)
		if f >= 1:
			count += 1
		else:
			count += 0
		if n < 2:
			print(count)
			break


def h(x):
	s = (-1 + (1 + 24 * x) ** 0.5) / 6
	q = (-1 - (1 + 24 * x) ** 0.5) / 6
	if s >= 0:
		return s
	else:
		return q
for j in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		c = c + 1
		p = int(h(n))
		n = n - (3 * p * p + p) // 2
	print(c)


t = int(input())

def main():
	numCards = int(input())
	numTowers = 0
	numCardsRemaining = numCards
	if numCards <= 1:
		print(0)
		return
	while numCardsRemaining > 1:
		cardsInTower = 0
		height = 0
		while True:
			height += 1
			numCardsInHeight = 3 * height - 1
			cardsInTower += numCardsInHeight
			if cardsInTower + 3 * height + 2 > numCardsRemaining:
				break
		numTowers += 1
		numCardsRemaining -= cardsInTower
	print(numTowers)
for i in range(t):
	main()


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	h = [0, 2]
	for i in range(2, 100000):
		if h[-1] > 10 ** 9:
			break
		h.append(h[i - 1] + 3 * (i - 1) + 2)
	for x in range(t):
		n = int(input())
		cnt = 0
		while n >= 2:
			index = bisect.bisect(h, n) - 1
			n = n - h[index]
			cnt += 1
		print(cnt)
main()


def reduce(num):
	h = (-1 + (1 + 24 * num) ** 0.5) // 6
	return 2 * h + 3 * (h - 1) * h // 2
ans = []
for h in range(int(input())):
	n = int(input())
	c = 0
	red = reduce(n)
	while red > 0 and n > 0:
		n -= red
		c += 1
		red = reduce(n)
	ans.append(str(c))
print('\n'.join(ans))


def f(x):
	return (3 * x ** 2 + x) // 2
for _ in range(int(input())):
	n = int(input())
	ans = 0
	x = 0
	while n > 1:
		if f(x + 1) < n:
			x += 1
		elif f(x + 1) == n:
			n = 0
			ans += 1
		else:
			n -= f(x)
			x = 0
			ans += 1
	print(ans)


def f(n):
	return (3 * n ** 2 + n) / 2

def total(n):
	if n == 0 or n == 1:
		return 0
	c = 0
	while n > 1:
		l = []
		i = 1
		while f(i) <= n:
			l.append(f(i))
			i += 1
		n = n - l[len(l) - 1]
		c += 1
	return c
t = int(input())
for tt in range(t):
	x = int(input())
	print(total(x))


from math import sqrt

def root(c):
	d = sqrt(0.25 + 6 * c)
	x = (-0.5 + d) // 3
	return x
t = int(input())
while t:
	n = int(input())
	c = 0
	while n > 1:
		x = root(n)
		n = n - x * (3 * x + 1) // 2
		c += 1
	print(c)
	t -= 1


def maxh(n):
	return int(((1 + 24 * n) ** 0.5 - 1) // 6)

def no(n):
	if n == 0 or n == 1:
		return 0
	else:
		a = maxh(n)
		s = (3 * a * a + a) // 2
		return 1 + no(n - s)
for _ in range(int(input())):
	n = int(input())
	print(no(n))


def main():
	t = int(input())
	for c in range(t):
		n = int(input())
		print(solve(n))

def h(n):
	return n * (3 * n + 1) // 2

def solve(n):
	count = 0
	i = 1
	while n >= 2:
		if h(i) <= n and h(i + 1) > n:
			n -= h(i)
			count += 1
			i = 1
		else:
			i += 1
	return count
main()


import math
num = int(input())
while num > 0:
	y = int(input())
	if y == 1:
		print('0')
		num -= 1
		continue
	elif y == 2:
		print('1')
		num -= 1
		continue
	t = 1
	x = int((-1 / 2 + math.sqrt(1 / 4 + 6 * y)) / 3)
	while True:
		if y - (3 * x * x + x) / 2 >= 2:
			y -= (3 * x * x + x) / 2
			x = int((-1 / 2 + math.sqrt(1 / 4 + 6 * y)) / 3)
			t += 1
		else:
			break
	print(t)
	num -= 1


import math

def quadr(a, b, c):
	d = b ** 2 - 4 * a * c
	sol1 = (-b - math.sqrt(d)) / (2 * a)
	sol2 = (-b + math.sqrt(d)) / (2 * a)
	return (sol1, sol2)
for _ in range(int(input())):
	n = int(input())
	o = 0
	while n > 1:
		(x1, x2) = quadr(3, 1, -2 * n)
		x3 = max(x1, x2)
		x4 = int(math.floor(x3))
		x5 = x4 * (3 * x4 + 1) // 2
		n = n - x5
		o += 1
	print(o)


import math
t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	while n >= 2:
		k = int((-1 + math.sqrt(1 + 24 * n)) // 6)
		count += 1
		n -= (3 * k ** 2 + k) // 2
	print(count)


T = int(input())
for _ in range(T):
	n = int(input())
	Ans = 0
	while n > 2:
		l = 1
		r = 1000000000
		ans = -1
		while l <= r:
			mid = (l + r) // 2
			Sum = mid * (mid + 1) // 2 * 3 - mid
			if Sum <= n:
				ans = mid
				l = mid + 1
			else:
				r = mid - 1
		n -= ans * (ans + 1) // 2 * 3 - ans
		Ans += 1
	if n > 1:
		Ans += 1
	print(Ans)


import math
stack1 = [2]
stack = []
k = int(1000000000.0)
x = 5
for i in range(0, 30000):
	if stack1[-1] < k:
		stack.append(stack1[-1])
	stack1.append(stack1[-1] + x)
	x += 3

def search(a):
	lo = 0
	hi = len(stack) - 1
	while lo <= hi:
		mid = (lo + hi) // 2
		if stack[mid] == a:
			return mid
		if stack[mid] < a:
			lo = mid + 1
		if stack[mid] > a:
			hi = mid - 1
	if stack[lo] > a:
		lo -= 1
	return lo

def xuly(nn):
	if nn >= stack[-1]:
		n1 = nn - stack[-1]
		return xuly(n1) + 1
	if nn == 0 or nn == 1:
		return 0
	if nn == 2:
		return 1
	else:
		pos = search(nn)
		n2 = nn - stack[pos]
		return xuly(n2) + 1
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	if n < 2:
		print(0)
	if n == 2:
		print(1)
	if n > 2:
		print(xuly(n))


import math
t = int(input())
for i in range(t):
	n = int(input())
	res = 0
	a = 3 / 2
	b = 7 / 2
	c = 2
	while n >= 2:
		new_c = c - n
		x = (-b + math.sqrt(b ** 2 - 4 * a * new_c)) // (2 * a)
		n -= a * x ** 2 + b * x + c
		res += 1
	print(res)


def numberCard(n):
	res = n * (n + 1) + n * (n - 1) // 2
	return int(res)

def process(n):
	if n < 2:
		return 0
	h = (6 * n + 0.25) ** 0.5
	h = (h - 0.5) / 3
	cards = numberCard(int(h))
	return 1 + process(int(n - cards))
limits = int(input())
for i in range(limits):
	n = int(input())
	res = process(n)
	print(res)


import math

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
t = inp()
while t:
	cards = inp()
	maxH = int(math.sqrt(cards)) + 1
	total = 0
	while cards > 1:
		for h in range(maxH, 0, -1):
			card_lagbe = int(round(2 * h + 3 * h * (h - 1) / 2))
			if card_lagbe <= cards:
				total += 1
				cards = cards - card_lagbe
				maxH = h
				break
	print(total)
	t -= 1


t = input()
t = int(t)
for tt in range(0, t):
	n = input()
	n = int(n)
	tower = 0
	while n > 1:
		for h in range(1, n):
			total = h * (3 * h + 1) // 2
			if total < n:
				continue
			if total > n:
				h -= 1
			total = h * (3 * h + 1) // 2
			n -= total
			tower += 1
			break
	print(tower)


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
for _ in range(ii()):
	n = ii()
	ans = 0
	while n > 2:
		i = int(math.sqrt((2 * n + 1 / 12) / 3) - 1 / 6 + 1e-09)
		n -= i * (3 * i + 1) // 2
		ans += 1
	else:
		if n == 2:
			ans += 1
	print(ans)


def maxhei(n):
	h = []
	h.append(0)
	h.append(2)
	for i in range(2, n + 1):
		y = i * h[1] + h[i - 1] + i - 1
		if y <= n:
			h.append(y)
		else:
			break
	return h[-1]
t = int(input())
ans = []
for p in range(t):
	n = int(input())
	c = 0
	while n > 1:
		x = maxhei(n)
		n = n - x
		c += 1
	ans.append(c)
for k in ans:
	print(k)


import sys
import math
try:
	sys.stdin = open('Input.txt', 'r')
	sys.stdout = open('Output.txt', 'w')
except:
	pass
input = sys.stdin.readline
for testCases in range(int(input())):
	x = int(input())
	h = 0
	cnt = 0
	while x > 1:
		h = -1 + (1 + 24 * x) ** 0.5
		h //= 6
		h = int(h)
		rem = 3 * h ** 2 + h
		rem //= 2
		x -= rem
		cnt += 1
	print(cnt)


a = [0, 2]

def triangle(h):
	cards = 0
	if len(a) > h:
		cards = a[h]
	else:
		cards = triangle(h - 1) + 2 * h + h - 1
		a.insert(h, cards)
	return cards
k = int(input())
p = []
for i in range(0, k):
	p.insert(i, int(input()))

def max(n):
	m = 0
	while triangle(m) <= n:
		m += 1
	return n - triangle(m - 1)

def number(b):
	count = 0
	while b >= 2:
		b = max(b)
		count += 1
	return count
for s in range(0, k):
	print(number(p[s]))


n = int(3.4 * 10 ** 4)
y = n
li1 = [0] * (n + 1)
li1[1] = 2
for a in range(2, n + 1):
	li1[a] += li1[a - 1] + 3 * a - 1
a = int(input())
for _ in range(a):
	b = int(input())
	x = b
	sum = 0
	while b > 1:
		for c in range(1, b // 3 + 2):
			if li1[c] == b:
				b = 0
				sum += 1
				break
			elif li1[c] > b:
				b -= li1[c - 1]
				sum += 1
				break
	print(sum)


def solve(q):
	for j in range(10 ** 9):
		if q < 2:
			return j
		for i in range(10 ** 9):
			diff = i + 2 * (i + 1)
			if q < diff:
				break
			q -= diff
n = int(input())
for _ in range(n):
	a = int(input())
	print(solve(a))


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		rem = int(input())
		a = 0
		while rem > 1:
			cards = 0
			i = 0
			while rem - cards >= 0:
				temp = cards + i + 2 * (i + 1)
				if rem - temp >= 0:
					cards = temp
					i += 1
				else:
					break
			rem -= cards
			a += 1
		print(a)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for i in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		ans += 1
		card = 2
		while n >= card:
			n -= card
			card += 3
	print(ans)


from math import *

def main():
	for _ in range(int(input())):
		n = int(input())
		ans = 0
		while True:
			tn = -(n * 2)
			a1 = int((-1 + sqrt(1 - 4 * 3 * tn)) // (2 * 3))
			if a1 == 0:
				break
			ans += 1
			n = n - a1 * (3 * a1 + 1) // 2
		print(ans)
main()


t = int(input())
for i in range(t):
	n = int(input())
	cersei = 0
	while n > 1:
		p = 1
		while n >= 3 * p * (p + 1) / 2 - p:
			p += 1
		p = p - 1
		pj = 3 * p * (p + 1) / 2 - p
		k = n - pj
		if k == 0:
			cersei += 1
			break
		else:
			cersei += 1
			n = k
	print(cersei)


def getCards(height):
	return 3 * height * (height + 1) // 2 - height

def getHeight(n):
	(l, r) = (0, n)
	while l < r:
		m = (l + r) // 2
		obj = getCards(m)
		if obj > n:
			r = m
		else:
			l = m + 1
	return l - 1
for t in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		n -= getCards(getHeight(n))
		ans += 1
	print(ans)


from sys import stdin
import collections
import copy
import math

def solver(n):
	num = 0
	while n >= 2:
		h = (math.sqrt(24 * n + 1) - 1) // 6
		n -= (3 * h ** 2 + h) / 2
		num += 1
	print(num)
	return 0
case = int(stdin.readline())
for i in range(case):
	n = int(stdin.readline())
	solver(n)


from math import sqrt

def f(h):
	return h * (3 * h + 1) // 2
a = []
for _ in range(int(input())):
	n = int(input())
	ans = 0
	for i in range(int(sqrt(n)), 0, -1):
		t = f(i)
		ans += n // t
		n %= t
	a.append(ans)
print('\n'.join(map(str, a)))


dp = []
a = 2
b = 5
while a <= 10 ** 9:
	dp.append(a)
	a += b
	b += 3
from bisect import bisect
for i in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		n -= dp[bisect(dp, n) - 1]
		ans += 1
	print(ans)


arr = []
n = 1
while 1:
	v = n * (n + 1) // 2 * 3 - n
	if v > 10 ** 9:
		break
	arr.append(v)
	n += 1
from bisect import bisect
T = int(input())
for _ in range(T):
	N = int(input())
	ans = 0
	while N >= 2:
		i = bisect(arr, N)
		v = arr[i - 1]
		N -= v
		ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	ans = 0
	c = []
	c.append(2)
	j = 1
	while n >= (j + 1) * 2 + j + c[j - 1]:
		c.append((j + 1) * 2 + j + c[j - 1])
		j += 1
	while n > 1:
		k = 0
		while k < len(c):
			if n < c[k]:
				break
			k += 1
		n -= c[k - 1]
		ans += 1
	print(ans)


n = int(input())
d = 0
for i in range(n):
	c = 0
	b = int(input())
	while b > 1:
		d = (-1 + (1 + 24 * b) ** 0.5) // 6
		b = b - d * (3 * d + 1) // 2
		c = c + 1
	print(c)


def correct(n):
	previous = 2
	for i in range(2, 100000000000000000000000, 1):
		c = i * (3 * i + 1) / 2
		if c > n:
			break
		else:
			previous = c
	return previous
t = int(input())
i = 0
while i < t:
	n = int(input())
	cards = 0
	while n > 1:
		new = correct(n)
		cards += 1
		n = n - new
	print(cards)
	i = i + 1


for _ in range(int(input())):
	n = int(input())
	dp = [0, 2]
	i = 1
	while dp[i] < n:
		i += 1
		dp.append(dp[i - 1] + 3 * i - 1)
	ans = 0
	j = i
	while j > 0:
		if dp[j] <= n:
			n -= dp[j]
			ans += 1
		else:
			j -= 1
		if n <= 1:
			break
	print(ans)


import sys
buff_readline = sys.stdin.buffer.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap
h = [0]
for i in range(1, 100000):
	h.append(h[-1] + i * 2 + i - 1)
assert h[-1] > 10 ** 9
import bisect

def slv(N):
	ans = 0
	while N >= h[1]:
		i = bisect.bisect_left(h, N)
		if h[i] != N:
			i -= 1
		N -= h[i]
		ans += 1
	return ans

def main():
	T = read_int()
	for _ in range(T):
		N = read_int()
		print(slv(N))
main()


n = int(input())
for i in range(n):
	t = int(input())
	summ = 0
	while t >= 2:
		o = 1
		k = 3 * (o * (o + 1) // 2) - o
		while k <= t:
			o += 1
			k = 3 * (o * (o + 1) // 2) - o
		summ += 1
		o -= 1
		t -= 3 * (o * (o + 1) // 2) - o
	print(summ)


import sys
readline = sys.stdin.readline

def solve():
	N = int(readline())
	ans = 0
	while True:
		for i in range(1, N + 2):
			if i * (3 * i + 1) // 2 > N:
				break
		if i == 1:
			break
		ans += 1
		N -= (i - 1) * (3 * (i - 1) + 1) // 2
	print(ans)
T = int(readline())
for i in range(T):
	solve()


import math
import sys

def fun1(val):
	return (3 * val + 1) * val // 2

def fun2(n, cnt):
	while n > 1:
		val = (-1 + int(math.sqrt(1 + 24 * n))) // 6
		temp = fun1(val)
		cnt += 1
		n -= temp
	return cnt
for _ in range(int(input())):
	n = int(input())
	print(fun2(n, 0))


l = [2]
for i in range(2, 100000):
	l.append(l[i - 2] + 2 * i + i - 1)
for _ in range(int(input())):
	n = int(input())
	a = 0
	while n >= l[0]:
		for i in range(len(l)):
			if n < l[i]:
				break
		n -= l[i - 1]
		a += 1
	print(a)


i_pytan = int(input())
pytania = [0] * i_pytan
for x in range(i_pytan):
	pytania[x] = int(input())
maks_kart = max(pytania)
karty = 2
zwiekszanie = 5
pietra = []
while karty <= maks_kart:
	pietra.append(karty)
	karty += zwiekszanie
	zwiekszanie += 3
for x in pytania:
	ind = len(pietra) - 1
	i_pir = 0
	while ind > -1:
		if x < pietra[ind]:
			ind -= 1
		else:
			x -= pietra[ind]
			i_pir += 1
	print(i_pir)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def pat(n):
	return n * (3 * n + 1) // 2

def foo():
	x = inp()
	if x == 1:
		print(0)
		return
	y = cnt = 0
	diff = x
	while True:
		n = 0
		while pat(n) <= diff:
			y = pat(n)
			n += 1
		diff = diff - y
		cnt += 1
		if diff == 0 or diff == 1:
			break
	print(cnt)
t = inp()
for i in range(t):
	foo()


from math import floor

def roots(a, b, c):
	d = (b ** 2 - 4 * a * c) ** (1 / 2)
	x1 = (-b + d) / (2 * a)
	x2 = (-b - d) / (2 * a)
	return (x1 if x1 >= x2 else x2) if x1 >= 0 <= x2 else x1 if x1 > 0 else x2 if x2 > 0 else None

def sum_ap(a, d, n):
	return int(n / 2 * (2 * a + (n - 1) * d))
t = int(input())
for _ in range(t):
	cards = int(input())
	(a, d) = (2, 3)
	c = 0
	while cards >= 2:
		n = floor(roots(3 / 2, 1 / 2, -cards))
		cards -= sum_ap(a, d, n)
		c += 1
	print(c)


from sys import stdout, stdin
(_input, _print) = (stdin.buffer.readline, stdout.write)
(_range, _int) = (range, int)

def solution():
	from bisect import bisect
	arr = [0, 2]
	current = 2
	while arr[-1] < 10 ** 9:
		arr.append(arr[current - 1] + current * 2 + current - 1)
		current += 1
	for _ in _range(_int(_input())):
		n = _int(_input())
		counter = 0
		index = bisect(arr, n)
		while index != 1:
			while n - arr[index - 1] >= 0:
				n -= arr[index - 1]
				counter += 1
			index = bisect(arr, n, 0, index)
		print(counter)
solution()


for _ in range(int(input())):
	ans = 0
	n = int(input())
	while n >= 2:
		t = 5
		c = 2
		while n >= c:
			c += t
			t += 3
		n -= c - (t - 3)
		ans += 1
	print(ans)


import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from heapq import heappush, heappop, heapify, nlargest, nsmallest

def STR():
	return list(input())

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def sortListWithIndex(listOfTuples, idx):
	return sorted(listOfTuples, key=lambda x: x[idx])

def sortDictWithVal(passedDic):
	temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))[::-1]
	toret = {}
	for tup in temp:
		toret[tup[0]] = tup[1]
	return toret

def sortDictWithKey(passedDic):
	return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
req = []
for i in range(1, 30000):
	req.append(i * (3 * i + 1) // 2)
t = INT()
while t != 0:
	n = INT()
	ans = 0
	while n > 1:
		lo = 0
		hi = 29999
		temp = 0
		while lo < hi:
			mid = (lo + hi) // 2
			if req[mid] > n:
				hi = mid
			elif req[mid] == n:
				temp = req[mid]
				lo = mid
				break
			else:
				temp = req[mid]
				lo = mid + 1
		n -= temp
		ans += 1
	print(ans)
	t -= 1


t = int(input())
for i in range(t):
	n = int(input())
	list = []
	k = n
	j = 1
	if n < 2:
		print(0)
		continue
	while k > 0:
		k = k - (j * 2 + (j - 1))
		if k >= 0:
			list.append(n - k)
		j += 1
	ans = 0
	for j in range(len(list) - 1, -1, -1):
		m = n // list[j]
		n = n - m * list[j]
		ans = ans + m
		if n >= 2:
			continue
		print(ans)
		break


import math
test = int(input())
sum = 0

def pyramid(cards):
	if cards <= 1:
		return
	global sum
	root = math.sqrt(1 + 4 * 3 * 2 * cards)
	x = (-1 + root) / 6
	height = int(x)
	used_cards = int(3 * height * (height + 1) / 2 - height)
	remain = int(cards) - used_cards
	if height > 0:
		sum += 1
	if remain > 1:
		pyramid(remain)
for t in range(test):
	cards = int(input())
	pyramid(cards)
	print(sum)
	sum = 0


import math
test = int(input())
for i in range(test):
	n = int(input())
	r = math.ceil(math.sqrt(n))
	ans = 0
	a = 2
	j = 1
	while n > 1:
		temp = j * (4 + (j - 1) * 3) // 2
		if temp > n:
			ans += 1
			n -= (j - 1) * (4 + (j - 2) * 3) // 2
			j = 1
		j += 1
	print(ans)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for i in range(t):
	n = int(inp())
	cardsT = 0
	cardsC = 0
	p = 0
	i = 0
	while n > 1:
		if i == 0:
			cardsT += 2
		else:
			cardsT += 5 + (i - 1) * 3
		i += 1
		if cardsT > n and n > 1:
			n -= cardsC
			p += 1
			i = 0
			cardsT = 0
		cardsC = cardsT
	print(p)


def calcPyramids(n):

	def cardsInPyramid(h):
		return 3 / 2 * h ** 2 + h / 2

	def calc(cards, total):
		if cards < 2:
			return total
		h = 1
		previousVal = cardsInPyramid(h)
		val = cardsInPyramid(h + 1)
		while val <= cards:
			previousVal = val
			val = cardsInPyramid(h + 1)
			h += 1
		return calc(cards - previousVal, total + 1)
	print(calc(n, 0))
n = int(input())
for i in range(n):
	calcPyramids(int(input()))


import sys
import heapq
import math
import bisect

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, input().split())

def rlinput():
	return list(map(int, input().split()))

def srlinput():
	return sorted(list(map(int, input().split())))
q = [2]
i = 2
while q[-1] < 1000000000.0:
	q.append(q[-1] + 2 * i + i - 1)
	i += 1

def main():
	n = iinput()
	res = 0
	while n >= q[0]:
		n -= q[bisect.bisect_right(q, n) - 1]
		res += 1
	print(res)
for sdfghjkl in range(iinput()):
	main()


R1 = lambda : list(map(int, input().split()))
R2 = lambda : int(input())
for i in range(R2()):
	n = R2()
	ans = 0
	while n > 1:
		count = 5
		curr = 2
		while n >= curr:
			n -= curr
			curr = count
			count += 3
		ans += 1
	print(ans)


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n > 1:
		p = 2 * n
		p = p / 3
		q = sqrt(p)
		a = floor(q)
		s = a * (3 * a + 1)
		s = s // 2
		k = n - s
		if k < 0:
			a = a - 1
			s = a * (3 * a + 1)
			s = s // 2
			n = n - s
			c = c + 1
		else:
			n = k
			c = c + 1
	print(c)


def _input():
	return map(int, input().split())

def f():
	n = int(input())
	res = 0
	while True:
		dt = 1 + 24 * n
		r = (-1 + dt ** 0.5) // 6
		if (-1 + dt ** 0.5) // 6 >= 1:
			res += 1
			n -= int(r + 3 * r ** 2) // 2
		else:
			break
	print(res)
for _ in range(int(input())):
	f()


def maxValue(n):
	array = [2]
	ans = 2
	k = 2
	while True:
		temp = array[-1] + k * 3 - 1
		if temp <= n:
			ans = temp
			k += 1
			array.append(ans)
		else:
			break
	return n - ans
for i in range(int(input())):
	n = int(input())
	ans = 0
	while n >= 2:
		n = maxValue(n)
		ans += 1
	print(ans)


import math
t = int(input())
while t:
	n = int(input())
	cnt = 0
	while True:
		x = int((math.sqrt(1 + 24 * n) - 1) / 6)
		if x == 0:
			break
		cnt += 1
		n -= (3 * x * x + x) // 2
	print(cnt)
	t -= 1


def build(n):
	i = 0
	s = 0
	while n >= (i + 1) * 3 - 1:
		i += 1
		s += i * 3 - 1
		n -= i * 3 - 1
	return (i, s)

def resolve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		time = 0
		while True:
			(i, s) = build(n)
			if i == 0:
				break
			time += 1
			n -= s
		print(time)
		time = 0
resolve()


c_list = []
c_list.append(0)
for _ in range(int(input())):
	n = int(input())
	i = len(c_list)
	s = c_list[i - 1]
	while s <= n:
		s += 3 * i - 1
		c_list.append(s)
		i += 1
	res = 0
	m = n
	c_l = len(c_list)
	c = c_l - 1
	while m >= 2:
		if c_list[c] <= m:
			m -= c_list[c]
			res += 1
			c = c_l
		c -= 1
	print(res)


import sys
import math

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def val(h):
	return 3 * (h * (h + 1) // 2) - h

def bi(n):
	l = 1
	r = n
	while l <= r:
		m = l + (r - l) // 2
		if val(m) == r:
			return val(m)
		elif val(m) > r:
			r = m - 1
		else:
			l = m + 1
	return -1
t = read_int()
for i in range(t):
	n = read_int()
	cnt = 0
	while n >= 2:
		i = int(math.sqrt(n) + 1)
		while i >= 0:
			if n - val(i) >= 0:
				cnt += 1
				n -= val(i)
				break
			else:
				i -= 1
	print(cnt)


for i in range(int(input())):
	n = int(input())
	if n >= 1 and n < 7:
		print(n // 2)
	elif n <= 8:
		print(1)
	else:
		count = 0
		a = n
		while a >= 2:
			x = a
			for i in range(1, x):
				d = x - 3 * i
				if d < 2 * (i + 1):
					a = x - 2 * i
					break
				else:
					x = d
			count += 1
		print(count)


t = int(input())
for i in range(t):
	target = int(input())
	count = 0
	if target < 2:
		print(0)
	else:
		for j in range(target):
			start = 1
			end = target
			ans = 0
			while start <= end:
				mid = (start + end) // 2
				s = mid / 2 * (4 + (mid - 1) * 3)
				if s <= target:
					ans = s
					start = mid + 1
				else:
					end = mid - 1
			target -= ans
			count += 1
			if target < 2:
				break
		print(count)


for i in range(int(input())):
	a = int(input())
	g = 0
	while a > 1:
		h = 2
		for n in range(5, 1000000000, 3):
			h += n
			if h > a:
				a -= h - n
				g += 1
				break
	print(g)


import math
from bisect import bisect_right
arr = [2]
t = 4
v = 1
while arr[-1] <= 10 ** 9:
	arr.append(arr[-1] + t + v)
	t += 2
	v += 1
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n >= 2:
		v = bisect_right(arr, n, 0, len(arr))
		n -= arr[v - 1]
		ans += 1
	print(ans)


import math
t = int(input())
import math
delay = []
for _ in range(t):
	n = int(input())
	k = 0
	while n > 0:
		x = math.floor(((24 * n + 1) ** 0.5 - 1) / 6)
		if x <= 0:
			break
		n -= x * (3 * x + 1) / 2
		k += 1
	print(k)


from sys import stdin
tc = int(stdin.readline())
for _ in range(tc):
	n = int(stdin.readline())
	cnt = 0
	while n >= 2:
		py = 0
		h = 0
		while py < n:
			h += 1
			py += h * 2 + (h - 1)
			if py == n:
				n -= py
				cnt += 1
				break
			if py > n:
				py -= h * 2 + (h - 1)
				n -= py
				cnt += 1
				break
	print(cnt)


from sys import stdin
closest = -1

def bs(arr, l, r, x):
	if l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			return bs(arr, mid + 1, r, x)
		else:
			return bs(arr, l, mid - 1, x)
	return l
input = stdin.readline

def list_input():
	return list(map(int, input().split()))

def sep_input():
	return map(int, input().split())
l = [2]
for i in range(1, 26000):
	l.append(l[-1] + 3 * i + 2)
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while True:
		if n <= 1:
			break
		else:
			ans += 1
			temp = bs(l, 0, len(l) - 1, n)
			if l[temp] == n:
				n = n - l[temp]
			elif l[temp] < n:
				f = l[temp]
				for i in range(temp, len(l)):
					if l[i] > n:
						break
					else:
						f = l[i]
				n = n - f
			else:
				f = l[temp]
				for i in range(temp, -1, -1):
					if l[i] < n:
						f = l[i]
						break
				n = n - f
	print(ans)


x = 2
i = 5
d = []
while x < 10 ** 10:
	d.append(x)
	x = x + i
	i = i + 3

def search(d, n):
	for i in range(len(d)):
		if d[i] > n:
			return d[i - 1]
for u in range(int(input())):
	n = int(input())
	c = 0
	while n >= 2:
		c = c + 1
		n = n - search(d, n)
	print(c)


import math
import sys

def HFromC(c):
	return math.floor((-0.5 + math.sqrt(0.25 + 6 * c)) / 3)

def CFromH(h):
	return int(1.5 * h * h + 0.5 * h)
t = int(input())
for _ in range(t):
	c = int(input())
	h = 0
	it = 0
	while c >= 2:
		c -= CFromH(HFromC(c))
		it += 1
	print(it)


for _ in range(int(input())):
	n = int(input())
	if n > 1:
		h = 1
		cnt = 0
		while n > 1:
			h = 1
			while True:
				if n >= h * 2 + (h - 1):
					n = n - (h - 1)
					n = n - h * 2
					h = h + 1
				else:
					cnt += 1
					break
		print(cnt)
	else:
		print(0)


from sys import stdin, stdout
from bisect import bisect_right
readline = stdin.readline
write = stdout.write
t = int(readline())
p = [2]
for i in range(t):
	n = int(readline())
	last = len(p)
	while p[-1] < n:
		p.append(p[-1] + last + (last + 1) * p[0])
		last += 1
	remain = n
	count = 0
	while remain > 1:
		i = bisect_right(p, int(remain))
		if i:
			count += 1
			remain -= p[i - 1]
	write(str(count) + '\n')


import bisect
t = int(input())
nim = 0
arr = []
i = 1
while nim <= 10 ** 9:
	currnim = 3 * nim + 2 * i
	arr.append(currnim)
	nim += i
	i += 1
for _ in range(t):
	ans = 0
	x = int(input())
	while True:
		k = bisect.bisect_right(arr, x)
		if k == 0:
			break
		else:
			k -= 1
			ans += 1
			x -= arr[k]
	print(ans)


possible = [2]
i = 1
j = 2
while possible[-1] <= 10 ** 9:
	i += j
	possible.append(i * 3 - j)
	j += 1
for _ in range(int(input())):
	ans = 0
	x = int(input())
	while x >= 2:
		pointer = 0
		while pointer < len(possible) - 1:
			if x >= possible[pointer + 1]:
				pointer += 1
			else:
				break
		ans += 1
		x -= possible[pointer]
	print(ans)


import math

def solve():
	x = int(input())
	ans = 0
	while x > 0:
		n = math.floor((-1 + math.sqrt(24 * x + 1)) / 6)
		if n <= 0:
			break
		sub = 3 * n * (n + 1) / 2 - n
		if sub <= x:
			x -= sub
		else:
			break
		ans += 1
	print(ans)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
lst = list()
for y in range(t):
	sum = 0
	n = int(input())
	while n > 1:
		s = 2
		while n >= s:
			n -= s
			s += 3
		sum += 1
	lst.append(sum)
for i in lst:
	print(int(i))


i = 0
x = 2
y = x
s = []
while y < 10 ** 9 + 1000000:
	s.append(y)
	i += 1
	y += x * (i + 1) + i
f = len(s)
for _ in range(int(input())):
	n = int(input())
	p = 0
	while n > 1:
		l = 0
		r = f - 1
		while l != r:
			m = (r + l) // 2
			if n > s[m]:
				l = m + 1
			else:
				r = m
		if s[r] == n:
			n = n - s[r]
		else:
			n = n - s[r - 1]
		p += 1
	print(p)


t = int(input())
for _ in range(t):
	n = int(input())
	i = int(n ** 0.5) + 2
	k = 0
	while i > 0 and n > 1:
		while n > 1:
			if n >= 3 * i * (i - 1) // 2 + 2 * i:
				k += 1
				n -= 3 * i * (i - 1) // 2 + 2 * i
			else:
				break
		i -= 1
	print(k)


hashmap = [2]
counter = 5
for i in range(0, 10 ** 5):
	hashmap.append(hashmap[-1] + counter)
	counter += 3
for _ in range(0, int(input())):
	n = int(input())
	i = 0
	res = 0
	while True:
		if n < 2:
			print(res)
			break
		if hashmap[i] == n:
			res += 1
			print(res)
			break
		if hashmap[i] > n:
			res += 1
			n -= hashmap[i - 1]
			i = 0
		else:
			i += 1


from bisect import bisect_right
test = int(input())
d = []
i = 1
c = 0
a = 0
while c <= 1000000000:
	c += 2 * i + i - 1
	a += c
	i += 1
	d.append(c)
for i in range(test):
	t = 0
	n = int(input())
	while n > 0:
		n -= d[bisect_right(d, n) - 1]
		t += 1
	if n < 0:
		t -= 1
	print(t)


import math

def solver(x):
	n = (-1 + math.sqrt(1 + 24 * x)) / 6
	return math.floor(n)
t = int(input())
for test in range(t):
	n = int(input())
	count = 0
	while n >= 2:
		x = solver(n)
		n -= x * (3 * x + 1) // 2
		count += 1
	print(count)


l = [2, 7, 15, 26]
from bisect import bisect_left
while l[-1] <= 10 ** 9:
	l.append(l[-1] + (l[-1] - l[-2] + 3))
for _ in range(int(input())):
	n = int(input())
	count = 0
	while n >= 2:
		i = bisect_left(l, n)
		if l[i] == n:
			n -= l[i]
		else:
			n -= l[i - 1]
		count += 1
	print(count)


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
have = [0, 2]
for i in range(50000):
	have.append(have[-1] * 2 - have[-2] + 3)
for _ in range(int(input())):
	n = int(input())
	cnt = 0
	(l, r) = (0, 50000 - 1)
	while l + 1 < r:
		m = l + (r - l) // 2
		if have[m] <= n:
			l = m
		else:
			r = m
	if have[r] <= n:
		x = r
	else:
		x = l
	for i in range(x, 0, -1):
		bf = n // have[i]
		cnt += bf
		n -= bf * have[i]
	print(str(cnt) + '\n')


def check(x, n):
	used = 2 * x
	used += 3 * x * (x - 1) // 2
	if used <= n:
		return True
	return False

def find(n):
	low = 0
	high = n
	h = 0
	while low <= high:
		mid = (low + high) // 2
		if check(mid, n):
			h = mid
			low = mid + 1
		else:
			high = mid - 1
	used = 2 * h
	used += 3 * h * (h - 1) // 2
	return used

def solve(n, ans):
	total = 0
	while n > 0:
		used = find(n)
		if used > 0:
			total += 1
			n -= used
		else:
			break
	ans.append(total)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		solve(n, ans)
	for i in ans:
		print(i)
main()


import math, sys
for _ in range(int(sys.stdin.readline())):
	n = int(sys.stdin.readline())
	ans = 0
	while n > 1:
		h = int((math.sqrt(1 + 24 * n) - 1) // 6)
		n -= h * (h + 1) + (h - 1) * h // 2
		ans += 1
	sys.stdout.write(str(ans) + '\n')


t = int(input())
lst = list()
while t > 0:
	n = int(input())
	lst.append(n)
	t = t - 1
for i in lst:
	nc = [2]
	cards = 2
	add = 5
	c = 0
	count = 0
	while i > 1:
		if cards < i:
			cards = cards + add
			add = add + 3
			nc.append(cards)
			c = c + 1
		if cards > i:
			s = nc[c - 1]
			i = i - s
			nc = [2]
			cards = 2
			add = 5
			c = 0
			count = count + 1
		if cards == i:
			i = i - cards
			count = count + 1
	print(count)


import sys

def cards(n):
	return (3 * n ** 2 + n) // 2
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	count = 0
	while n >= 2:
		m = int(n ** 0.5)
		while cards(m) > n:
			m -= 1
		n -= cards(m)
		count += 1
	print(count)


import math

def ret_max_h(n):
	i = 1
	while int(i * (3 * i + 1) / 2) <= n:
		i += 1
	i -= 1
	return int(i * (3 * i + 1) / 2)

def solve():
	n = int(input())
	count = 0
	if n < 2:
		print(0)
		return 0
	while n >= 2:
		count += 1
		n_needed = ret_max_h(n)
		n = n - n_needed
	print(count)
	return 0
t = int(input())
for _ in range(t):
	solve()


for test in range(int(input())):
	n = int(input())
	a = 2
	if n == 1:
		print('0')
	else:
		result = 0
		while True:
			count = 1
			while a <= n:
				count += 1
				a += count * 2 + count - 1
			a -= count * 2 + count - 1
			result += 1
			n -= a
			a = 2
			if n <= 1:
				break
		print(result)


from math import sqrt
for t in range(int(input())):
	k = int(input())
	shag = 0
	while k >= 2:
		n = int((1 / 2 + sqrt(1 / 4 + 6 * k)) / 3)
		while 3 * (n * (n + 1) // 2) - n > k:
			n -= 1
		k -= 3 * (n * (n + 1) // 2) - n
		shag += 1
	print(shag)


def formula(n):
	return n * (3 * n + 1) / 2
for i in range(int(input())):
	n = int(input())
	res = 0
	while n >= 2:
		s = 0
		while formula(s + 100) <= n:
			s += 100
		while formula(s + 1) <= n:
			s += 1
		res += 1
		n -= formula(s)
	print(res)


def solve(n):
	pyramids = 0
	while n > 1:
		n = build(n)
		pyramids += 1
	return pyramids

def build(n):
	init = 2
	h = 1
	while n >= init * h + h - 1:
		row = init * h + h - 1
		n -= row
		h += 1
	return n

def main():
	t = int(input())
	for i in range(t):
		d = int(input())
		ans = solve(d)
		print(ans)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	if n < 2:
		print(0)
		continue
	p = [0, 2]
	h = 2
	while p[-1] <= n:
		m = p[h - 1] + h * 2 + h - 1
		p.append(m)
		h += 1
	c = 1
	n -= p[-2]
	while n > 1:
		for i in range(len(p)):
			if n < p[i]:
				n -= p[i - 1]
				break
		c += 1
	print(c)


from bisect import bisect_left, bisect_right
fr = [0]
i = 1
l = 1
val = 1
while fr[i - 1] <= 10 ** 9:
	val = i * 3
	fr.append(fr[l - 1] + val)
	l += 1
	i += 1
for _ in range(int(input())):
	n = int(input())
	count = 0
	if n == 2:
		print('1')
	else:
		while n > 2:
			ind = bisect_right(fr, n) - 1
			if fr[ind] == n:
				n -= fr[ind]
				n += ind
				count += 1
			else:
				rem = n - fr[ind]
				if rem >= (ind + 1) * 2:
					n -= fr[ind] + (ind + 1) * 2
				else:
					n -= fr[ind]
					n += ind
				count += 1
			if n == 2:
				count += 1
		print(count)


def generatepyramids():
	start = 2
	total = 2
	pyramids = [0, 2]
	for i in range(40000):
		start += 3
		total += start
		pyramids.append(total)
	return pyramids

def largestpyramid(n, pyramids):
	lo = 0
	hi = len(pyramids)
	mid = (lo + hi) // 2
	while lo != hi:
		mid = (lo + hi) // 2
		cur_pyramid = pyramids[mid]
		if cur_pyramid <= n:
			lo = mid + 1
		else:
			hi = mid
	if cur_pyramid <= n:
		return pyramids[mid]
	else:
		return pyramids[mid - 1]
pyramids = generatepyramids()
t = int(input())
for case in range(t):
	n = int(input())
	answer = 0
	while n > 1:
		cur = largestpyramid(n, pyramids)
		n -= cur
		answer += 1
	print(answer)


def main():
	from sys import stdin, stdout
	for _ in range(int(stdin.readline())):
		n = int(stdin.readline())
		ans = 0
		while n > 1:
			(h1, hr) = (1, n)
			while h1 + 1 < hr:
				hm = (h1 + hr) // 2
				if hm * (hm * 3 + 1) // 2 > n:
					hr = hm
				else:
					h1 = hm
			n -= h1 * (h1 * 3 + 1) // 2
			ans += 1
		print(ans)
main()


from sys import stdin

def cards(h):
	return h * (3 * h + 1) // 2

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		ans = 0
		n = int(inp())
		for i in range(30001, 0, -1):
			k = cards(i)
			if k == n:
				ans += 1
				break
			if k < n:
				ans += n // k
				n %= k
		print(ans)
main()


s = lambda n: 3 * (1 + n) * n // 2 - n

def bin_s(x):
	l = 0
	r = 100000
	while True:
		m = (l + r) // 2
		if m == l:
			break
		if x < s(m):
			r = m
		else:
			l = m
	return l
n = int(input())
for i in range(n):
	x = int(input())
	ans = 0
	while x > 1:
		ans += 1
		x -= s(bin_s(x))
	print(ans)


t = int(input())
for _ in range(t):
	c = int(input())
	cnt = 0
	while c != 0:
		n = ((24 * c + 1) ** 0.5 - 1) // 6
		if n == 0:
			break
		else:
			cnt += 1
		c -= n * (3 * n + 1) // 2
	print(cnt)


from bisect import bisect_right

def find_le(a, x):
	i = bisect_right(a, x)
	if i:
		return a[i - 1]
	raise ValueError
arr = [n * (n + 1) + n * (n - 1) // 2 for n in range(1, 10 ** 5)]
t = int(input())
for tc in range(t):
	n = int(input())
	cnt = 0
	while n >= 2:
		x = find_le(arr, n)
		cnt += 1
		n -= x
	print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n >= 2:
		p = ((24 * n + 1) ** 0.5 - 1) // 6
		u = (3 * p * p + p) / 2
		c += 1
		n -= u
	print(c)


for i in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		l = 0
		r = 1000000
		while r - l != 1:
			s = (l + r) // 2
			if s * (3 * s + 1) // 2 > n:
				r = s
			else:
				l = s
		c += 1
		n -= l * (3 * l + 1) // 2
	print(c)


t = int(input())
for i in range(0, t):
	n = int(input())
	h = -1 + pow(1 + 24 * n, 0.5)
	h = h // 6
	if h == 0:
		print(0)
	else:
		count = 0
		while n != 0 and n != 1:
			count += 1
			x = h * (3 * h + 1) // 2
			n = n - x
			h = -1 + pow(1 + 24 * n, 0.5)
			h = h // 6
		print(count)


t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	while n > 1:
		flag = True
		h = 0
		s = 0
		while flag:
			h += 1
			if s + 3 * h - 1 > n:
				flag = False
			else:
				s += 3 * h - 1
		n -= s
		c += 1
	print(c)


def f(o):
	return o * (o - 1) // 2 + o * (o + 1)
for i in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		(l, r) = (0, 10 ** 6)
		while r != l + 1:
			m = (l + r) // 2
			if f(m) <= n:
				l = m
			else:
				r = m
		ans += 1
		n -= f(l)
	print(ans)


import math

def cards(n):
	return n * (3 * n + 1) / 2

def reverseCard(k):
	return (-1 + math.sqrt(1 + 24 * k)) / 6
num = int(input())
for i in range(num):
	n = int(input())
	count = 0
	while n >= 2:
		n -= cards(math.floor(reverseCard(n)))
		count += 1
	print(count)


t = int(input())
for i in range(t):
	x = 1
	n = int(input())
	previ = 0
	count = 0
	while n > 0:
		if n == 1:
			break
		value = x * (x + 1) + (x - 1) * x / 2
		if value < n:
			previ = value
			x = x + 1
		elif value > n:
			count = count + 1
			n = n - previ
			x = 1
		else:
			count = count + 1
			n = n - value
			break
	print(count)


for _ in range(int(input())):
	n = int(input())
	(prev, i, ans) = (0, 0, 0)
	while prev + i + 2 * (i + 1) <= n:
		while prev + i + 2 * (i + 1) <= n:
			prev = prev + i + 2 * (i + 1)
			i += 1
		ans += 1
		n = n - prev
		(prev, i) = (0, 0)
	print(ans)


from math import *
t = int(input())
for i in range(t):
	n = int(input())
	cnt = 0
	while True:
		if floor((sqrt(24 * n + 1) - 1) / 6) > 0:
			cnt += 1
			x = floor((sqrt(24 * n + 1) - 1) // 6)
			n -= x * (3 * x + 1) // 2
		else:
			break
	print(cnt)


import bisect
mx = -10 ** 9
t = int(input())
p = []
for i in range(t):
	n = int(input())
	c = 0
	p.append(n)
mx = max(p)
l = [2, 7, 15]
while True:
	x = l[-1] - l[-2] + 3
	pp = x + l[-1]
	if pp > mx:
		break
	l.append(pp)
for i in range(t):
	n = p[i]
	c = 0
	while n > 1:
		j = bisect.bisect_left(l, n)
		if j < len(l):
			if l[j] == n:
				n -= n
				c += 1
				continue
		if j > 0:
			n -= l[j - 1]
			c += 1
	print(c)


def card(c):
	if c < 2:
		return 0
	else:
		n = 2
		while True:
			if c <= (3 * n - 2) * (n - 1) // 2:
				break
			else:
				n += 1
		if c < (3 * n - 2) * (n - 1) // 2:
			c -= (3 * (n - 1) - 2) * (n - 2) // 2
			return 1 + card(c)
		elif c == (3 * n - 2) * (n - 1) // 2:
			c -= (3 * n - 2) * (n - 1) // 2
			return 1 + card(c)
t = int(input())
l = []
for i in range(t):
	n = int(input())
	l.append(n)
for j in l:
	print(card(j))


import bisect
a = [0]
for i in range(1, 100000):
	x = 2 * i + i * (i - 1) // 2 * 3
	a.append(x)
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n > 0:
		j = bisect.bisect_left(a, n)
		if n == 1:
			break
		elif a[j] == n:
			c += 1
			break
		n -= a[j - 1]
		if n == 0:
			c += 1
			break
		elif n < 0:
			break
		c += 1
	print(c)


t = int(input())
for tt in range(t):
	n = int(input())
	q = 0
	while n > 1:
		if round((24 * n + 1) ** 0.5) ** 2 == 24 * n + 1:
			if round(-1 + (24 * n + 1) ** 0.5) % 6 == 0:
				nn = round((-1 + (24 * n + 1) ** 0.5) / 6)
				ncm = round(nn * (3 * nn + 1) / 2)
				n -= ncm
				q += 1
			else:
				nn = int((-1 + (24 * n + 1) ** 0.5) / 6)
				ncm = round(nn * (3 * nn + 1) / 2)
				n -= ncm
				q += 1
		else:
			nn = int((-1 + (24 * n + 1) ** 0.5) / 6)
			ncm = round(nn * (3 * nn + 1) / 2)
			n -= ncm
			q += 1
	print(q)


import bisect
t = int(input())
l = []
total = 2
i = 2
while total < 1000000000:
	l.append(total)
	total += 3 * i - 1
	i += 1

def do_pyramid(n):
	return n - l[bisect.bisect(l, n) - 1]
for _ in range(t):
	n = int(input())
	ans = 0
	while n >= 2:
		ans += 1
		n = do_pyramid(n)
	print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict as dd, deque as dq
import bisect
l = [0, 5]
c = [2]
while c[-1] <= 2000000000:
	c.append(c[-1] + l[-1])
	l.append(3 + l[-1])
t = int(input())
while t:
	n = int(input())
	cou = 0
	while n > 1:
		cou += 1
		ind = bisect.bisect_left(c, n)
		if c[ind] > n:
			ind -= 1
		n -= c[ind]
	print(cou)
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	f = 0
	while n > 1:
		k = 2
		tmp = 2
		g = 1
		while n >= tmp:
			k = tmp
			tmp += g + (g + 1) * 2
			g += 1
		f += 1
		n -= k
	print(f)


from math import sqrt, ceil

def solve(n):
	ans = 0
	cards = n
	while cards >= 2:
		MAX = ceil(sqrt(cards))
		cards -= binary_search(1, MAX, cards)
		ans += 1
	return ans

def binary_search(l, r, n):
	while r - l > 1:
		mid = (l + r) // 2
		value = mid * (3 * mid + 1) // 2
		if value < n:
			l = mid
		elif value > n:
			r = mid
		else:
			return value
	return l * (3 * l + 1) // 2
t = int(input())
for i in range(t):
	n = int(input())
	print(solve(n))


l = int(input())

def f(n):
	return (3 * n * n + n) * 0.5

def t(n):
	c = 0
	i = 1
	while n > 1:
		while n >= f(i):
			i += 1
		i -= 1
		n -= f(i)
		c = c + 1
		i = 1
	return c
for i in range(l):
	n = int(input())
	print(t(n))


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	i = 2
	ans = 1
	while ans <= n:
		ans = (3 * i - 2) * (i - 1)
		ans = ans / 2
		a.append(ans)
		i += 1
	a.sort(reverse=True)
	(tot, count) = (0, 0)
	if a[0] > n:
		a.remove(a[0])
	i = 0
	while i < len(a) and tot <= n:
		if tot + a[i] > n:
			i += 1
			continue
		else:
			tot = tot + a[i]
			count += 1
	print(count)


m = 25820
l = list()
l.append(2)

def fs():
	global l, m
	for i in range(1, m):
		l.append(l[i - 1] + 3 * i + 2)
	return

def f(key):
	global l, m
	i = 0
	j = m
	while i <= j:
		mid = (i + j) // 2
		if l[mid] <= key and (mid + 1 >= m or l[mid + 1] > key):
			return mid
		elif l[mid] > key:
			j = mid - 1
		elif l[mid] < key:
			i = mid + 1
	return -1
fs()
n = int(input())
for _ in range(n):
	n = int(input())
	c = 0
	while n > 0:
		ans = f(n)
		if ans == -1:
			break
		n -= l[ans]
		c += 1
	print(c)


t = int(input())
a = [0] * t
for i in range(t):
	n = int(input())
	while n > 1:
		k = 0
		while (k + 1) * 2 + k <= n:
			n -= (k + 1) * 2 + k
			k += 1
		a[i] += 1
for x in a:
	print(x)


def py(n, count):
	if n <= 1:
		print(int(count))
		return
	i = 1
	while True:
		if i * (3 * i + 1) / 2 >= n:
			break
		i += 1
	if i * (3 * i + 1) / 2 > n:
		i -= 1
	count += n // (i * (3 * i + 1) / 2)
	n %= i * (3 * i + 1) / 2
	py(n, count)
	return
for _ in range(int(input())):
	n = int(input())
	py(n, 0)


l = [-1] * 10 ** 6
import math

def S(s):
	f = 1
	k = 1
	while f:
		if l[k] == -1:
			l[k] = (3 * k ** 2 + k) // 2
		if s - l[k] == 0:
			break
		elif s - l[k] < 0:
			k -= 1
			break
		k += 1
	return l[k]
for _ in range(int(input())):
	x = int(input())
	c = 0
	while x > 1:
		c += 1
		x -= S(x)
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	k = 0
	h = 2
	g = n
	j = 2
	e = 1
	while True:
		if n <= 1:
			break
		if n - h < 0:
			n = n - j
			k += 1
			h = 2
			j = 2
			e = 1
		else:
			e += 1
			j = h
			h = h + ((e - 1) * 3 + 2)
	print(k)


t = int(input())
while t:
	n = int(input())
	s = 0
	h = 1
	c = 0
	while n > 1:
		s = 0
		h = 1
		while s <= n:
			prev = s
			s += h * 2 + h - 1
			h += 1
		h -= 1
		s = prev
		n = n - s
		c += 1
	print(c)
	t -= 1


t = int(input())

def noc(i):
	return 3 * (i * (i + 1) // 2) - i

def bs(n):
	(lo, hi) = (1, 10 ** 5)
	ans = -1
	while hi >= lo:
		mid = (lo + hi) // 2
		if noc(mid) <= n:
			ans = max(ans, mid)
			lo = mid + 1
		else:
			hi = mid - 1
	return ans
for T in range(t):
	n = int(input())
	if n == 1:
		print(0)
		continue
	ans = 0
	while n > 1:
		n -= noc(bs(n))
		ans += 1
	print(ans)


def calc(n):
	lastA = 0
	lastV = 0
	for a in range(1, n + 1):
		v = int(a * (3 * a + 1) / 2)
		if v > n:
			break
		lastV = v
	return lastV
for t in range(int(input())):
	n = int(input())
	a = 0
	while n > 1:
		a += 1
		n -= calc(n)
	print(a)


import bisect
maxn = 1000000001
n = 2
ar = []
ar.append(n)
i = 2
while n < maxn:
	n = i * (3 * i + 1) // 2
	ar.append(n)
	i += 1
t = int(input())
while t > 0:
	cnt = 0
	n = int(input())
	while True:
		pos = bisect.bisect(ar, n)
		if pos == 0:
			break
		elif n >= ar[pos - 1]:
			n = n - ar[pos - 1]
			cnt += 1
		else:
			break
	print(cnt)
	t -= 1


from bisect import bisect
l = [2]
c = 2
i = 0
j = 2
while c <= 10 ** 9:
	i += 1
	j += 2
	c = c + i + j
	l.append(c)
for _ in range(int(input())):
	c = 0
	n = int(input())
	while n >= 2:
		a = bisect(l, n) - 1
		n = n - l[a]
		c += 1
	print(c)


T = int(input())
for _ in range(T):
	X = int(input())
	ans = 0
	while X > 0:
		N = 0
		while (N ** 2 + N) // 2 * 3 - N <= X:
			N += 1
		N -= 1
		if N > 0:
			X -= (N ** 2 + N) // 2 * 3 - N
			ans += 1
		else:
			break
	print(ans)


n = int(input())
for i in range(n):
	d = int(input())
	c = 0
	while d >= 2:
		k = 2
		c += 1
		while d >= k:
			d = d - k
			k = k + 3
	print(c)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys
from bisect import bisect_right

def main():
	F = [0, 2]
	prev = 2
	num = 1
	while prev < 10 ** 9 + 1:
		prev += num * 3 + 2
		F.append(prev)
		num += 1

	def solve(n):
		ret = 0
		while n >= 2:
			idx = bisect_right(F, n)
			n -= F[idx - 1]
			ret += 1
		return ret
	t = int(input())
	for _ in range(t):
		n = int(input())
		ans = solve(n)
		sys.stdout.write(str(ans) + '\n')
main()


temp = 0
l = []
i = 1
while True:
	temp += 3 * i - 1
	if temp >= 1000000000:
		break
	l.append(temp)
	i += 1
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 0:
		ind = -1
		for i in range(len(l)):
			if l[i] <= n:
				ind = i
			else:
				break
		if ind == -1:
			break
		ans += n // l[ind]
		n = n % l[ind]
	print(ans)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *
f = [0, 2]
while f[-1] <= 10 ** 9:
	i = len(f)
	f.append(f[i - 1] + (i - 1) + 2 * i)

def findmaxheight(n):
	global f
	l = 0
	r = len(f) - 1
	ret = 0
	while l <= r:
		mid = (l + r) // 2
		if f[mid] <= n:
			ret = max(ret, mid)
			l = mid + 1
		else:
			r = mid - 1
	return f[ret]

def main():
	ntest = int(stdin.readline())
	for testcase in range(ntest):
		n = int(stdin.readline())
		res = 0
		while n > 1:
			n -= findmaxheight(n)
			res += 1
		stdout.write('%d\n' % res)
	return 0
main()


t = int(input())
z = {}
i = 2
add = 2
while i <= 1000000000:
	z[i] = True
	add = add + 3
	i = i + add
for _ in range(0, t):
	n = int(input())
	total = 0
	if n < 2:
		print(0)
	elif n in z:
		print(1)
	else:
		while n >= 2:
			o = 0
			while n >= 2 and n not in z:
				n = n - 1
				o = o + 1
			n = o
			total = total + 1
		print(total)


import bisect

def pyr(n):
	return n * (n + 1) // 2 * 3 - n
pyrlist = []
pyrlist.append(pyr(1))
t = int(input())
for k in range(t):
	cards = int(input())
	while pyrlist[-1] < cards:
		pyrlist.append(pyr(len(pyrlist)))
	count = 0
	while cards > 1:
		guess = pyrlist[bisect.bisect_left(pyrlist, cards)]
		if guess == cards:
			cards = 0
			count += 1
		else:
			guess = pyrlist[bisect.bisect_left(pyrlist, cards) - 1]
			count += 1
		cards += -guess
	print(count)


pre = 2
count = 1
arr = [2]
while arr[-1] < 10 ** 9:
	pre = pre + 3
	arr.append(arr[count - 1] + pre)
	count += 1

def binary_search(arr, n):
	(l, r) = (0, len(arr) - 1)
	ans = -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] <= n:
			ans = max(ans, arr[mid])
			l = mid + 1
		else:
			r = mid - 1
	return ans
numcases = int(input())
for i in range(numcases):
	n = int(input())
	count = 0
	while True:
		p1 = binary_search(arr, n)
		if p1 < 0:
			break
		n = n - p1
		count += 1
	print(count)


import bisect

def f(x):
	return x * (x + 1) // 2 * 2 + x * (x - 1) // 2
arr = []
i = 1
while True:
	n = f(i)
	if n > 1000000000.0:
		break
	arr.append(n)
	i += 1
for _ in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
		continue
	t = 0
	while True:
		if n < 2:
			break
		i = bisect.bisect_left(arr, n)
		if i < len(arr) and arr[i] == n:
			t += 1
			break
		else:
			n -= arr[i - 1]
			t += 1
	print(t)


t = int(input())
for i in range(t):
	n = int(input())
	ctr = 0
	while n >= 2:
		h = int(n ** (1 / 3))
		while h / 2 + 3 / 2 * h ** 2 <= n:
			h += 1
		h -= 1
		n -= int(h / 2 + 3 / 2 * h ** 2)
		ctr += 1
	print(ctr)


from math import sqrt
for i in range(int(input())):
	n = int(input())
	count = 0
	while n > 1:
		d = int((sqrt(1 + 24 * n) - 1) // 6)
		x = 2 * d + 3 * d * (d - 1) // 2
		n -= x
		count += 1
	print(count)


def solve():
	n = int(input())
	cnt = 0
	while n > 1:
		l = 1
		r = n
		while l < r:
			m = l + (r - l) // 2
			v = m * (m + 1) + m * (m - 1) // 2
			if v <= n:
				l = m + 1
			else:
				r = m
		l -= 1
		n -= l * (l + 1) + l * (l - 1) // 2
		cnt += 1
	print(cnt)
t = int(input())
for _ in range(t):
	solve()


ls = []
for i in range(1, 10 ** 5):
	temp = (3 * i * i + i) // 2
	if temp <= 10 ** 9:
		ls.append(temp)
	else:
		break
t = int(input())
while t:
	n = int(input())
	ans = 0
	i = len(ls) - 1
	while i >= 0:
		if n - ls[i] >= 0:
			ans += n // ls[i]
			n %= ls[i]
		i -= 1
	print(ans)
	t -= 1


def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def largest(n):
	partial = 2
	height = 1
	next_partial = 7
	while next_partial <= n:
		partial = next_partial
		height += 1
		next_partial = partial + 2 * (height + 1) + height
	return partial

def solve():
	n = ri()
	total = 0
	while n >= 2:
		n -= largest(n)
		total += 1
	print(total)
t = ri()
for i in range(t):
	solve()


import bisect
n = int(input())
x = 2
i = 0
a = []
while x < 1000000000 // 2:
	a.append(x)
	x = x + 3 * (i + 1) + 2
	i += 1
for i in range(n):
	m = int(input())
	count = 0
	while True:
		ret = bisect.bisect_right(a, m)
		if ret == 0:
			break
		count += 1
		m -= a[ret - 1]
	print(count)


def neededCards(h):
	return 2 * (h * (h + 1) // 2) + h * (h - 1) // 2

def answer(cards):
	if cards == 1:
		return 0
	_max = 1
	stack = 0
	for i in range(1, cards):
		stack += 3 * (i - 1) + 2
		if cards < stack:
			_max = i - 1
			break
	count = 0
	for h in range(_max, 0, -1):
		_c = neededCards(h)
		if cards > 1 and cards % _c == 0:
			return count + cards // _c
		if cards >= _c:
			count += 1
			cards -= _c
	if cards > 2:
		count += cards // 2
	return count
n = int(input())
for _ in range(n):
	cards = int(input())
	print(answer(cards))


for _ in range(int(input())):
	n = int(input())
	count = 0
	while n > 1:
		count += 1
		cards = 0
		h = 1
		while True:
			temp = (3 * h * h + h) // 2
			if temp > n:
				break
			cards = temp
			h += 1
		n -= cards
	print(count)


prec = []

def get_ans(n):
	ans = 0
	while n >= 2:
		i = 1
		while n >= prec[i]:
			i += 1
		n -= prec[i - 1]
		ans += 1
	return ans
prec = [0, 2]
val = 2
inc = 5
while val <= 1000000009:
	val += inc
	prec.append(val)
	inc += 3
(li, hi) = (1, len(prec) - 1)
tc = int(input().strip())
for t in range(tc):
	n = int(input().strip())
	print(get_ans(n))


t = int(input())
H = []
for k in range(1, 26002):
	H.append(k * (3 * k + 1) / 2)

def noOFpyramid(num):
	c = 0
	if num > 1:
		j = 0
		while j < 26002:
			if num < H[j]:
				num = num - H[j - 1]
				c += 1
				return c + noOFpyramid(num)
			j += 1
	else:
		return 0
for i in range(t):
	n = int(input())
	x = noOFpyramid(n)
	print(x)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		n = N()
		res = 0
		ct = 2

		def c(num):
			if num == 2:
				return 1
			(l, r) = (1, 1000000)
			while l < r:
				m = (l + r + 1) // 2
				c = (3 * m ** 2 + m) // 2
				if c <= num:
					l = m
				else:
					r = m - 1
			return l
		while n >= 2:
			now = c(n)
			res += 1
			n -= (3 * now ** 2 + now) // 2
		print(res)
main()


import math
t = int(input())
for _ in range(t):
	x = int(input())
	flag = 1
	if x < 2:
		print('0')
		flag = 0
	else:
		a = 3
		b = 1
		ans = 0
		while x >= 2:
			c = -(2 * x)
			d = b ** 2 - 4 * a * c
			s1 = int((-b - math.sqrt(d)) / (2 * a))
			s2 = int((-b + math.sqrt(d)) / (2 * a))
			if s1 > 0:
				ans += 1
				mi = int(s1 * (3 * s1 + 1) / 2)
				x -= mi
			else:
				ans += 1
				mi = int(s2 * (3 * s2 + 1) / 2)
				x -= mi
	if flag == 1:
		print(ans)


import bisect
pre = []
dup = 0
i = 1
while dup < 1000000001:
	temp = i * (3 * i + 1) // 2
	pre.append(temp)
	dup = temp
	i += 1
t = int(input())
for _ in range(t):
	n = int(input())
	cnt = 0
	while True:
		if n < 2:
			break
		x = bisect.bisect_left(pre, n, 0, len(pre))
		if pre[x] == n:
			cnt += 1
			break
		else:
			x = x - 1
			n = n - pre[x]
			cnt += 1
	print(cnt)


def height(n):
	t = 0
	while n > 1:
		data = []
		for i in range(1, n + 1):
			if i * (3 * i + 1) / 2 > n:
				break
			else:
				data.append(i * (3 * i + 1) / 2)
		n = n - int(max(data))
		t = t + 1
	print(t)
t = int(input())
for i in range(t):
	n = int(input())
	if n > 1:
		height(n)
	else:
		print(0)


n = int(input())
a = [0] * 100000
for i in range(1, 100000):
	a[i] = int(i * i * 1.5 + 0.5 * i)
for i in range(n):
	m = int(input())
	c = 0
	while m >= 2:
		i = 0
		while a[i] <= m:
			i = i + 1
		m = m - a[i - 1]
		c = c + 1
	print(c)


def pyramidMaker(h):
	return round(2 + 5 * (h - 1) + 3 * (h - 2) * (h - 1) / 2)
t = int(input())
for _ in range(t):
	n = int(input())
	count = 0
	while True:
		if n <= 1:
			break
		for i in range(n):
			if pyramidMaker(i + 1) > n:
				n -= pyramidMaker(i)
				count += 1
				break
	print(count)


def buscaBinaria(vetor, n, valor):
	l = 0
	r = n - 1
	ans = -1
	while l <= r:
		meio = l + (r - l) // 2
		if vetor[meio] <= valor:
			ans = meio
			l = meio + 1
		else:
			r = meio - 1
	return vetor[ans]
t = int(input())
for q in range(t):
	n = int(input())
	bases = [0, 5]
	total = [2, 7]
	proximo = 7
	i = 1
	while proximo < n:
		bases.append(bases[i] + 3)
		i += 1
		proximo = bases[i] + total[i - 1]
		total.append(proximo)
	cont = 0
	while n > 0:
		if n == 1:
			n -= 1
		elif n <= 6:
			cont += n // 2
			n = n % 2
		else:
			p = buscaBinaria(total, len(total), n)
			n -= p
			cont += 1
	print(cont)


t = int(input())
for i in range(t):
	n = int(input())
	p = 0
	while n > 1:
		h = int(((1 + 24 * n) ** 0.5 - 1) // 6)
		n1 = ((6 * h + 1) ** 2 - 1) // 24
		p += 1
		n = n - n1
	print(p)


from sys import stdin

def fin(n):
	h = 1
	for i in range(n + 1):
		if l[h] > n:
			break
		h += 1
	return l[h - 1]
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	(h, count, t) = (0, 2, 0)
	l = [0 for i in range(int(n ** 0.5) + 3)]
	(h, l[1]) = (1, 2)
	for i in range(int(n ** 0.5) + 1):
		l[h + 1] = l[h] + 3 * h + 2
		h += 1
	(h, t) = (0, 0)
	m = n
	for i in range(n):
		if m < 2:
			break
		else:
			m = m - fin(m)
			t += 1
	print(t)


t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n > 1:
		req = 2
		while req <= n:
			n = n - req
			req = req + 3
		c = c + 1
	print(c)


def func(arr, n):
	for i in range(len(arr)):
		if arr[i] > n:
			break
	return n - arr[i - 1]
t = int(input())
res = []
arr = [(3 * h * h + h) / 2 for h in range(30000)]
for _ in range(t):
	n = int(input())
	cnt = 0
	while n > 1:
		cnt += 1
		n = func(arr, n)
	res.append(cnt)
for r in res:
	print(r)


arr = []
cur = 2
h = 1
d = 1
while cur < 10 ** 9:
	arr.append(cur)
	cur += 3 * h + 2
	h += 1
t = int(input())
for tt in range(t):
	n = int(input())
	cnt = 0
	for i in reversed(arr):
		while n >= i:
			cnt += 1
			n -= i
	print(cnt)


import random
import math

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		c = 0
		while n != 1 and n != 0:
			x = int((math.sqrt(1 + 24 * n) - 1) // 6)
			n = n - (3 * x * x + x) // 2
			c += 1
		print(c)
main()


import math as m
t = int(input())
for i in range(t):
	n = int(input())
	c = 0
	while n >= 2:
		k = m.floor((-1 + m.sqrt(24 * n + 1)) / 6)
		n -= k * (3 * k + 1) // 2
		c += 1
	print(c)


from sys import stdin, stdout

def solve(n):
	if n < 2:
		return 0
	amntCards = n
	pyramids = 0
	while amntCards >= 2:
		l = 0
		r = amntCards
		resSum = 0
		while l <= r:
			mid = l + (r - l) // 2
			sum = 3 * mid ** 2 / 2 + mid / 2
			if sum == amntCards:
				pyramids += 1
				return pyramids
			elif sum < amntCards:
				l = mid + 1
				resSum = max(resSum, sum)
			else:
				r = mid - 1
		amntCards -= resSum
		pyramids += 1
	return pyramids
t = int(stdin.readline())
for _ in range(t):
	stdout.write(f'{solve(int(stdin.readline()))}\n')


from bisect import bisect
x = [3 * n * (n + 1) // 2 - n for n in range(1, 30000)]

def solve(n):
	res = 0
	while n > 1:
		n -= x[bisect(x, n) - 1]
		res += 1
	return res
for _ in range(int(input())):
	print(solve(int(input())))


import bisect
l = []
l.append(0)
l.append(2)
a = l[-1]
d = 5
while l[-1] < 10 ** 9:
	a = a + d
	l.append(a)
	d = d + 3
a = a + d
l.append(a)
t = int(input())
for _ in range(t):
	n = int(input())
	s = 0
	while n >= 2:
		i = bisect.bisect_right(l, n, 0, len(l))
		i = i - 1
		n = n - l[i]
		s = s + 1
	print(s)


from math import sqrt
t = int(input())
for qq in range(t):
	n = int(input())
	p = int(sqrt(n)) + 1
	s = 0
	p_c = p
	for i in range(p_c, 0, -1):
		if (3 * i * i + i) // 2 <= n:
			k = n // ((3 * i * i + i) // 2)
			n -= k * (3 * i * i + i) // 2
			s += k
	print(s)


def game(r):
	count = 0
	if r > 1:
		while r >= 2:
			cards = 0
			height = 1
			while r >= 0.5 * (height * (3 * height + 1)):
				cards = 0.5 * (height * (3 * height + 1))
				height += 1
			r -= cards
			count += 1
	print(count)
t = int(input())
for i in range(t):
	r = int(input())
	game(r)


for _ in range(int(input())):
	n = int(input())
	t = max((-1 + (1 + 24 * n) ** 0.5) // 6, (-1 - (1 + 24 * n) ** 0.5) // 6)
	t = int(t)
	Ans = 0
	while n != 0 and t > 0:
		k = (3 * t ** 2 + t) // 2
		m = n // k
		Ans += m
		n = n - m * k
		t -= 1
	print(Ans)


def mm(n):
	if n <= 1:
		return 0
	if n == 2:
		return 1
	h = ((1 + 24 * n) ** 0.5 - 1) // 6
	n -= (3 * h * h + h) // 2
	return 1 + mm(n)
t = int(input())
for _ in range(t):
	n = int(input())
	print(mm(n))


i = 1
s = 2
d = 5
p = 0
l = []
while True:
	l.append(s)
	if s > 1000000000:
		break
	s = s + d
	d = d + 3
	i = i + 1
import bisect
for t in range(int(input())):
	n = int(input())
	if n == 1:
		print(0)
		continue
	ans = 0
	while True:
		ix = bisect.bisect_left(l, n)
		val = l[ix - 1]
		if l[ix] == n:
			val = l[ix]
		n = n - val
		ans = ans + 1
		if n == 1 or n == 0:
			break
	print(ans)


check = [2]
i = 0
while check[-1] <= 10 ** 9:
	check.append(check[-1] + 3 * i + 5)
	i += 1
from bisect import bisect_right

def dfs(x):
	if x < 2:
		return 0
	return dfs(x - check[bisect_right(check, x) - 1]) + 1
for _ in range(int(input())):
	n = int(input())
	print(dfs(n))


def find_cards(x):
	height = (-1 + (1 + 24 * x) ** 0.5) // 6
	x -= (3 * (height * (height + 1)) - 2 * height) // 2
	return x
for _ in range(int(input())):
	x = int(input())
	cou = 0
	while x > 1:
		x = find_cards(x)
		cou += 1
	print(cou)


import cmath
t = int(input())
for i in range(t):
	co = 0
	c = int(input())
	while c > 1:
		d = 0.5 ** 2 - 4 * 1.5 * -c
		r = (-0.5 + cmath.sqrt(d)) / (2 * 1.5)
		r = r.real
		r = int(r)
		if r > 0:
			co += 1
		cn = 1.5 * r * r + 0.5 * r
		c = c - cn
	print(co)


def cards_needed(n):
	return 3 * n * (n + 1) // 2 - n

def max_height(n):
	start = 0
	end = pow(10, 10)
	while start <= end:
		mid = start + (end - start) // 2
		cards = cards_needed(mid)
		if cards == n:
			return mid
		elif cards < n:
			start = mid + 1
		else:
			end = mid - 1
	return start - 1

def solve(n):
	result = 0
	needed = cards_needed(max_height(n))
	while needed > 0:
		result += 1
		n -= needed
		needed = cards_needed(max_height(n))
	return result
for i in range(int(input())):
	print(solve(int(input())))


for _ in range(int(input())):
	n = int(input())
	used_cards = 0
	pyramids = 0
	h = 1
	while h * (3 * h + 1) // 2 <= n:
		h += 1
	h -= 1
	n -= h * (3 * h + 1) // 2
	if h > 0:
		pyramids += 1
	while h > 0 and n > 0:
		if n - h * (3 * h + 1) // 2 >= 0:
			n -= h * (3 * h + 1) // 2
			pyramids += 1
		else:
			h -= 1
	print(pyramids)


t = int(input())
for _ in range(t):
	n = int(input())
	if n < 2:
		print(0)
	else:
		b = []
		for i in range(1, 100000):
			a = int(i * (i + 1) + i * (i - 1) / 2)
			if a > n:
				break
			b.insert(0, a)
		count = 0
		for i in b:
			count += n // i
			n = n % i
			if n < 2:
				break
		print(count)


import math
T = int(input())
for tc in range(T):
	n = int(input())
	ans = 0
	while n > 1:
		nn = int(math.sqrt(n))
		ans += 1
		while True:
			if (nn ** 2 + nn) / 2 + nn ** 2 <= n:
				n = n - ((nn ** 2 + nn) / 2 + nn ** 2)
				break
			else:
				nn -= 1
	print(ans)


piramides = list()
(cartas, nivel) = (0, 1)
while cartas < 10 ** 9:
	cartas = cartas + 2 * nivel + (nivel - 1)
	piramides.append(cartas)
	nivel += 1
for _ in range(int(input())):
	cartas = int(input())
	construcoes = 0
	while cartas >= piramides[0]:
		teste = 0
		while cartas >= piramides[teste]:
			teste += 1
		cartas = cartas - piramides[teste - 1]
		construcoes += 1
	print(construcoes)


h = [(3 * i * i + i) // 2 for i in range(1, 100003)]
import bisect
t = int(input())
for i in range(t):
	n = int(input())
	cnt = 0
	while n > 1:
		pos = bisect.bisect_left(h, n)
		if h[pos] > n:
			pos -= 1
		n -= h[pos]
		cnt += 1
	print(cnt)


M = 100000007
for _ in range(int(input())):
	n = int(input())
	x = 0
	while (3 * x * x + x) // 2 < n:
		x += 1
	ans = 0
	while n > 1:
		if (3 * x * x + x) // 2 <= n:
			n = n - (3 * x * x + x) // 2
			ans += 1
		else:
			x -= 1
	print(ans)


t = int(input())

def find_max(n):
	if n == 2:
		return 1
	(l, r) = (1, 100000.0)
	ans = -1
	while l <= r:
		m = l + (r - l) // 2
		c = (3 * m ** 2 + m) // 2
		if c > n:
			r = m - 1
		else:
			ans = m
			l = m + 1
	return ans
for _ in range(t):
	n = int(input())
	res = 0
	while n > 1:
		c = find_max(n)
		c = (3 * c ** 2 + c) // 2
		n -= c
		res += 1
	print(res)


k = 5
l = [2, 7]
while l[-1] < 10 ** 9:
	k += 3
	l.append(l[-1] + k)
t = int(int(input()))
for _ in range(t):
	n = int(input())
	i = len(l) - 1
	ans = 0
	while i >= 0:
		if n - l[i] >= 0:
			ans += n // l[i]
			n %= l[i]
		i -= 1
	print(ans)


def cards(n):
	return int(2 * ((n ** 2 + n) / 2) + (n ** 2 - n) / 2)
for i in range(int(input())):
	count = 0
	prompt = int(input())
	stop = True
	while stop:
		temp = 0
		for i in range(1, prompt + 1):
			if cards(i) > prompt:
				break
			else:
				temp += 1
		if temp == 0:
			print(count)
			stop = False
		else:
			count += 1
			prompt -= cards(temp)


def sum(x):
	return x * (x + 1) // 2

def cartas(X):
	return sum(X) * 2 + sum(X - 1)

def BN(n):
	a = 1
	b = 25820
	while a < b:
		med = (a + b) // 2
		x = cartas(med)
		if n < x:
			b = med
		else:
			a = med + 1
	if cartas(a) > n:
		a -= 1
	return a
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = BN(n)
	cnt = 0
	UKA = cartas(a)
	while a > 0:
		UKA = cartas(a)
		if n >= UKA:
			D = n // UKA
			n = n - UKA * D
			cnt += D
		else:
			a -= 1
	print(cnt)


t = int(input())

def count(n):
	c = 0
	while n >= 2:
		c += 1
		i = 1
		while n - i * 3 > 0 and n - i * 3 - (i + 1) * 2 >= 0:
			n = n - i * 3
			i += 1
		n = n - i * 2
	return c
for _ in range(t):
	n = int(input())
	ans = count(n)
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	nAll = 0
	while n - 2 > -1:
		i = 2
		l = 0
		while True:
			n -= i + l
			i += 2
			l += 1
			if n - (i + l) < 0:
				nAll += 1
				break
	print(nAll)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		for i in range(1, 10 ** 6):
			if i * (3 * i + 1) // 2 > n:
				ans += 1
				n -= (i - 1) * (3 * i - 2) // 2
				break
	print(ans)


def card_contsructions(n):
	cards = n
	if cards == 0 or cards == 1:
		return 0
	h = 0
	while cards - 2 - 3 * h >= 0:
		cards = cards - 2 - 3 * h
		h = h + 1
	return 1 + card_contsructions(cards)
t = int(input())
array = []
for i in range(t):
	array.append(int(input()))
for a in array:
	print(card_contsructions(a))


t = int(input())
for i in range(t):
	n = int(input())
	c = (int((1 + 24 * n) ** 0.5) - 1) // 6
	s = 0
	while c > 0:
		a = c * (3 * c + 1) // 2
		if n - a >= 0:
			n -= a
			s += 1
		else:
			break
		c = (int((1 + 24 * n) ** 0.5) - 1) // 6
	print(s)


from sys import stdin
import bisect

def main():
	h = [2]
	m = 2
	while True:
		h.append(m * 2 + (m - 1) * 1 + h[-1])
		m += 1
		if h[-1] >= 10 ** 9:
			break
	readline = stdin.readline
	t = int(readline())
	for i in range(t):
		n = int(readline())
		res = 0
		while True:
			if n <= 1:
				break
			else:
				l = bisect.bisect_right(h, n) - 1
				n -= h[l]
				res += 1
		print(res)
main()


t = int(input())
for _ in range(t):
	n = int(input())
	pyramids = 0
	while n > 1:
		h = 1
		cards = 0
		while True:
			temp = int(1 / 2 * h * (3 * h + 1))
			if temp <= n:
				cards = temp
			else:
				break
			h += 1
		n -= cards
		pyramids += 1
	print(pyramids)


import math
import collections
from sys import stdin, stdout
M = 10 ** 9 + 7
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	c = 0
	while n > 0:
		k = (math.sqrt(1 + 24 * n) - 1) // 6
		if k == 0:
			break
		else:
			n = n - k * (3 * k + 1) // 2
			c += 1
	print(c)


def f():
	d = []
	S = 0
	i = 1
	while S <= 10 ** 9:
		S += i * 2 + i - 1
		d.append(S)
		i += 1
	return d

def bin_search(x):
	l = -1
	r = 25820
	while r - l > 1:
		m = (l + r) // 2
		if d[m] <= x:
			l = m
		else:
			r = m
	return d[l]
t = int(input())
d = f()
for i in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		ans += 1
		n -= bin_search(n)
	print(ans)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n > 1:
		n1 = n
		for i in range(n1, 1, -1):
			x = (-1 + math.sqrt(1 + 4 * 2 * i * 3)) / 6
			if x == int(x):
				c += 1
				n -= i
				break
	print(c)


def s(k):
	return k * (3 * k + 1)
T = int(input())
ans = ''
for _ in range(T):
	n = int(input())
	t = 0
	while n > 1:
		l = 1
		r = int(n ** 0.5)
		while l + 1 < r:
			k = (l + r) // 2
			if 2 * n >= s(k):
				l = k
			else:
				r = k - 1
		if l == r:
			n -= s(l) // 2
		elif 2 * n >= s(r):
			n -= s(r) // 2
		else:
			n -= s(l) // 2
		t += 1
	ans += str(t) + '\n'
print(ans)


import bisect
arr = [2]
h = 2
level = 2
while h <= 1000000000:
	h = h + level - 1 + level * 2
	arr.append(h)
	level += 1
t = int(input())
for test in range(t):
	n = int(input())
	count = 0
	while n > 1:
		ind = bisect.bisect_right(arr, n) - 1
		n -= arr[ind]
		count += 1
	print(count)


import sys
input = sys.stdin.readline
import bisect
d = []
a = 2
b = 0
s = 0
while True:
	s += a
	d.append(s)
	a += 3
	if s > 10 ** 9:
		break
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		n -= d[bisect.bisect_right(d, n) - 1]
		c += 1
	print(c)


cl = [(3 * i * i + 7 * i) // 2 + 2 for i in range(30000)]

def bs(k, li):
	(l, r) = (0, len(li) - 1)
	if li[l] > k:
		return 0
	if li[r] <= k:
		return len(li)
	while True:
		if r - l < 2:
			return r
		m = l + (r - l >> 1)
		if li[m] > k:
			r = m
		else:
			l = m
m = int(input())
for i in range(m):
	n = int(input())
	r = len(cl)
	c = 0
	while True:
		j = bs(n, cl[:r])
		if j == 0:
			break
		n = n - cl[j - 1]
		c += 1
		r = j
	print(c)


t = int(input())
vc = [2]
idx = 1
while True:
	tmp = vc[idx - 1] + 2 + idx * 3
	if tmp > 1000000000:
		break
	else:
		vc.append(tmp)
		idx = idx + 1
for i in range(t):
	n = int(input())
	count = 0
	for k in range(idx - 1, -1, -1):
		if n >= vc[k]:
			count = count + n // vc[k]
			n = n % vc[k]
		if n <= 1:
			break
	print(count)


prefixSum = []
s = 0
prefixSum.append(0)
for i in range(1, 25821):
	s += i * 3
	prefixSum.append(s)
testcases = int(input())
for i in range(testcases):
	n = int(input())
	count = 0
	while n > 1:
		for i in range(n):
			if prefixSum[i] + (i + 1) * 2 < n:
				pass
			else:
				if prefixSum[i] + (i + 1) * 2 == n:
					count += 1
					n = 0
				else:
					n -= prefixSum[i - 1] + i * 2
					count += 1
				break
	print(count)


from copy import deepcopy as dc

def func():
	global n, k
	temp = 1
	while True:
		n1 = dc(n)
		a = temp * 2 + temp - 1
		if n >= a:
			n -= a
			temp += 1
			continue
		elif temp > 1:
			k += 1
			temp = 1
		if n < 2:
			return 0
		n1 = dc(n)

def main():
	global n, k
	t = int(input())
	for i in range(t):
		n = int(input())
		k = 0
		func()
		print(k)
n = 0
k = 0
main()


t = int(input())
for z in range(t):
	n = int(input())
	count = 0
	while True:
		low = 1
		high = 10 ** 9
		ans = -1
		while low <= high:
			mid = (low + high) // 2
			if 3 * (mid * (mid + 1)) // 2 - mid <= n:
				ans = mid
				low = mid + 1
			else:
				high = mid - 1
		if ans == -1:
			break
		else:
			count += 1
			n = n - (3 * (ans * (ans + 1) // 2) - ans)
	print(count)


l = []
l.append(0)
l.append(2)
for i in range(2, 10 ** 5):
	l.append(l[i - 1] + i - 1 + 2 * i)

def find(n):
	s = 0
	e = 10 ** 5
	ans = 0
	while s <= e:
		mid = (s + e) // 2
		if l[mid] > n:
			e = mid - 1
		else:
			ans = l[mid]
			s = mid + 1
	return ans
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		ele = find(n)
		n -= ele
		c += 1
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		l = 0
		r = n
		while l != r:
			mid = (l + r) // 2
			if (3 * mid + 1) * mid // 2 <= n:
				l = mid + 1
			else:
				r = mid
		n -= (3 * (l - 1) + 1) * (l - 1) // 2
		ans += 1
	print(ans)


import math
t = int(input())
for T in range(t):
	n = int(input())
	count = 0
	while n >= 2:
		l = math.sqrt(1 + 24 * n)
		k = int((-1 + l) / 6)
		count += 1
		e = (3 * k ** 2 + k) / 2
		e = int(e)
		n = n - e
	print(count)


for s in [*open(0)][1:]:
	x = int(s)
	res = 0
	while x > 1:
		d = int((-1 + (1 + 4 * 3 * 2 * x) ** 0.5) / 6)
		x -= d * (3 * d + 1) // 2
		res += 1
	print(res)


number = int(input())
for i in range(number):
	n = int(input())
	if n == 1:
		print(0)
	else:
		maxSize = 2
		delta = 5
		while maxSize < n + 1:
			maxSize += delta
			delta += 3
		delta -= 3
		maxSize -= delta
		delta -= 3
		np = 0
		while n >= 2:
			if n >= maxSize:
				n -= maxSize
				np += 1
			else:
				maxSize -= delta
				delta -= 3
				if maxSize < 1:
					break
		print(np)


def getHeight(n):
	temp = 1
	while temp * (3 * temp + 1) // 2 <= n:
		temp += 1
	return temp - 1
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while True:
		temp = getHeight(n)
		if temp > 0:
			ans += 1
		else:
			break
		n -= temp * (3 * temp + 1) // 2
	print(ans)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	p = 0
	while n >= 2:
		p += 1
		x = 2
		i = 2
		j = 1
		while x <= n:
			y = x
			x += j + i * 2
			i += 1
			j += 1
		n -= y
	print(p)


def cards(k):
	return 1.5 * k * k + 0.5 * k
T = int(input())
for t in range(0, T):
	n = int(input())
	count = 0
	k = 1
	while True:
		if n < 2:
			break
		else:
			p = cards(k)
			if p <= n and p + 3 * k + 2 > n:
				count += 1
				n = n - p
				k = 1
			else:
				k += 1
	print(count)


T = int(input())

def numCards(h):
	return h * (h * 3 - 3 + 4) // 2

def solve():
	N = int(input())
	ans = 0
	while N >= 2:
		idx = 0
		jump = int(1000000000.0)
		while jump != 0:
			while idx + jump >= 1 and numCards(idx + jump) <= N:
				idx += jump
			jump //= 2
		ans += 1
		N -= numCards(idx)
	print(ans)
for _ in range(T):
	solve()


for _ in range(int(input())):
	n = int(input())
	p = 0
	while n > 1:
		cards = 2
		more_cards = 5
		while n >= cards + more_cards:
			cards += more_cards
			more_cards += 3
		n -= cards
		p += 1
	print(p)


import math

def solve():
	n = int(input())
	count = 0
	if n == 1:
		print(0)
		return
	while 1:
		v = -1 + int(pow(1 + 24 * n, 0.5))
		v1 = v // 6
		d = v1 * (v1 + 1) // 2
		d = 3 * d - v1
		if n >= d:
			count += 1
			n = n - d
		else:
			break
		if n <= 1:
			break
	print(count)
for _ in range(int(input())):
	solve()


import math
from decimal import Decimal
import heapq
import copy
import heapq
from collections import deque

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def da():
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	return (n, m, a)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def lol(lst, k):
	k = k % len(lst)
	ret = [0] * len(lst)
	for i in range(len(lst)):
		if i + k < len(lst) and i + k >= 0:
			ret[i] = lst[i + k]
		if i + k >= len(lst):
			ret[i] = lst[i + k - len(lst)]
		if i + k < 0:
			ret[i] = lst[i + k + len(lst)]
	return ret

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

def dvs():
	n = int(input())
	m = int(input())
	return (n, m)

def fact(n):
	tc = []
	ans = {}
	d = 2
	while d * d <= n:
		if n % d == 0:
			tc.append(d)
			n //= d
		else:
			d += 1
	if n > 1:
		tc.append(n)
	for i in tc:
		ans[i] = ans.get(i, 0) + 1
	return ans

def how_many(l, r, c):
	m = (l + r) // 2
	if r - l == 1:
		if s[l] == c:
			return 0
		else:
			return 1
	d = s[l:m]
	k1 = (r - l) // 2 - s[l:m].count(c) + how_many(m, r, chr(ord(c) + 1))
	k2 = (r - l) // 2 - s[m:r].count(c) + how_many(l, m, chr(ord(c) + 1))
	return min(k1, k2)
for _ in range(int(input())):
	n = int(input())
	k = 0
	while n >= 2:
		l = 0
		r = 155000
		lst = 0
		while l + 1 < r:
			m = (l + r) // 2
			d = m * (3 * m + 1) // 2
			if d <= n:
				l = m
				lst = m
			else:
				r = m
		d = lst * (3 * lst + 1) // 2
		n -= d
		k += 1
	print(k)


z = int(input())
for h in range(z):
	n = int(input())
	cnt = 0
	while n > 1:
		h = 2
		x = 2
		while True:
			y = 2 * h + 3 * (h - 1) * h // 2
			if y > n:
				cnt += 1
				n = n - x
				break
			else:
				x = y
			h += 1
	print(cnt)


t = int(input())
for q in range(t):
	n = int(input())
	answer = 0
	while n > 0:
		x = 1
		ch = 0
		while n > 0:
			if n < ch + 2 * x + x - 1:
				if ch > 0:
					answer += 1
					n -= ch
					break
				else:
					n = 0
					break
			ch += 2 * x + x - 1
			x += 1
	print(answer)


import math
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		h = int((math.sqrt(1 + 24 * n) - 1) // 6)
		n -= h * (h + 1) + (h - 1) * h // 2
		ans += 1
	print(ans)


for i in range(int(input())):
	n = int(input())
	h = 1
	c = 0
	f = 1
	l = []
	if n < 2:
		print(0)
		continue
	while n >= 0:
		if n - h * 2 - (h - 1) >= 0:
			n = n - h * 2 - (h - 1)
			h += 1
			f = 1
		elif n - h * 2 - (h - 1) < 0 and f == 0:
			break
		else:
			f = 0
			c += 1
			l.append(h)
			h = 1
	print(c)


def cal(n):
	if n < 2:
		return 0
	else:
		h = 1
		x = 0
		c = 1
		while x <= n:
			x = h * (h + 1) + h * (h - 1) // 2
			h += 1
		h = h - 2
		x = h * (h + 1) + h * (h - 1) // 2
		n = n - x
		return c + cal(n)
T = int(input())
for _ in range(0, T):
	n = int(input())
	if n < 2:
		ans = 0
	else:
		ans = cal(n)
	print(ans)


queries = int(input())

def solution(number_of_cards):
	number_of_pyramids = 0
	while number_of_cards > 1:
		layer = 1
		while number_of_cards >= build_pyramids(layer):
			number_of_cards -= build_pyramids(layer)
			layer += 1
		number_of_pyramids += 1
	print(number_of_pyramids)

def build_pyramids(number_of):
	if number_of == 1:
		return 2
	else:
		return number_of * 2 + number_of - 1
for _ in range(queries):
	solution(int(input()))


def f(b):
	n = 2
	k = 2
	while True:
		if n + k + 3 <= b:
			n = k + n + 3
			k = k + 3
		else:
			break
	return n
a = int(input())
for i in range(a):
	b = int(input())
	k = 0
	while b > 1:
		b = b - f(b)
		k += 1
	print(k)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n > 1:
		x = int((-1 + (1 + 24 * n) ** (1 / 2)) // 6)
		c = c + 1
		n = n - (3 * x ** 2 + x) // 2
	print(c)


nums = []

def seive():
	for i in range(1, 100000):
		x = (3 * i + 1) * i // 2
		nums.append(x)

def binarySearch(arr, n, key):
	left = 0
	right = n
	mid = 0
	while left < right:
		mid = (right + left) // 2
		if arr[mid] == key:
			while mid + 1 < n and arr[mid + 1] == key:
				mid += 1
			break
		elif arr[mid] > key:
			right = mid
		else:
			left = mid + 1
	while mid > -1 and arr[mid] > key:
		mid -= 1
	return mid
seive()
for _ in range(int(input())):
	num = int(input())
	if num < 2:
		print(0)
	else:
		ans = 0
		while num > 1:
			index = binarySearch(nums, len(nums), num)
			y = nums[index]
			ans += num // y
			num = num % y
		print(ans)


import math
t = int(input())
while t != 0:
	n = int(input())
	count = 0
	while n > 1:
		ans = int((-1 + math.sqrt(1 + 4 * (2 * n) * 3)) / 6)
		count += 1
		n -= (3 * ans * ans + ans) / 2
		if n == 1:
			break
	print(count)
	t -= 1


for test in range(int(input())):
	n = int(input())
	pyramid_count = 0
	while n > 1:
		cards_currently = 0
		for i in range(1, n):
			temp = cards_currently + i * 2 + (i - 1)
			if temp <= n:
				cards_currently += i * 2 + (i - 1)
			elif temp > n:
				break
		n -= cards_currently
		pyramid_count += 1
	print(pyramid_count)


import math

def calculerDelta(a, b, c):
	return b * b - 4 * a * c

def resoudreEquationSecondDegre(a, b, c):
	delta = calculerDelta(a, b, c)
	if delta > 0:
		racineDeDelta = math.sqrt(delta)
		retour = [(-b - racineDeDelta) / (2 * a), (-b + racineDeDelta) / (2 * a)]
	elif delta < 0:
		retour = []
	else:
		retour = [-b / (2 * a)]
	return retour
for _ in range(int(input())):
	n = int(input())
	total = 0
	ok = True
	while ok:
		a = resoudreEquationSecondDegre(3, 1, -n * 2)
		if len(a) > 1 and a[-1] > 0:
			k = math.floor(a[-1])
			if k > 0:
				n -= k * (3 * k + 1) / 2
				total += 1
			else:
				ok = False
		else:
			ok = False
	print(total)


import os
import sys
from io import BytesIO, IOBase

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def main():
	from bisect import bisect_left as bl

	def fn(x, n):
		return x + n * 3 - 1
	a1 = [2]
	for i in range(2, 101000):
		a1.append(fn(a1[-1], i))
	T = iin()
	for _ in range(T):
		n = iin()
		ans = 0
		while n > 1:
			pos = bl(a1, n)
			if a1[pos] != n:
				pos -= 1
			x1 = a1[pos]
			n -= x1
			ans += 1
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())

def f(x):
	return (3 * x + 1) * x // 2

def constructable_height(n):
	D = (1 + 24 * n) ** 0.5
	x = (-1 + D) / 6
	x = int(x)
	return x
for _ in range(t):
	n = int(input())
	remaining = n
	trees = 0
	while True:
		if remaining < 2:
			break
		trees += 1
		a = constructable_height(remaining)
		usable = f(a)
		remaining = remaining - usable
	print(trees)


T = int(input())
from functools import lru_cache

@lru_cache()
def num_cards(h):
	if h == 1:
		return 2
	res = h * (h + 1) + (h - 1) * h // 2
	return res

def find_max_bound(n):
	h = 2
	while num_cards(h) <= n:
		h *= 2
	return h

def lower_bound(n, max_bound):
	left = 1
	right = max_bound
	while left < right:
		mid = (left + right) // 2
		if num_cards(mid) > n:
			right = mid
		elif num_cards(mid) < n:
			left = mid + 1
		else:
			return mid + 1
	return left
for t in range(T):
	n = int(input())
	cards_left = n
	max_bound_h = find_max_bound(cards_left)
	res = 0
	while cards_left > 1:
		h = lower_bound(cards_left, max_bound_h) - 1
		cards_left -= num_cards(h)
		res += 1
	print(res)


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	n = int(I1())
	ans = 0
	while n >= 2:
		c = 2
		f = 0
		while n >= c:
			n -= c
			c += 3
			f = 1
		if f:
			ans += 1
	print(ans)


def solve(n):
	ans = 0
	while n:
		(can, n) = build(n)
		if can:
			ans += 1
	return ans

def build(n):
	(cur, h) = (0, 0)
	while cur + (h + 1) * 2 + h <= n:
		cur += (h + 1) * 2 + h
		h += 1
	if h:
		return (True, n - cur)
	else:
		return (False, None)
t = int(input())
for i in range(t):
	n = int(input())
	print(solve(n))


T = int(input())
for i in range(T):
	n = int(input())
	x1 = 2
	count = 0
	while x1 <= n:
		prev = x1
		while x1 <= n:
			temp = x1
			x1 = x1 + (prev + 3)
			prev += 3
		count += 1
		n = n - temp
		x1 = 2
	print(count)


from math import floor
for i in range(int(input())):
	n = int(input())
	a = 3
	b = 1
	s = 0
	while n > 1:
		c = -2 * n
		d = b ** 2 - 4 * a * c
		h = floor((-b + d ** 0.5) / (2 * a))
		n -= h * (3 * h + 1) // 2
		s += 1
	print(s)


t = int(input())
for i in range(t):
	x = -1
	sum = 0
	y = 0
	a = int(input())
	while a >= 2:
		while sum <= a:
			x = x + 3
			sum = sum + x
		sum = sum - x
		a = a - sum
		y = y + 1
		x = -1
		sum = 0
	print(y)


t = int(input())
for _ in range(t):
	a = int(input())
	c = 0
	while 1:
		if a == 1:
			break
		ans = (-1 + (1 + 24 * a) ** (1 / 2)) / 6
		if ans == int(ans):
			c += 1
			break
		n = int(ans)
		res = n * (3 * n + 1) / 2
		a = a - res
		c += 1
		if a <= 1:
			break
	print(c)


import math
t = int(input())

def build(c):
	if c <= 1:
		return 0
	x0 = (-1 + math.sqrt(24 * c + 1)) / 6
	nmax = math.floor(x0)
	return 1 + build(c - (3 * nmax ** 2 + nmax) / 2)
for _ in range(t):
	n = int(input())
	print(build(n))


import math

def find_sqrt(n):
	x = (-1 + math.sqrt(1 + 24 * n)) / 6
	y = (-1 - math.sqrt(1 + 24 * n)) / 6
	return max(x, y)
test = int(input())
while test > 0:
	count = 0
	n = int(input())
	while True:
		height = int(find_sqrt(n))
		if not height > 0:
			print(count)
			break
		n = n - (pow(height, 2) * 3 + height) / 2
		count += 1
	test = test - 1


from sys import *
from bisect import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)

def binary_search(n, lst):
	(low, high) = (0, len(lst) - 1)
	if n < 2:
		return -1
	else:
		while low <= high:
			mid = low + (high - low) // 2
			if lst[mid] == n:
				return mid + 1
			elif lst[mid] <= n:
				low = mid + 1
			else:
				high = mid - 1
		return bisect_left(lst, n)
for _ in range(int(input())):
	n = int(input())
	inc = 5
	val = 2
	lst = []
	while val <= n:
		lst.append(val)
		val += inc
		inc += 3
	ct = 0
	ind = 0
	if lst:
		while 1:
			ind = binary_search(n, lst)
			if ind == -1:
				break
			n -= lst[ind - 1]
			ct += 1
		print(ct)
	else:
		print(0)


w = int(input())
for x in range(w):
	c = int(input())
	p = 0
	while c >= 2:
		i = 1
		j = 0
		n_t = i * 2 + j
		while c - n_t >= 0:
			c -= n_t
			i += 1
			j += 1
			n_t = i * 2 + j
		p += 1
	print(p)


for _ in range(int(input())):
	n = int(input())
	f = 0
	s = 0
	while f == 0:
		p = 0
		for i in range(1, n):
			x = (3 * i ** 2 + i) / 2
			x = int(x)
			if x <= n:
				p = x
			else:
				break
		if p > 0:
			n = n - p
			s = s + 1
		else:
			f = 1
	print(s)


for i in range(int(input())):
	n = int(input())

	def pi(n):
		a = 2
		c = False
		while n >= a:
			n -= a
			a += 3
		return n
	c = 0
	while n >= 2:
		n = pi(n)
		c += 1
	print(c)


from sys import stdin

def r():
	return stdin.readline()

def r_t():
	return map(int, r().strip().split())

def r_a():
	return list(r_t())

def lower(A, x):
	(lo, hi) = (0, len(A))
	while lo + 1 != hi:
		mid = lo + hi >> 1
		if A[mid] <= x:
			lo = mid
		else:
			hi = mid
	return lo

def solve(n, A):
	ans = 0
	while n > 1:
		n -= A[lower(A, n)]
		ans += 1
	return ans

def main():
	(ac, i) = (0, 1)
	A = list()
	while ac <= int(1000000000.0):
		ac += i
		A.append(ac * 2 + (ac - i))
		i += 1
	cases = int(r())
	for case in range(cases):
		n = int(r())
		print(solve(n, A))
main()


def solve(n):
	ans = 0
	while n > 1:
		cur = 0
		for h in range(2, 100000):
			p = (3 * h * h - 5 * h + 2) // 2
			if p <= n:
				cur = p
			else:
				break
		if cur > 0:
			n -= cur
			ans += 1
		else:
			break
	return ans

def main():
	T = int(input())
	for case in range(T):
		n = int(input())
		answer = solve(n)
		print(answer)
main()


test = int(input())

def value(t):
	return t * (3 * t + 1) / 2

def f(x):
	if x < 2:
		return 0
	elif x == 2:
		return 1
	else:
		h = 1
		k = 2
		while k <= x:
			h += 1
			k = value(h)
		card_used = value(h - 1) if k != x else k
		return 1 + f(x - card_used)
for i in range(test):
	n = int(input())
	ans = f(n)
	print(ans)


from math import *
from random import *
cr = 2
h = 1
mas = []
for i in range(50000):
	mas.append(cr)
	cr = cr + h + (h + 1) * 2
	h += 1
for t in range(int(input())):
	cnt = 0
	n = int(input())
	while n > 1:
		l = 0
		r = 50000 - 1
		while r - l > 1:
			m = (l + r) // 2
			if mas[m] <= n:
				l = m
			else:
				r = m
		cnt += 1
		n -= mas[l]
	print(cnt)


import bisect
a = [0] * 25819
for i in range(1, 25820):
	a[i - 1] = int(1.5 * i ** 2 + 0.5 * i)
for _ in range(int(input())):
	n = int(input())
	if n == 1:
		count = 0
	else:
		count = 0
		pyr = n
		while n > 1:
			pyr = n
			pyr = a[bisect.bisect_right(a, pyr) - 1]
			n = n - pyr
			count += 1
	print(count)


def next():
	return [int(x) for x in input().split()]

def f(n):
	return (n + 1) * n // 2 * 3 - n
(cas,) = next()
for i in range(cas):
	(n,) = next()
	r = 0
	while n >= 2:
		r += 1
		l = 0
		h = n
		while h - l > 1:
			m = (h + l) // 2
			if f(m) <= n:
				l = m
			else:
				h = m
		n -= f(l)
	print(r)


from sys import stdin, exit, setrecursionlimit
from collections import deque
from heapq import *
from math import gcd
from math import ceil, log2
setrecursionlimit(10000000)
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()

def f(x):
	y = 1.5 * x ** 2 + 0.5 * x
	return int(y)
for _ in range(int(input())):
	n = int(input())
	cnt = 0
	while n >= 2:
		r = 100000
		l = 0
		cur = 0
		while r > l:
			mid = r + l >> 1
			if f(mid) > n:
				r = mid
			else:
				cur = mid
				l = mid + 1
		n -= f(cur)
		cnt += 1
	print(cnt)


lista = []
nivel = 1
cards = 0
while cards < 10 ** 9:
	cards = cards + nivel * 2 + (nivel - 1)
	nivel += 1
	lista.append(cards)
for _ in range(int(input())):
	n = int(input())
	py = 0
	i = 0
	while n >= 2:
		if n > lista[i]:
			i += 1
		elif n == lista[i]:
			n -= lista[i]
			py += 1
		else:
			n -= lista[i - 1]
			py += 1
			i = 0
	print(py)


import sys, bisect
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)

def main():
	ntc = next(ints)
	(total, base) = (2, 1)
	a = [0, total]
	while total <= 10 ** 9:
		base += 1
		total += 2 * base + base - 1
		a.append(total)
	for tc in range(ntc):
		n = next(ints)
		ans = 0
		while n >= 2:
			i = bisect.bisect(a, n) - 1
			assert a[i] <= n
			n -= a[i]
			ans += 1
		print(ans)
	return
main()


t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n >= 2:
		count = 0
		tmp = 0
		i = 1
		while count < n:
			tmp += i * 2 + i - 1
			if tmp <= n:
				count = tmp
			else:
				break
			i += 1
		n -= count
		ans += 1
	print(ans)


t = int(input())
a = []
for i in range(t):
	a.append(int(input()))
m = max(a)
pre = []
for i in range(100000):
	pre.append(i * (3 * i + 1) // 2)
	if pre[-1] > m:
		break

def build(x):
	n_ = 0
	for n in pre:
		if n > x:
			return n_
		n_ = n
for x in a:
	pyramids = 0
	while x > 1:
		pyramids += 1
		x -= build(x)
	print(pyramids)


for _ in range(int(input())):
	n = int(input())
	(array, i, c) = ([2], 0, 0)
	while array[-1] < n:
		i += 1
		array.append(array[i - 1] + (3 * i + 2))
	i = len(array)
	try:
		while i >= 0 or n:
			i -= 1
			while array[i] <= n:
				n -= array[i]
				c += 1
	except:
		pass
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	counter = 0
	while n >= 2:
		nexus = 2
		while n > 0:
			n -= nexus
			nexus += 3
		counter += 1
		if n == 0:
			break
		n += nexus - 3
	print(counter)


from math import floor, sqrt
for t in range(int(input())):
	n = int(input())
	c = n
	count = 0
	while c >= 2:
		h = floor((-1 + sqrt(1 + 24 * c)) / 6)
		c = c - 2 * h - (h * h - h) * 3 / 2
		count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	ispossible = True
	left_cards = n
	counter = 0
	while ispossible:
		h = ((24 * left_cards + 1) ** 0.5 - 1) // 6
		if h > 0:
			counter += 1
		left_cards = left_cards - h * (h + 1) - (h - 1) * h // 2
		if left_cards < 2:
			ispossible = False
	print(counter)


from math import sqrt

def find_max_count(n):
	c = int((-1 + sqrt(1 + 3 * 4 * 2 * n)) / 6)
	return int(1.5 * c ** 2 + 0.5 * c)

def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		ans = 0
		while n >= 2:
			ans += 1
			n -= find_max_count(n)
		print(ans)
main()


import sys
import math
import collections
import heapq
import queue
import itertools
import functools
import operator
import time
readline = sys.stdin.readline
IPS = lambda : readline().rstrip()
IP = lambda : int(readline().rstrip())
MP = lambda : map(int, readline().split())
LS = lambda : list(map(int, readline().split()))
dp = [0]

def pre():
	for i in range(1, 1000001):
		dp.append(3 * i - 1 + dp[i - 1])

def solve():
	for _ in range(IP()):
		n = IP()
		(i, cnt) = (1, 0)
		while n > 1:
			if dp[i] > n:
				n -= dp[i - 1]
				i = 1
				cnt += 1
			else:
				i += 1
		print(cnt)
pre()
solve()


import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li1():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			s.add(i)
			n = n // i
	if n > 2:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def treeOrderByDepth(n, adj, root=0):
	parent = [-2] + [-1] * (n - 1)
	ordered = []
	q = deque()
	q.append(root)
	depth = [0] * n
	while q:
		c = q.popleft()
		ordered.append(c)
		for a in adj[c]:
			if parent[a] == -1:
				parent[a] = c
				depth[a] = depth[c] + 1
				q.append(a)
	return (ordered, parent, depth)
l = [2]
x = 2
n = 2
k = 1
while x <= mod - 7:
	x = n ** 2 + n + k * (k + 1) // 2
	n += 1
	k += 1
	l.append(x)
for _ in range(ii()):
	n = ii()
	c = 0
	if n <= 1:
		print(0)
	else:
		while n >= 2:
			index = bisect.bisect(l, n)
			c += n // l[index - 1]
			n -= l[index - 1] * (n // l[index - 1])
		print(c)


def bs(x):
	a = 0
	b = 100000
	while a <= b:
		if b - a <= 5:
			for i in range(b, a - 1, -1):
				if l[i] <= x:
					return l[i]
			return 0
		mid = (a + b) // 2
		if l[mid] <= x:
			a = mid
		else:
			b = mid - 1
l = []
for i in range(100001):
	l.append(0)
for i in range(100001):
	l[i] = i * (3 * i + 1) // 2
t = int(input())
for _ in range(t):
	n = int(input())
	count = 0
	while True:
		x = bs(n)
		if x == 0:
			break
		n -= x
		count += 1
	print(count)


import sys
I = sys.stdin.readline
ans = ''
for _ in range(int(I())):
	n = int(I())
	card = 2
	next_card = 5
	k = 0
	if n < card:
		ans += '0\n'
	else:
		p = []
		while card <= n:
			p.append(card)
			card += next_card
			next_card += 3
		p.reverse()
		i = 0
		while n > 1:
			if n >= p[i]:
				n -= p[i]
				k += 1
			else:
				i += 1
		ans += str(k) + '\n'
print(ans)


for _ in [0] * int(input()):
	n = int(input())
	towers = 0
	while n > 1:
		a = int(((24 * n + 1) ** 0.5 - 1) / 6)
		n -= a * (3 * a + 1) // 2
		towers += 1
	print(towers)


t = int(input())
for i in range(t):
	n = int(input())
	height = 2
	count = 0
	while n >= 2:
		n -= height
		height += 3
		if height > n:
			height = 2
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	p = 2
	i = 0
	nop = 0
	if n == 1:
		print(0)
		continue
	while n > p:
		i += 1
		p += 2 + 3 * i
	if p == n:
		print(1)
		continue
	p -= 2 + 3 * i
	nop = n // p
	n %= p
	while n > 1:
		i -= 1
		p -= 2 + 3 * i
		if p <= n:
			nop += n // p
			n %= p
	print(nop)


t = int(input())
for i in range(t):
	n = int(input())
	count = 0
	while n >= 2:
		k = (-1 + (1 + 24 * n) ** 0.5) // 6
		count += 1
		n -= (3 * k ** 2 + k) // 2
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())

	def f(x):
		return 3 * (x + 1) * x // 2 - x
	ans = 0
	while n > 1:
		(left, right) = (1, int(100000.0))
		while left < right:
			mid = (left + right + 1) // 2
			if f(mid) > n:
				right = mid - 1
			else:
				left = mid
		n -= f((left + right + 1) // 2)
		ans += 1
	print(ans)


for _ in range(int(input())):
	N = int(input())
	ctr = 0
	while N > 1:
		height = ((1 + 24 * N) ** 0.5 - 1) // 6
		N -= height * (3 * height + 1) // 2
		ctr += 1
	print(ctr)


import sys
import math

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]
t = int(input())
for q in range(t):
	n = inputnum()
	h = 1
	t = 0
	ans = 0
	while n > 1:
		while 3 * (h * (h + 1)) // 2 - h <= n:
			t = 3 * (h * (h + 1)) // 2 - h
			h += 1
		n -= t
		ans += 1
		h = 1
		t = 0
	print(ans)


import math
T = int(input())
for t in range(1, T + 1):
	x = int(input())
	count = 0
	while x >= 2:
		n = int((-1 + math.sqrt(24 * x + 1)) / 6)
		count += 1
		x = x - int((3 * n * n + n) / 2)
	print(count)


import math
for i in range(int(input())):
	n = int(input())
	c = 0
	while n > 0:
		b = math.floor(abs(1 - math.sqrt(1 + 24 * n)) / 6)
		if b == 0:
			break
		n -= (3 * b * b + b) / 2
		c += 1
	print(c)


n = int(input())
mas = []
a = 2
dif = 5
while a < pow(10, 9):
	mas.append(a)
	a += dif
	dif += 3
mas = mas[::-1]
for test in range(n):
	m = int(input())
	ans = 0
	while m > 1:
		for el in mas:
			if el <= m:
				m -= el
				ans += 1
				break
	print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def f(a):
	return a * (a + 1) // 2 * 3 - a

def solve():
	n = int(inp())
	cnt = 0
	while n > 1:
		h = 1
		while f(h) <= n:
			h += 1
		h -= 1
		cnt += 1
		n -= f(h)
	print(cnt)
testcase(int(inp()))


t = int(input())

def solve(n):
	total = 0
	sizes = [2]
	amt = 2
	triangles = 1
	while amt <= n:
		amt += (triangles - 1) * 3 + 2 + 3
		triangles += 1
		sizes.append(amt)
	idx = len(sizes) - 1
	while idx >= 0:
		if sizes[idx] > n:
			idx -= 1
		else:
			n -= sizes[idx]
			total += 1
	return total
for _ in range(t):
	n = int(input())
	print(solve(n))


from collections import *
from bisect import *
dp = [2, 7, 15]
i = 4
while dp[-1] <= pow(10, 9):
	dp.append(dp[-1] + i * 2 + i - 1)
	i += 1
a = int(input())
for i in range(a):
	count = 0
	n = int(input())
	while n > 0:
		r = bisect_left(dp, n)
		if dp[r] > n:
			r -= 1
		if r >= 0:
			n -= dp[r]
			count += 1
		else:
			break
	print(count)


for o in range(int(input())):
	k = int(input())
	sum = 0
	while True:
		n = (-1 + (1 + 24 * k) ** 0.5) // 6
		if n == 0:
			print(sum)
			break
		k = k - n * (3 * n + 1) // 2
		sum = sum + 1
		if k < 0:
			print(sum - 1)
			break


a = [2]
i = 1
while a[-1] <= 10 ** 9:
	a.append(a[-1] + 2 * i + 2 + i)
	i += 1
L = len(a)
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		l = -1
		r = L
		m = (l + r) // 2
		t = 0
		while l < r - 1:
			if a[m] > n:
				r = m
			else:
				l = m
				t = max(a[m], t)
			m = (l + r) // 2
		n -= t
		ans += 1
	print(ans)


a = [2]
t = 2
while a[-1] < 10 ** 9:
	t += 3
	a.append(a[-1] + t)
a = a[::-1]
for _ in range(int(input())):
	n = int(input())
	ans = 0
	for i in a:
		if n >= i:
			x = n // i
			ans += x
			n -= i * x
	print(ans)


def solve(k):
	count = 0
	n = int((2 * k / 3) ** 0.5)
	while True:
		s = int(n * (3 * n + 1) / 2)
		if k == 1 or k == 0:
			break
		if s > k:
			count += 1
			k -= (n - 1) * (3 * (n - 1) + 1) / 2
			n = int((2 * k / 3) ** 0.5)
			continue
		n += 1
	return count
n = int(input())
for i in range(n):
	k = int(input())
	print(solve(k))


z = input
from math import *
for _ in range(int(z())):
	n = int(z())
	c = 0
	while n > 1:
		k = 2
		while n - k >= 0:
			n -= k
			k += 3
		c += 1
	print(c)


array = []
h = 0
res = 0
cards = 0
maxi_cards = 10 ** 9 + 1
while cards <= maxi_cards:
	cards += 2 * (h + 1) + h
	h += 1
	array.append(cards)
len_array = len(array)

def search(array, n, begin, end):
	if begin == end:
		return begin
	middle = (begin + end) // 2
	if array[middle] <= n:
		res = search(array, n, middle + 1, end)
	else:
		res = search(array, n, begin, middle)
	return res
T = int(input())
for t in range(T):
	n = int(input())
	res = 0
	while True:
		r = search(array, n, 0, len_array)
		cards = array[r - 1]
		n -= cards
		if r == 0:
			break
		res += 1
	print(res)


height = []
for i in range(1, 10 ** 5):
	height.append((3 * i ** 2 + i) // 2)
t = int(input())
while t:
	t -= 1
	n = int(input())
	count = 0
	while n > 1:
		h = int(((1 + 24 * n) ** 0.5 - 1) / 6)
		n -= height[h - 1]
		count += 1
	print(count)


sum1 = 0
l = [0, 0]
l.append(2)
r = 2
while sum1 < 1000000000:
	tmp1 = 2 * r + r - 1
	l.append(l[r] + tmp1)
	sum1 = l[r] + tmp1
	r += 1
l = l[2:]
for i in range(int(input())):
	n = int(input())
	cnt1 = 0
	while n > 1:
		i = 0
		while l[i] <= n:
			i += 1
		n = n - l[i - 1]
		cnt1 += 1
	print(cnt1)


def floorSearch(arr, low, high, x):
	if low > high:
		return -1
	if x >= arr[high]:
		return high
	mid = int((low + high) / 2)
	if arr[mid] == x:
		return mid
	if mid > 0 and arr[mid - 1] <= x and (x < arr[mid]):
		return mid - 1
	if x < arr[mid]:
		return floorSearch(arr, low, mid - 1, x)
	return floorSearch(arr, mid + 1, high, x)
l = [0, 2, 7]
tmp = 8
for i in range(2, 1000000000):
	x = l[i] + tmp
	l.append(x)
	tmp += 3
	if x > 1000000000:
		break
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n > 0:
		x = floorSearch(l, 0, len(l) - 1, n)
		if x != -1 and x != 0:
			c += 1
		else:
			break
		n -= l[x]
	print(c)


import sys
input = sys.stdin.readline
from collections import *

def binary_search():
	(l, r) = (0, len(a) - 1)
	while l <= r:
		m = (l + r) // 2
		if n >= a[m]:
			l = m + 1
		else:
			r = m - 1
	return r
t = int(input())
a = []
for i in range(1, 10 ** 5):
	a.append(i * (i + 1) + i * (i - 1) // 2)
for _ in range(t):
	n = int(input())
	ans = 0
	s = binary_search()
	for i in range(s, -1, -1):
		ans += n // a[i]
		n %= a[i]
	print(ans)


from collections import defaultdict as dfd
import math
for _ in range(int(input())):
	n = int(input())
	t = 0
	while n > 1:
		x = (-1 + (1 + 12 * 2 * n) ** 0.5) // 6
		t += 1
		n -= (3 * x ** 2 + x) / 2
	print(t)


t = int(input())
kmax = 25819
sizes = [(3 * k + 1) * k // 2 for k in range(kmax + 1)]
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		k = int(1 / 6 * ((24 * n + 1) ** 0.5 - 1))
		n -= sizes[k]
		ans += 1
	print(ans)


from sys import stdin as cin
t = int(input())
pyracosts = [0]
while pyracosts[-1] <= 10 ** 9:
	pyracosts.append(pyracosts[-1] + len(pyracosts) - 1 + 2 * len(pyracosts))
for test in range(t):
	n = int(input())
	curres = 0
	while n >= 2:
		(l, r) = [0, len(pyracosts) - 1]
		while r > l:
			m = (r + l) // 2 + 1
			if pyracosts[m] > n:
				r = m - 1
			else:
				l = m
		curres += 1
		n -= pyracosts[r]
	print(curres)


import bisect
dp = []
init = int(0)
i = int(1)
while 1:
	n = init + 2 + (i - 1) * 3
	dp.append(n)
	init = n
	i += 1
	if n > 1000000000:
		break
for i in range(int(input())):
	x = int(input())
	cnt = int(0)
	while x > 1:
		pos = bisect.bisect(dp, x) - 1
		cnt += 1
		x -= dp[pos]
	print(cnt)


L = []
for i in range(1, 100005):
	L.append(i * (3 * i + 1) // 2)
T = int(input())
for _ in range(0, T):
	n = int(input())
	ans = 0
	c = 0
	while c < 100000:
		c += 1
		low = 0
		high = len(L) - 1
		temp = -1
		while low <= high:
			mid = low + high >> 1
			if L[mid] <= n:
				temp = L[mid]
				low = mid + 1
			else:
				high = mid - 1
		if temp == -1:
			break
		else:
			ans += 1
			n -= temp
	print(ans)


heigth = [i * (3 * i + 1) / 2 for i in range(1, 25820)]
for _ in range(int(input())):
	n = int(input())
	ans = 0
	for i in heigth[::-1]:
		while i <= n:
			n -= i
			ans += 1
	print(ans)


def f(i):
	if i == 0:
		return 2
	r = (3 * i ** 2 + i) // 2
	return r

def tallest(N):
	i = 0
	while f(i + 1) <= N:
		i += 1
	return f(i)

def solve():
	N = int(input())
	ans = 0
	while True:
		tallest_cost = tallest(N)
		N -= tallest_cost
		if N >= 0:
			ans += 1
		else:
			break
	print(ans)
for _ in range(int(input())):
	solve()


d = [2]
for i in range(2, 25860):
	d.append(d[i - 2] + 2 * i + i - 1)

def lower_bound(arr, n):
	low = 0
	high = len(arr) - 1
	while low < high:
		k = (low + high) // 2
		if n > arr[k]:
			low = k + 1
		else:
			high = k - 1
	k = (low + high) // 2
	if arr[min(k + 1, len(arr) - 1)] <= n:
		return k + 1
	elif arr[k] <= n:
		return k
	elif arr[max(0, k - 1)] <= n:
		return k - 1
	else:
		return -1
t = int(input())
for _ in range(t):
	E = 0
	n = int(input())
	while True:
		k = lower_bound(d, n)
		if k != -1:
			n -= d[k]
			E += 1
		else:
			break
	print(E)


import bisect
dp = [2, 7]
i = 3
while dp[-1] < 10 ** 9:
	h = dp[-1] + 2 * i + i - 1
	dp.append(h)
	i += 1
t = int(input())
for _ in range(t):
	n = int(input())
	idx = 10 ** 9
	ans = 0
	while idx > 0:
		idx = bisect.bisect_right(dp, n)
		if dp[idx - 1] == n:
			ans += 1
			break
		else:
			ans += n // dp[idx - 1]
			n = n % dp[idx - 1]
	print(ans)


t = int(input())
for i in range(0, t):
	cantidad = int(input())
	total = 0
	if cantidad == 1:
		print(0)
	else:
		while cantidad > 1:
			aprox = int((2 / 3 * cantidad) ** 0.5)
			pisos = aprox - 2
			demanda = int(3 * pisos * (pisos + 1) / 2 - pisos)
			while demanda <= cantidad:
				pisos += 1
				demanda = int(3 * pisos * (pisos + 1) / 2 - pisos)
			pisos -= 1
			demanda = int(3 * pisos * (pisos + 1) / 2 - pisos)
			cantidad -= demanda
			total += 1
		print(total)


from bisect import bisect_left
t = int(input())
cards_required = []
for i in range(1, 100000):
	value = i * (3 * i + 1) // 2
	cards_required.append(value)
	if value > 1000000000:
		breaking_point = i
		break
for _ in range(t):
	value = int(input())
	ans = 0
	while value > 0:
		index = bisect_left(cards_required[1:], value)
		if cards_required[index + 1] == value:
			index += 1
		if cards_required[index] > value:
			break
		no_of_pyramids = value // cards_required[index]
		value -= no_of_pyramids * cards_required[index]
		ans += no_of_pyramids
	print(ans)


for _ in range(int(input())):
	n = int(input())
	sol = 0
	while n >= 2:
		k = (-1 + (1 + 24 * n) ** (1 / 2)) // 6
		ans = (3 * k ** 2 + k) // 2
		sol += 1
		n = n - ans
	print(sol)


import bisect
t = int(input())
a = [n * (n + 1) // 2 * 3 - n for n in range(1, 10 ** 5)]
for _ in range(t):
	n = int(input())
	count = 0
	while n > 1:
		best = a[bisect.bisect_right(a, n) - 1]
		count += n // best
		n %= best
	print(count)


t = int(input())

def car(h):
	z = 3 * h * (h + 1) // 2 - h
	return z
for xx in range(t):
	cd = int(input())
	pil = 0
	xr = cd
	while xr > 1:
		xd = 0
		for i in range(1, xr + 1):
			if car(i) > xr:
				xd = car(i - 1)
				break
		xr -= xd
		if xr <= 1:
			pil += 1
			break
		pil += 1
	print(pil)


t = int(input())
pyramids = [2]
cards = 2
h = 2
while cards < 1000000000.0:
	cards = 3 * h - 1 + pyramids[h - 2]
	pyramids.append(cards)
	h += 1
for case in range(t):
	n = int(input())
	count = 0
	while n > 1:
		tallest = 0
		for i in range(len(pyramids)):
			if n >= pyramids[i]:
				tallest = pyramids[i]
			else:
				break
		while n - tallest >= 0:
			count += 1
			n -= tallest
	print(count)


def main():
	now = 2
	i = 2
	total = [now]
	while now <= 10 ** 9:
		now = 2 * i + i - 1 + now
		total.append(now)
		i += 1
	ans = 0
	total = total[::-1]
	t = int(input())
	for i in range(t):
		n = int(input())
		ans = 0
		for elem in total:
			if n == 0:
				break
			ans += n // elem
			n = n % elem
		print(ans)
main()


import math
t = int(input())
for i in range(t):
	a = int(input())
	x = math.sqrt(1 + 24 * a)
	x = x - 1
	x = x / 6
	x = int(x)
	count = 0
	while a > 1 and x > 0:
		z = (3 * x * x + x) // 2
		d = a // z
		count += d
		a = a - z * d
		x -= 1
	print(count)


def f(x):
	return x * 2 + x * (x - 1) // 2 * 3

def search(table, n):
	r = int(n ** (1 / 2)) + 1
	if n < 2:
		return 0
	else:
		for i in range(r, -1, -1):
			if n // table[i] >= 1:
				break
		return n // table[i] + search(table, n % table[i])
t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	r = int(n ** (1 / 2)) + 1
	table = [0] * (r + 1)
	for i in range(1, r + 1):
		table[i] = f(i)
	print(search(table, n))


import bisect
l = [0]
i = 1
while l[i - 1] < 10 ** 9:
	if i == 1:
		l.append(2)
	else:
		l.append(l[i - 1] + i - 1 + l[1] * i)
	i = i + 1
t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n > 1:
		j = bisect.bisect_right(l, n)
		c = c + 1
		n = n - l[j - 1]
	print(c)


t = int(input())
for _ in range(t):
	n = int(input())
	p = 0
	while n > 1:
		p += 1
		prev = 0
		for h in range(1, n):
			c = h * (h + 1) + (h - 1) * h // 2
			if c == n:
				n -= c
				break
			elif c > n:
				n -= prev
				break
			else:
				prev = c
	print(p)


import math as m

def func(a):
	return int((m.sqrt(24 * a + 1) - 1) // 6)
t = int(input())
for _ in range(t):
	n = int(input())
	c = 0
	while n > 1:
		a = func(n)
		n = n - (3 * a * a + a) // 2
		c = c + 1
	print(c)


T = int(input())
for i in range(T):
	n = int(input())
	ans = 0
	while True:
		if n < 2:
			break
		t = (-1 + pow(1 + 24 * n, 0.5)) / 6
		t = int(t)
		n -= int((3 * t + 1) * t) / 2
		ans += 1
	print(ans)


import math
for _ in range(int(input())):
	x = int(input())
	c = 0
	while x >= 2:
		y = (math.sqrt(1 + 24 * x) - 1) // 6
		if y >= 1:
			c += 1
		else:
			break
		x = x - y * (y + 1) - y * (y - 1) / 2
	print(c)


t = int(input())
import math
for i in range(t):
	n = int(input())
	ans = 0
	v = math.ceil(((1 + 24 * n) ** 0.5 - 1) / 6)
	for j in range(v, -1, -1):
		if j == 0:
			break
		d = 2 * j + 3 / 2 * j * (j - 1)
		d = int(d)
		if d <= n:
			c = n // d
			n -= d * c
			ans += c
	print(ans)


for _ in range(int(input())):
	n = int(input())
	res = 0
	while n > 1:
		x = 1
		while x * (3 * x + 1) / 2 <= n:
			x += 1
		if x == 1:
			break
		elif x > 1:
			x -= 1
		n -= x * (3 * x + 1) / 2
		res += 1
	print(res)


import bisect
n_test = int(input())
li = [i * (i - 1) // 2 * 3 + i * 2 for i in range(1, 100000)]

def total(num):
	if num < 2:
		return 0
	mx = li[bisect.bisect_right(li, num) - 1]
	return total(num - mx) + 1
for _ in range(n_test):
	n = int(input())
	print(total(n))


import sys
import os
import heapq
import math
try:
	path = './file/input.txt'
	if os.path.exists(path):
		sys.stdin = open(path, 'r')
except:
	pass
t = int(input())

def printd(value):
	pass
index = 0
pre = [0] * 300000

def case():
	n = int(input())
	result = 0
	while n >= 2:
		left = 1
		global index
		right = index
		while left < right:
			middle = int((left + right) / 2)
			if pre[middle] > n:
				right = middle - 1
			else:
				left = middle + 1
		left -= 2
		left = max(0, left)
		for i in range(left, left + 5):
			if pre[i] <= n and pre[i + 1] > n or i == left + 4:
				result += 1
				n -= pre[i]
				break
	print(result)
last = 1
sum = 0
index = 1
while sum < 10 ** 9:
	last = index * 2 + index - 1
	sum += last
	pre[index] = sum
	index += 1
index -= 1
for _ in range(t):
	case()


t = int(input())
pop = []
for i in range(t):
	n1 = int(input())
	n = 1
	q2 = 2
	a1 = n1
	count = 0
	while a1 > 1:
		q3 = 3 / 2 * (n * (n + 1))
		q3 = int(q3)
		q1 = q3 - n
		if q1 > a1:
			a1 = a1 - q2
			n = 1
			count = count + 1
		else:
			n = n + 1
		if n == 1:
			q2 = 2
		else:
			q2 = q1
	pop.append(count)
for i in pop:
	print(i)


def S(h):
	return (h - 1) * ((3 * h + 4) / 2) + 2
arr = [None] + [int(S(i)) for i in range(1, 10 ** 5)]

def func(n, l, r):
	if n <= 0:
		return 0
	elif n == 1:
		return 0
	else:
		while l <= r:
			mid = (l + r) // 2
			if arr[mid] <= n:
				l = mid
			elif arr[mid] > n:
				r = mid
			if r - l <= 1:
				if arr[r] <= n:
					return 1 + func(n - arr[r], 1, 10 ** 5)
					break
				else:
					return 1 + func(n - arr[l], 1, 10 ** 5)
					break
t = int(input())
for _ in range(t):
	n = int(input())
	l = 1
	r = 10 ** 5
	print(func(n, l, r))


import sys
import math
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for i in range(t):
	n = inp()
	ct = 0
	sum = n
	while sum > 1:
		i = 0
		while 3 * i * (i + 1) // 2 - i <= sum:
			i = i + 1
		i = i - 1
		ct = ct + 1
		sum = sum - (3 * i * (i + 1) // 2 - i)
	print(ct)


import time

def getCards(h):
	return int((h + 1) * h + h * (h - 1) / 2)

def getMaxH(N):
	if N >= 2:
		h = 1
		count = 1
		diff = N - getCards(h)
		while diff > 0:
			h += 1
			diff = N - getCards(h)
		if diff < 0:
			return h - 1
		else:
			return h
	else:
		return 0
T = int(input())
while T > 0:
	N = int(input())
	count = 0
	if N >= 2:
		while N > 1:
			N -= getCards(getMaxH(N))
			count += 1
		print(count)
	else:
		print(0)
	T -= 1


exec(int(input()) * 'x,c=int(input()),0;\nwhile x>1:n=int(((1+24*x)**0.5 -1)/6);x-=n*(3*n+1)//2;c+=1\nprint(c);')


t = int(input())
c = 0

def solving(n):
	global c
	if n - 2 < 0:
		return
	c += 1
	f_n = n
	n = n - 2
	N = 2
	p = 0
	stairs = 0
	while n >= 2 + N + stairs + 1:
		p += 1
		stairs += 1
		N += 2
		n -= N + stairs
	if n < 2:
		return
	else:
		solving(n)
for _ in range(t):
	n = int(input())
	solving(n)
	print(c)
	c = 0


for u in range(int(input())):
	x = int(input())
	z = 0
	n = 1
	l = []
	while z < x:
		z = 3 * n * (n + 1) // 2 - n
		l.append(z)
		n += 1
	ans = 0
	y = l[::-1]
	if x // y[0] == 0:
		for i in range(1, len(y)):
			ans += x // y[i]
			x = x % y[i]
	else:
		for i in range(len(l)):
			ans += x // y[i]
			x = x % y[i]
	print(ans)


import math
t = int(input())
while t:
	n = int(input())
	s = 2
	b = 0
	total = 0
	tmp = n
	while tmp >= 2:
		if tmp >= s + b:
			tmp = tmp - s - b
			s = s + 2
			b = b + 1
			if tmp < 2:
				total = total + 1
		else:
			total = total + 1
			s = 2
			b = 0
	print(total)
	t = t - 1


Times = int(input())
j = 0

def f(n):
	i = 1
	while True:
		if n < (3 * i ** 2 + i) // 2:
			return i - 1
		i += 1
while j < Times:
	n = int(input())
	s = 0
	while f(n) > 0:
		n -= (3 * f(n) ** 2 + f(n)) // 2
		s += 1
	print(s)
	j += 1


for _ in range(int(input())):
	n = int(input())
	a = 0
	while n > 1:
		a += 1
		c = 2
		while n >= c:
			n -= c
			c += 3
	print(a)


import sys
from math import sqrt
cin = sys.stdin.buffer.readline

def fn(n):
	sq = int(sqrt(n))
	tm = sq * (3 * sq + 1) // 2
	while tm < n:
		sq += 1
		tm = sq * (3 * sq + 1) // 2
	while tm > n:
		sq -= 1
		tm = sq * (3 * sq + 1) // 2
	return tm
for _ in range(int(cin())):
	n = int(cin())
	ans = 0
	while n != 0 or n != 1:
		tmp = fn(n)
		if tmp >= 2 and n >= tmp:
			ans += 1
			n -= tmp
		else:
			break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	ans = 0
	i = 1
	while n > 1:
		b = i * (i + 1) / 2
		cd = b * 2 + i * (i - 1) / 2
		if int(n / cd) < 1:
			ans += 1
			i -= 1
			b = i * (i + 1) / 2
			cd = b * 2 + i * (i - 1) / 2
			i = 1
			n -= cd
		else:
			i += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	count = 0
	while n >= 2:
		next_l = 1
		next_add = 2
		while n - next_add >= 0:
			n -= next_add
			next_add = next_l + 2 * (next_l + 1)
			next_l += 1
		count += 1
	print(count)


def task(n, table):
	builds = 0
	while n > 1:
		for i in range(1, len(table)):
			if table[i] > n:
				builds += 1
				n -= table[i - 1]
				break
	print(builds)
table = [0]
triangles = 0
rows = 0
for i in range(1, 30001):
	triangles += i
	rows += i - 1
	total = triangles * 2 + rows
	table.append(total)
t = int(input())
for i in range(0, t):
	n = int(input())
	task(n, table)


def ans(n):
	x = 0
	ele = 0
	A = []
	while ele <= n:
		x += 1
		ele += x
		A.append(ele)
	B = [2]
	i = 1
	while B[-1] <= n:
		z = 2 * A[i] + A[i - 1]
		i += 1
		B.append(z)
	if B[-1] == n:
		return 1
	del B[-1]
	index = len(B) - 1
	count = 0
	while n > 1 and index >= 0:
		if n >= B[index]:
			n -= B[index]
			count += 1
		else:
			index -= 1
	return count
t = int(input())
for i in range(t):
	q = int(input())
	print(ans(q))


t = int(input())
for _ in range(t):
	num_pyramids = 0
	n = int(input())
	while n >= 2:
		num_pyramids += 1
		inc = 2
		while n >= inc:
			n -= inc
			inc += 3
	print(num_pyramids)


import sys
input = sys.stdin.readline
t = int(input())

def bs(l, h, n):
	if l <= h:
		m = (l + h) // 2
		temp = 2 * m + 3 * (m - 1) * m / 2
		if temp <= n:
			m1 = m + 1
			temp2 = 2 * m1 + 3 * (m1 - 1) * m1 / 2
			if temp2 <= n:
				return bs(m + 1, h, n)
			else:
				return m
		else:
			return bs(l, m - 1, n)
	return 0
for t1 in range(t):
	n = int(input())
	l = 0
	h = n
	c = 0
	while n > 0:
		h1 = bs(l, h, n)
		if h1 == 0:
			break
		else:
			temp = 2 * h1 + 3 * (h1 - 1) * h1 / 2
			n -= temp
			c += 1
	print(c)


def pyramid(given):
	mylis = []
	n = 1
	formula = n * (n + 1)
	while formula <= given:
		formula = n * (n + 1) + n * (n - 1) // 2
		n += 1
		mylis.append(formula)
	return mylis
for _ in range(int(input())):
	given = int(input())
	count = 0
	lis = pyramid(given)[::-1]
	for i in lis:
		if given >= i:
			a = given // i
			given -= a * i
			count += a
		elif given < 2:
			break
	print(count)


def pyramidcount(n):
	count = 0
	while n > 1:
		k = 1
		while (k + 1) * (3 * k + 4) // 2 <= n:
			k += 1
		n -= k * (3 * k + 1) // 2
		count += 1
	return count
numberofcases = int(input())
for _ in range(numberofcases):
	print(pyramidcount(int(input())))


p = [2]
k = 2
while p[-1] < 1000000000:
	p.append(p[-1] + k * 3 - 1)
	k += 1
t = int(input())
for _ in range(t):
	n = int(input())
	s = 0
	while True:
		l = 0
		r = len(p)
		while r - l > 1:
			m = (l + r) // 2
			if p[m] > n:
				r = m
			else:
				l = m
		if p[l] <= n:
			n -= p[l]
			s += 1
		else:
			break
	print(s)


def solve(n):
	c = 0
	while n > 1:
		for i in range(1, int(n) + 1):
			if n < 2 * i + (i - 1) / 2 * (6 + (i - 2) * 3):
				c += 1
				n = n - (2 * (i - 1) + (i - 2) / 2 * (6 + (i - 3) * 3))
				break
	return c
t = int(input())
for _ in range(t):
	a = int(input())
	print(solve(a))


def p(n):
	return (3 * n * n + n) // 2
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		L = 0
		R = n // 2 + 1
		while R - L > 1:
			M = (L + R) // 2
			if p(M) <= n:
				L = M
			else:
				R = M
		ans += 1
		n -= p(L)
	print(ans)


import sys
import math

def main():
	input_list = get_input()
	for line in input_list[1:]:
		print(func(int(line)))

def get_input():
	input_list = []
	for line in sys.stdin:
		input_list.append(line.rstrip('\n'))
	return input_list

def func(num):
	card_left = num
	pyramid_num = 0
	while card_left >= 2:
		i = 1
		while req_cards(i + 1) <= card_left:
			i += 1
		card_left -= req_cards(i)
		pyramid_num += 1
	return pyramid_num

def req_cards(side_num):
	return int((3 * side_num ** 2 + side_num) / 2)
main()


import bisect
t = int(input())
need = [2]
(now, cnt) = (2, 5)
while now <= 10 ** 9:
	now += cnt
	need.append(now)
	cnt += 3
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		div = need[bisect.bisect_left(need, n) - 1]
		if n == need[bisect.bisect_left(need, n)]:
			ans += 1
			break
		else:
			ans += n // div
			n = n % div
	print(ans)


import bisect
size = [2, 2]
for i in range(2, 30000):
	size_curr = size[i - 1] + (3 * i - 1)
	size.append(size_curr)
for t in range(int(input())):
	n = int(input())
	count = 0
	arr = size.copy()
	while n > 1:
		index = bisect.bisect_right(arr, n)
		n -= arr[index - 1]
		count += 1
		arr = arr[:index]
	print(count)


t = int(input())

def getLevelCost(n):
	return n - 1 + n * 2

def getMaxValLowerThan(dp, val):
	l = 0
	r = len(dp) - 1
	while l < r:
		m = (l + r + 1) // 2
		if dp[m] == val:
			return val
		if dp[m] < val:
			l = m
		else:
			r = m - 1
	return dp[l]
myMax = 15
number = 27000
dp = [0] * number
for i in range(number):
	prev = 0 if i < 1 else dp[i - 1]
	dp[i] = prev + getLevelCost(i + 1)
for i in range(t):
	val = int(input())
	counter = 0
	while val > 1:
		g = getMaxValLowerThan(dp, val)
		val -= g
		counter += 1
	print(counter)


t = int(input())
for _ in range(t):
	n = int(input())
	if n == 1:
		print(0)
	elif n == 2 or n == 3:
		print(1)
	elif n == 4 or n == 5:
		print(2)
	elif n == 6:
		print(3)
	else:
		num2 = n
		c = 0
		while num2 >= 7:
			num = 2
			i = 2
			while num <= num2:
				num1 = i * 2 + (i - 1)
				num = num + num1
				i = i + 1
			num = num - num1
			num2 = num2 - num
			c = c + 1
		if num2 == 6:
			c = c + 3
		elif num2 == 5 or num2 == 4:
			c = c + 2
		elif num2 == 3 or num2 == 2:
			c = c + 1
		print(c)


for _ in range(int(input())):
	n = int(input())
	count = 0
	while n > 1:
		min = 2
		t = 5
		while n >= min:
			n -= min
			min = t
			t += 3
		count += 1
	print(count)


import math

def fun(n):
	k = (math.sqrt(1 + 24 * n) - 1) / 6
	return int(k)
t = int(input())
for i in range(0, t):
	n = int(input())
	s = 0
	while n >= 2:
		k = fun(n)
		n = int(n - 3 * k * k / 2 - k / 2)
		s += 1
	print(s)


global n

def compute(n):
	total_pyramid = 0
	while n > 1:
		card = 2
		h = 1
		while n - (card + 3 * h + 2) >= 0:
			card = card + 3 * h + 2
			h += 1
		n -= card
		total_pyramid += 1
	return total_pyramid
t = int(input())
for _ in range(t):
	n = int(input())
	print(compute(n))


def get(n):
	return n * (3 * n + 1) // 2
arr = []
i = 1
x = 0
while True:
	x = get(i)
	if x > 1000000000:
		break
	arr.append(x)
	i += 1
arr.reverse()
for test in range(int(input())):
	n = int(input())
	ans = 0
	for i in arr:
		if n >= i:
			ans += n // i
			n -= n // i * i
	print(ans)


dp = [[999999999999] * 100 for i in range(100)]
from functools import lru_cache
import sys
from math import log10, ceil
sys.setrecursionlimit(1000)

@lru_cache(maxsize=None)
def solve(g):
	if g == 1:
		return 2
	return solve(g - 1) + 3 * g - 1
import time
for i in range(1, 70000):
	solve(i)
t = int(input())
for i in range(t):
	n = int(input())
	start = time.time()
	done = 0
	while n > 1:
		low = 0
		high = 70001
		while low < high:
			mid = low + ceil((high - low) / 2)
			if solve(mid) <= n:
				low = mid
			else:
				high = mid - 1
		n -= solve(low)
		done += 1
	print(done)


x = int(input())

def pyramid(n):
	if n > 1:
		i = 1
		while i * (i + 1) + i * (i - 1) / 2 <= n:
			i += 1
		i -= 1
	return n - i * (i + 1) - i * (i - 1) / 2
for i in range(x):
	n = int(input())
	count = 0
	while n > 1:
		k = pyramid(n)
		count += 1
		n = k
	print(count)


a = []
for i in range(1, 10 ** 6):
	t = i * (3 * i + 1)
	y = t // 2
	if y > 10 ** 9:
		break
	a.append(y)
d = len(a)

def binarySearchCount(arr, n, key):
	left = 0
	right = n
	mid = 0
	while left < right:
		mid = (right + left) // 2
		if arr[mid] == key:
			while mid + 1 < n and arr[mid + 1] == key:
				mid += 1
			break
		elif arr[mid] > key:
			right = mid
		else:
			left = mid + 1
	while mid > -1 and arr[mid] > key:
		mid -= 1
	return mid + 1
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		z = a[binarySearchCount(a, d, n) - 1]
		n -= z
		ans += 1
	print(ans)


t = int(input())
while t > 0:
	x = -1
	sum = 0
	y = 0
	a = int(input())
	while a >= 2:
		while sum <= a:
			x = x + 3
			sum = sum + x
		sum = sum - x
		a = a - sum
		y = y + 1
		x = -1
		sum = 0
	t = t - 1
	print(y)


def getN():
	return int(input())

def getNM():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))
from collections import defaultdict, deque
from sys import exit
import math
import copy
from bisect import bisect_right
import sys

def solve(pyr):
	k = getN()
	ans = 0
	while k > 1:
		idx = bisect_right(pyr, k)
		ans += 1
		k -= pyr[idx - 1]
	print(ans)
	return

def main():
	N = getN()
	pyr = [n * (n + 1) // 2 * 3 - n for n in range(100000)]
	for _ in range(N):
		solve(pyr)
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
from bisect import bisect_left as bl
z = 10 ** 5
a = []
for i in range(1, z):
	a.append(i * (3 * i + 1) // 2)
for _ in range(I()[0]):
	(n,) = I()
	ans = 0
	while n > 1:
		ind = bl(a, n)
		if a[ind] == n:
			n -= a[ind]
		else:
			n -= a[ind - 1]
		ans += 1
	print(ans)


import math
t = int(input())
for i in range(t):
	p = int(input())
	q = 0
	c = 0
	while True:
		q = math.sqrt(24 * p + 1) - 1
		if q % 6 == 0:
			c += 1
			break
		else:
			q = math.floor(q / 6)
			if q == 0:
				break
			else:
				c += 1
				p -= q * (3 * q + 1) // 2
	print(c)


from math import floor

def func(n, heaps, counter=0):
	if n < heaps[0]:
		return counter
	elif n == heaps[0]:
		return counter + 1
	i = 0
	while i < len(heaps) and n >= heaps[i]:
		i += 1
	counter += 1
	n -= heaps[i - 1]
	return func(n, heaps, counter) if n >= heaps[0] else counter

def main():
	k = int(input())
	for q in range(k):
		n = int(input())
		heaps = [0] * (floor(n ** (1 / 2)) + 1)
		heaps[0] = 2
		for i in range(2, floor(n ** (1 / 2)) + 2):
			heaps[i - 1] = heaps[i - 2] + 3 * i - 1
		print(func(n, heaps))
main()


def maxpyramide(n):
	h = 0
	condition = True
	while condition:
		h += 1
		if n < (3 * h * (h + 1) - 2 * h) // 2:
			condition = False
	return (3 * (h - 1) * h - 2 * (h - 1)) // 2
t = int(input())
for i in range(t):
	n = int(input())
	compte = 0
	while n > 1:
		n -= maxpyramide(n)
		compte += 1
	print(compte)


count = int(input())
for i in range(count):
	n = int(input())
	step = 0
	while n > 1:
		h = (-1 + pow(1 + 24 * n, 0.5)) / 6 // 1
		n -= 2 * h + 3 * h * (h - 1) / 2
		step += 1
	print(step)


for i in range(int(input())):
	n = int(input())
	count = 0
	while n > 1:
		h = 1
		while h * (3 * h + 1) / 2 <= n:
			h = h + 1
		n = n - (h - 1) * (3 * (h - 1) + 1) / 2
		count += 1
	print(count)


t = int(input())
while t:
	t += -1
	n = int(input())
	if n == 1:
		print(0)
		continue
	ans = 0
	while 1:
		for i in range(1, 100001):
			if 3 * (i * (i - 1) // 2) + 2 * i > n:
				ans -= -1
				tmp = i - 1
				n -= 3 * (tmp * (tmp - 1) // 2) + 2 * tmp
				break
		if n <= 1:
			break
	print(ans)


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
import bisect as bi
import heapq

def I():
	return int(input())

def In():
	return map(int, input().split())

def find_le(a, x):
	i = bi.bisect_right(a, x)
	if i:
		return a[i - 1]
	else:
		return -1

def qua(a, b, c):
	d = b ** 2 - 4 * a * c
	sol1 = (-b - math.sqrt(d)) / (2 * a)
	sol2 = (-b + math.sqrt(d)) / (2 * a)
	return max(sol1, sol2)

def main():
	try:
		n = I()
		ans = 0
		t = 5
		while n >= 2:
			a = int(qua(3, 1, -(2 * n)))
			n -= (3 * a ** 2 + a) // 2
			ans += 1
		print(ans)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


from sys import stdin, stdout
import bisect as bs

def fn(n):
	sm = n * (n + 1) >> 1
	return 3 * sm - n
a = []
p = 2
lim = 10 ** 10 + 9
pos = 1
while p <= lim:
	a += [p]
	pos += 1
	p = fn(pos)
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	ans = 0
	while n > 0:
		pos = bs.bisect_left(a, n)
		if a[pos] != n:
			pos -= 1
		n -= a[pos]
		if n < 0:
			break
		ans += 1
	print(ans)


t = int(input())
i = 0
while i < t:
	n = int(input())
	add = 0
	if n == 0 or n == 1:
		add = 0
	else:
		while True:
			h = 0
			while True:
				eq = 2 + 3 * h + (3 * h * h + h) // 2
				if eq >= n:
					if eq > n:
						h = h - 1
						eq = 2 + 3 * h + (3 * h * h + h) // 2
					break
				h += 1
			n = n - eq
			add += 1
			if n <= 1:
				break
	print(add)
	i += 1


def upper_bound(n: int):
	low = 0
	high = 10 ** 9
	while low < high:
		mid = low + high >> 1
		c = mid * (mid + 1) + mid * (mid - 1) // 2
		if n >= c:
			low = mid + 1
		else:
			high = mid
	return low - 1

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		count = 0
		while True:
			c = upper_bound(n)
			if c == 0:
				break
			count += 1
			n -= c * (c + 1) + c * (c - 1) // 2
		print(count)
main()


t = int(input())
i = 0
while i < t:
	n = int(input())
	count = 0
	while True:
		j = 2
		res = 2
		z = True
		prev = res
		while res <= n:
			prev = res
			res = res + 2 * j + (j - 1)
			j = j + 1
			z = False
		if z == False:
			count = count + 1
			n = n - prev
		if z == True:
			break
	print(count)
	i = i + 1


import bisect
seq = [i * (3 * i + 1) // 2 for i in range(30000)]

def solve():
	n = int(input())
	cnt = 0
	while n > 1:
		p = bisect.bisect_left(seq, n + 1) - 1
		n -= seq[p]
		cnt += 1
	return cnt
tests = int(input())
for _ in range(tests):
	print(solve())


n = int(input())
potenciales = {}
numero_cartas_para_piramide = 2
sumado = 5
for i in range(0, 90010):
	potenciales[numero_cartas_para_piramide] = True
	numero_cartas_para_piramide += sumado
	sumado += 3
lista = list(potenciales)
cards = []
for i in range(0, n):
	card = int(input())
	cards.append(card)

def buscar_maximo(numero):
	resto = 0
	value_anterior = 0
	u = find_index(lista, len(lista), numero)
	resto = numero - lista[u]
	if lista[u] == 0:
		return (0, False)
	else:
		return (resto, True)

def find_index(arr, n, K):
	start = 0
	end = n - 1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] == K:
			return mid
		elif arr[mid] < K:
			start = mid + 1
		else:
			end = mid - 1
	return end
for card in cards:
	suma = 0
	resto = card
	while resto > 1:
		(resto, encontrado) = buscar_maximo(resto)
		if encontrado:
			suma += 1
	print(suma)


import bisect
import os
import sys
from io import BytesIO, IOBase
Cards = [0] * 31623
for i in range(1, len(Cards)):
	Cards[i] = i * (i + 1) + i * (i - 1) // 2

def main():
	T = int(input())
	for _ in range(T):
		ans = 0
		n = int(input())
		while True:
			pos = bisect.bisect_right(Cards, n)
			if Cards[pos] != n:
				pos -= 1
			if pos == 0:
				break
			ans += 1
			n -= Cards[pos]
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = lambda s: self.buffer.write(s.encode()) if self.writable else None

	def read(self):
		if self.buffer.tell():
			return self.buffer.read().decode('ascii')
		return os.read(self._fd, os.fstat(self._fd).st_size).decode('ascii')

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline().decode('ascii')

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

def print(*args, sep=' ', end='\n', file=sys.stdout, flush=False):
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(end)
	if flush:
		file.flush()
(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(10000)
main()


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys

def solve(k):
	return (-1 + sqrt(1 + 24 * k)) // 6
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while True:
		z = solve(n)
		n -= (3 * z ** 2 + z) // 2
		if z == 0:
			break
		else:
			ans += 1
	print(ans)


from math import floor
from math import sqrt
t = int(input())
for i in range(t):
	n = int(input())
	i = 0
	while n >= 2:
		i = i + 1
		v = floor((-0.5 + sqrt(0.25 + 6 * n)) / 3.0)
		n = n - (1.5 * v ** 2 + 0.5 * v)
	print(i)


from collections import defaultdict
a = [2]
freq = defaultdict(lambda : 0)
add = 5
i = 1
freq[a[0]] = 1
while True:
	val = a[i - 1] + add
	freq[val] = 1
	add += 3
	a.append(val)
	i += 1
	if val > 1000000000:
		break

def binsearch(a, x):
	low = 0
	high = len(a) - 1
	while low <= high:
		mid = low + (high - low + 1) // 2
		if a[mid] == x:
			high = mid - 1
		elif a[mid] > x:
			high = mid - 1
		elif a[mid] < x:
			ind = mid
			low = mid + 1
	return ind
t = input()
for _ in range(int(t)):
	n = int(input())
	if n == 1:
		ans = 0
	elif n == 2:
		ans = 1
	else:
		key = n
		ans = 0
		while True:
			if key == 1:
				break
			if freq[key] == 1:
				ans += 1
				break
			index = binsearch(a, key)
			ans += 1
			key = key - a[index]
	print(ans)


def solve(a):
	n = 1
	count = 0
	while a > 1:
		while (n + n * 3 * n) / 2 < a:
			n += 1
		if (n + n * 3 * n) // 2 == a:
			a = a - (n + n * 3 * n) / 2
		else:
			a = a - (n - 1 + (n - 1) * 3 * (n - 1)) / 2
		count += 1
		n = 1
	return count
t = int(input())
for _ in range(t):
	a = int(input())
	print(solve(a))


import math
testCases = int(input())
for i in range(0, testCases):
	givenStick = float(input())
	yourTower = 0
	while 1:
		towerFloor = int(math.sqrt(givenStick * 2 / 3 + 1 / 36) - 1 / 6 + 1e-07)
		usedStick = towerFloor * (3 * towerFloor + 1) / 2
		leftStick = givenStick - usedStick
		givenStick = leftStick
		if towerFloor > 0:
			yourTower += 1
		else:
			break
	print(yourTower)


t = int(input())
for q in range(0, t):
	n = int(input())
	number = 0
	while n > 1:
		left = 1
		right = n
		while right - left > 1:
			m = (right + left) // 2
			if 3 * m * (m + 1) // 2 - m > n:
				right = m
			else:
				left = m
		n -= 3 * left * (left + 1) // 2 - left
		number += 1
	print(number)


def find_cards(x):
	return x * (x + 1) + int(x * (x - 1) / 2)
for t in range(int(input())):
	n = int(input())
	count = 0
	while n > 1:
		max_x = 32000
		x = 16000
		cards = find_cards(x)
		_cards = find_cards(x + 1)
		while not (cards < n and _cards > n):
			if cards > n:
				temp = x
				x = int(x / 2)
				max_x = temp
			elif cards < n:
				x = int((x + max_x) / 2)
			elif cards == n:
				break
			cards = find_cards(x)
			_cards = find_cards(x + 1)
		n -= cards
		count += 1
	print(count)


mxn = 100000
dp = [0] * mxn
dp[0] = 2
for i in range(1, mxn):
	dp[i] = dp[i - 1] + i + 2 * (i + 1)
import bisect
for ii in range(int(input())):
	n = int(input())
	count = 0
	while n >= 0:
		ind = bisect.bisect(dp, n)
		n -= dp[ind - 1]
		count += 1
	print(count - 1)


import sys

class BCardConstructions:

	def solve(self, tc=0):

		def highest(n):
			return int(((24 * n + 1) ** 0.5 - 1) / 6)
		for _ in range(int(input())):
			n = int(input())
			ans = 0
			while n >= 2:
				h = highest(n)
				n -= h * (h + 1) + h * (h - 1) // 2
				ans += 1
			print(ans)
solver = BCardConstructions()
input = sys.stdin.readline
solver.solve()


from math import sqrt
for j in range(int(input())):
	a = int(input())
	rem = a % 3
	tri = a // 3
	total = 0
	while tri > 0:
		total += 1
		ans = int(sqrt(2 * tri))
		(x, y) = (ans + 1, ans)
		while x * y > 2 * tri:
			(x, y) = (x - 1, y - 1)
		p = (tri - y * (y + 1) // 2) * 3 + rem
		if p >= 2 * (y + 1):
			while p >= (y + 1) * 2:
				p = p - 2 * (y + 1)
				y += 1
		else:
			p += y
		tri = p // 3
		rem = p % 3
	if rem == 2:
		total += 1
	print(total)


def f(x):
	p = int((1 + 24 * x) ** 0.5)
	p -= 1
	p //= 6
	v = 2 * p + p * (p - 1) // 2 * 3
	return v
import sys

def sol():
	x = int(input())
	res = 0
	while x >= 2:
		x -= f(x)
		res += 1
	print(res)
for n in range(int(input())):
	sol()


import bisect
list = []
for i in range(1, 10 ** 5):
	list.append((3 * i ** 2 + i) // 2)
for _ in range(int(input())):
	n = int(input())
	count = 0
	while n >= 2:
		r = bisect.bisect_right(list, n)
		n -= list[r - 1]
		count += 1
	print(count)


def need_m(m):
	if m == 1:
		return 2
	if m == 2:
		return 7
	return 2 * m + (m - 1) * m * 3 // 2

def algo(n):
	result = 0
	while n >= 2:
		i = 1
		while True:
			(a, b) = (need_m(i), need_m(i + 1))
			if a <= n < b:
				result += 1
				n -= a
				break
			i += 1
	return result
c = int(input())
for _ in range(c):
	n = int(input())
	print(algo(n))


t = int(input())

def pyr(a):
	c = 0
	while a > 1:
		n = int((-1 + pow(1 + 24 * a, 0.5)) / 6)
		c += 1
		a = a - (3 * pow(n, 2) + n) / 2
	return c
for i in range(t):
	x = int(input())
	print(pyr(x))


final_out = []

def no_of_cards(n):
	return int(n * (3 * n + 1) / 2)

def check_for_kth(k):
	n = 1
	while True:
		if k / no_of_cards(n) < 1:
			return no_of_cards(n - 1)
		else:
			n = n + 1

def solve(k):
	global final_out
	s = check_for_kth(k)
	final_out.append(s)
	k = k - s
	if k == 0 or k == 1:
		return 0
	else:
		solve(k)
t = int(input())
answer = []
for i in range(t):
	final_out = []
	k = int(input())
	if k == 1 or k == 0:
		final_out.append(0)
	else:
		m = solve(k)
	final_out.sort()
	total = 0
	if final_out[0] == 0:
		answer.append(0)
	else:
		i = 0
		while i < len(final_out):
			total = total + final_out.count(final_out[i])
			i = i + final_out.count(final_out[i])
		answer.append(total)
for s in answer:
	print(s)


def get_number(h):
	return int(h * (3 * h + 1) / 2)
items = []
k = 0
item = get_number(k)
while item < 10 ** 9:
	k += 1
	item = get_number(k)
	items.append(item)

def solve(n):
	k = 0
	ost = 10 ** 10
	while ost >= 1:
		i = 0
		curr_item = items[i]
		while curr_item <= n:
			i += 1
			curr_item = items[i]
		ost = n - items[i - 1]
		if ost < 0:
			break
		k += 1
		n = n - items[i - 1]
	return k
t = int(input())
for i in range(t):
	n = int(input())
	print(solve(n))


t = int(input())
from math import sqrt
for i in range(t):
	x = int(input())
	cnt = 0
	while x > 0:
		if x == 1:
			break
		k = int((-1 + sqrt(1 + 4 * x)) / 2)
		while k * (k + 1) + k * (k - 1) // 2 > x:
			k -= 1
		x -= k * (k + 1)
		x -= k * (k - 1) // 2
		cnt += 1
	print(cnt)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	if n == 1:
		print(0)
	else:
		e = n
		c = 0
		while e >= 2:
			c += 1
			a = int((-1 + (1 + 24 * e) ** 0.5) // 6)
			f = (3 * a * a + a) // 2
			e -= f
		print(c)


import bisect
t = int(input())
for _ in range(t):
	n = int(input())
	if n < 2:
		print(0)
		continue
	curr = 7
	a = list()
	a.append(2)
	i = 0
	while a[i] <= n:
		a.append(curr)
		i += 1
		curr = 2 * a[i] - a[i - 1] + 3
	n -= a[i - 1]
	count = 1
	while n > 1:
		i = bisect.bisect_left(a, n)
		if a[i] > n:
			n -= a[i - 1]
		else:
			n -= a[i]
		count += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	if n < 2:
		print(0)
	else:
		cards = [2]
		curr = 2
		i = 2
		while curr <= n:
			curr += 2 * i + (i - 1)
			cards.append(curr)
			i += 1
		res = 0
		for i in range(len(cards) - 1, -1, -1):
			res += n // cards[i]
			n = n % cards[i]
		print(res)


import sys
input = sys.stdin.readline

def pyramid(n, l, r):
	if l == r:
		return l
	mid = (l + r + 1) // 2
	if (3 * mid * mid + mid) // 2 > n:
		return pyramid(n, l, mid - 1)
	else:
		return pyramid(n, mid, r)
for _ in range(int(input())):
	n = int(input())
	cnt = 0
	while n >= 2:
		x = pyramid(n, 1, n)
		n -= (3 * x * x + x) // 2
		cnt += 1
	print(cnt)


import bisect
cards = list(map(lambda h: int(3 / 2 * h ** 2 + 1 / 2 * h), [h for h in range(1, 25820)]))
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		idx = bisect.bisect(cards, n)
		n = n - cards[idx - 1]
		ans += 1
	print(ans)


def nivel(n):
	return 2 * n + (n - 1)
tabla = {0: 0}

def cartas(c):
	car = 0
	n = 1
	while car <= c:
		if n not in tabla:
			aux = nivel(n)
			tabla[n] = tabla[n - 1] + aux
		car = tabla[n]
		n += 1
	return tabla[n - 2]
t = int(input())
for _ in range(t):
	restantes = int(input())
	torres = 0
	while restantes > 1:
		restantes -= cartas(restantes)
		torres += 1
	print(torres)


import math

def r():
	return map(int, input().split())

def l():
	return list(map(int, input().split()))

def i():
	return int(input())

def si():
	return input()

def pYes():
	print('YES')

def pNo():
	print('NO')

def plist(l):
	print(''.join(l))
t = i()
dic = {}
for i in range(t):
	a = int(input())
	cnt = 0
	while True:
		d = 24 * a + 1
		sq = (int(math.sqrt(d)) - 1) // 6
		e = sq * (3 * sq + 1) // 2
		if sq == 0:
			break
		if a >= e:
			a = a - e
			cnt += 1
		else:
			break
	print(cnt)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
dp = [2]
cd = 5
while dp[-1] < pow(10, 9):
	dp.append(dp[-1] + cd)
	cd += 3
for _ in range(int(data())):
	n = int(data())
	temp = br(dp, n)
	answer = 0
	while temp >= 0 and n:
		if dp[temp] <= n:
			div = n // dp[temp]
			answer += div
			n -= div * dp[temp]
		temp -= 1
	out(answer)


t = int(input())
for _ in range(t):
	n = int(input())
	h = 1
	while int(3 / 2 * h ** 2 + h / 2) < n:
		h += 1
	total = 0
	for x in range(h, 0, -1):
		dif = int(3 / 2 * x ** 2 + x / 2)
		total += n // dif
		n %= dif
	print(total)


import pdb

def formula(cards_in_house, ebene):
	return cards_in_house + (ebene * 2 + (ebene - 1))

def house(cards, result):
	if cards <= 1:
		return 0
	temp = 0
	ebene = 1
	cards_in_house = 0
	while temp < cards:
		temp = formula(cards_in_house, ebene)
		if cards - temp < formula(temp, ebene + 1) - temp:
			if cards - temp >= 2:
				cards_left = cards - temp
				result = house(cards_left, result) + 1
			else:
				return result + 1
			break
		else:
			ebene += 1
			cards_in_house = temp
	return result
test_cases = int(input())
for i in range(test_cases):
	cards = int(input())
	result = 0
	result = house(cards, result)
	print(result)


import math
T = int(input())
for _ in range(T):
	n = int(input())
	ans = 0
	while 1:
		h = int((math.sqrt(24 * n + 1) - 1) / 6)
		n = n - (3 * h ** 2 + h) // 2
		if h == 0:
			break
		ans += 1
	print(ans)


construct = []
height = 1
while True:
	ans = height * (3 * height + 1) // 2
	if ans > 1000000000:
		construct.append(ans)
		break
	construct.append(ans)
	height += 1
from sys import stdin, stdout
test = int(stdin.readline())
for _ in range(test):
	N = int(stdin.readline())
	cnt = 0
	pyramids = 0
	while True:
		if N <= 1:
			break
		if construct[cnt] == N:
			pyramids += 1
			break
		if construct[cnt] > N:
			pyramids += 1
			N -= construct[cnt - 1]
			cnt = 0
		cnt += 1
	print(pyramids)


import sys
t = int(sys.stdin.readline())
for T in range(t):
	r = 30000
	n = int(sys.stdin.readline())
	arr = [0] * r
	for i in range(r):
		arr[i] = (3 * (i + 1) ** 2 + i + 1) // 2
		if arr[i] >= n:
			r = i + 1
			break
	ans = 0
	for i in range(r):
		z = r - i - 1
		p = n // arr[z]
		n -= arr[z] * p
		ans += p
	print(ans)


from math import sqrt
for _ in range(int(input())):
	n = int(input())
	z = lambda x: int((-1 + int(sqrt(1 + 24 * x))) / 6)
	cost = lambda x: (3 * x ** 2 + x) // 2
	ans = 0
	while n > 1:
		ans += 1
		n -= cost(z(n))
	print(ans)


from bisect import bisect_right as bl
t = int(input())
a = []
for i in range(1, 25820):
	a.append(i * (i + 1) + i * (i - 1) // 2)
for _ in range(t):
	n = int(input())
	cnt = 0
	while n > 0:
		n -= a[bl(a, n) - 1]
		if n >= 0:
			cnt += 1
	print(cnt)


def calc(n):
	return 3 * (n * (n + 1)) // 2 - n

def binSearch(start, end, num):
	mid = (start + end) // 2
	a = calc(mid)
	b = calc(mid + 1)
	if a <= num and b > num:
		return a
	elif a < num:
		return binSearch(mid + 1, end, num)
	return binSearch(start, mid - 1, num)
for tt in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		n -= binSearch(1, n, n)
		c += 1
	print(c)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
from io import BytesIO
array = [1]
array2 = [2]
limit = 1000000001
for i in range(2, 1000000):
	array.append(array[len(array) - 1] + i)
	array2.append(array[len(array) - 1] + i ** 2)
	if array2[len(array) - 1] > limit:
		break
for t in range(int(input())):
	n = int(input())
	answer = 0
	while n > 1:
		for i in range(len(array2) - 1, -1, -1):
			if n >= array2[i]:
				n -= array2[i]
				break
		answer += 1
	print(answer)


from itertools import takewhile
from bisect import bisect
cards = list(takewhile(lambda x: x <= 10 ** 9, map(lambda x: x * (3 * x + 1) // 2, range(1, 10 ** 5))))
tc = int(input())
while tc > 0:
	n = int(input())
	cards_count = 0
	hi = len(cards)
	while n > 1:
		hi = bisect(cards, n, lo=0, hi=hi) - 1
		(q, r) = divmod(n, cards[hi])
		cards_count += q
		n = r
	print(cards_count)
	tc -= 1


def Spider():
	n = int(input())
	c = 2
	m = 0
	while n > 1:
		if n < c:
			c = 2
			m += 1
		else:
			n -= c
			c += 3
		if n <= 1:
			m += 1
	print(m)
TIMES = 1
TIMES = int(input())
for TIME_TEMP in range(TIMES):
	Spider()


import sys
sys.setrecursionlimit(10 ** 8)
try:
	FILE_POINTER = open('input.inpt')
	input = FILE_POINTER.readline
except:
	FILE_POINTER = None
	input = sys.stdin.readline
from bisect import bisect_right
arr = [0, 2]
i = 2
while arr[-1] < 1000000000.0 + 10:
	arr.append(arr[-1] + 3 * i - 1)
	i += 1
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		ind = bisect_right(arr, n)
		ans += 1
		n -= arr[ind - 1]
	print(ans)
if FILE_POINTER:
	FILE_POINTER.close()


dp = [0] * int(100000.0)
dp[1] = 2
dp[2] = 7
for i in range(3, int(100000.0)):
	dp[i] = 2 * dp[i - 1] - dp[i - 2] + 3
for _ in range(int(input())):
	n = int(input())
	i = 1
	count = 0
	while n > 1:
		if dp[i] > n:
			n -= dp[i - 1]
			i = 1
			count += 1
		i += 1
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	i = 2
	cards = 2
	l = []
	l.append(0)
	l.append(2)
	while cards < n:
		cards = cards + 2 * i + (i - 1)
		l.append(cards)
		i += 1
	if n == l[len(l) - 1]:
		print(1)
	else:
		l = l[1:len(l) - 1]
		count = 0
		i = len(l) - 1
		while n > 1:
			if l[i] <= n:
				count += n // l[i]
				n = n % l[i]
			i -= 1
		print(count)


n = int(input())
o = []

def dfs(n, s):
	t = (-1 + (1 + 24 * n) ** 0.5) // 6
	if t == 0:
		return s
	else:
		s += 1
		s = dfs(n - 0.5 * t * (3 * t + 1), s)
	return s
for i in range(n):
	m = int(input())
	o += [str(dfs(m, 0))]
print('\n'.join(o))


a = [0] * 5 * 10 ** 4
a[1] = 2
for i in range(2, 5 * 10 ** 4):
	a[i] = a[i - 1] + i * 3 - 1
for _ in range(int(input())):
	n = int(input())
	k = 0
	l = -1
	r = 5 * 10 ** 4 - 1
	while r - l > 1:
		m = (r + l) // 2
		if a[m] < n:
			l = m
		else:
			r = m
	i = r + 1
	while i > 0:
		if a[i] <= n:
			n -= a[i]
			k += 1
		else:
			i -= 1
	print(k)


import math

def solve(card_counts):
	pyramids_possible = list()
	for card_count in card_counts:
		total_pyramids = 0
		while card_count >= 2:
			highest_pyramid_height = (math.sqrt(6 * card_count + 0.25) - 0.5) / 3
			highest_pyramid_cards_needed = cards_needed_for_given_height(int(highest_pyramid_height))
			if card_count >= highest_pyramid_cards_needed:
				card_count -= highest_pyramid_cards_needed
			else:
				break
			total_pyramids += 1
		pyramids_possible.append(total_pyramids)
	return '\n'.join((str(p) for p in pyramids_possible))

def cards_needed_for_given_height(h):
	return h * (3 * h + 1) / 2
t = int(input())
card_counts = list()
for _t in range(0, t):
	card_counts.append(int(input()))
print(solve(card_counts))


def list_int():
	return list(map(int, input().split()))

def int_in():
	return int(input())

def map_in():
	return map(int, input().split())

def list_in():
	return input().split()
t = int_in()

def p(n):
	return 3 * n * (n + 1) // 2 - n
for _ in range(t):
	n = int_in()
	c = 0
	a = int(n ** 0.5)
	while n > 1:
		while p(a) > n:
			a -= 1
		n -= p(a)
		a = min(a, int(n ** 0.5))
		c += 1
	print(c)


import sys
from os import path
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
from math import sqrt
get_int = lambda : int(input())
get_ints = lambda : map(int, input().split())
get_ints_list = lambda : list(get_ints())
t = get_int()
for _ in range(t):
	s = get_int()
	x = 0
	while s >= 2:
		n = (-1 + sqrt(1 + 24 * s)) // 6
		s2 = n * (2 * 2 + (n - 1) * 3) // 2
		s -= s2
		x += 1
	print(x)


arr = [0 for i in range(50000)]
for i in range(1, 50000):
	arr[i] = arr[i - 1] + 2 * i + i - 1
for t in range(int(input())):
	n = int(input())
	cnt = 0
	i = 1
	while n > 1:
		if n >= arr[i + 1]:
			i += 1
		else:
			n -= arr[i]
			i = 1
			cnt += 1
	print(cnt)


import bisect
n = input()
n = int(n)
cache = []
i = 0
while True:
	num = 2 + 2 * i + 3 / 2 * (i + 1) * i
	num = int(num)
	if num <= 1000000000:
		cache.append(num)
		i += 1
	else:
		break
for i in range(n):
	num = input()
	num = int(num)
	if num < 2:
		print(0)
		continue
	count = 0
	idx = bisect.bisect_right(cache, num)
	while num >= 2:
		idx = idx - 1
		num -= cache[idx]
		count += 1
		idx = bisect.bisect_right(cache, num)
	print(count)


for _ in range(int(input())):
	n = int(input())
	s = 0
	while n > 2:
		px = 2
		py = 5
		while px <= n:
			px += py
			py += 3
		py -= 3
		px -= py
		n -= px
		s += 1
	if n == 2:
		s += 1
	print(s)


l = [2]
for i in range(3 * 10 ** 4):
	l.append(l[-1] + 3 * (i + 2) - 1)

def abn(l, n):
	if n < 2:
		return 0
	else:
		c = 0
		for i in range(n):
			if l[i] > n:
				c = i
				break
		n -= l[c - 1]
		return abn(l, n) + 1
for _ in range(int(input())):
	n = int(input())
	print(abn(l, n))


def g(n):
	return (3 * n ** 2 + n) // 2

def f(n):
	if n == 0 or n == 1:
		return 0
	(lo, hi) = (1, n)
	while lo <= hi:
		mid = (lo + hi) // 2
		if g(mid) <= n:
			el = mid
			lo = mid + 1
		else:
			hi = mid - 1
	return f(n - g(el)) + 1
t = int(input())
for _ in range(t):
	n = int(input())
	print(f(n))


from bisect import bisect
l = [2]
i = 1
while l[-1] <= 10 ** 9:
	i += 1
	l.append(l[-1] + 2 * i)
for i in range(len(l)):
	l[i] += i * (i + 1) // 2
for _ in range(int(input())):
	n = int(input())
	c = 0
	while True:
		x = bisect(l, n)
		if x != 0 and l[x] > n:
			x -= 1
		n -= l[x]
		if n < 0:
			break
		c += 1
	print(c)


import math
t = int(input())
for _ in range(t):
	n = int(input())
	count = 0
	while n >= 2:
		lar = 0
		n1 = int(math.sqrt(n)) + 1
		for h in range(1, n1):
			k1 = 3 / 2 * h ** 2
			k2 = 1 / 2 * h
			k = int(k1 + k2)
			if k <= n:
				lar = k
			else:
				break
		count = count + 1
		n = n - lar
	print(count)


import math
lista = [2, 7, 15]
for w in range(int(input())):
	a = int(input())
	while a > lista[-1]:
		lista.append(lista[-1] + (len(lista) + 1) * 2 + len(lista))
	if a in lista:
		print(1)
	else:
		b = len(lista)
		cont = 0
		while True:
			if a >= lista[b - 1]:
				a -= lista[b - 1]
				cont += 1
			else:
				b -= 1
			if a <= 1:
				break
		print(cont)


import sys
import bisect as bs

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
d = [0 for i in range(25821)]
d[1] = 2
for i in range(2, 25821):
	d[i] = d[i - 1] + 3 * i - 1
	if d[i] >= 10 ** 9:
		break
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	c = 0
	while n >= 2:
		z = bs.bisect_left(d, n)
		if d[z] > n:
			z -= 1
		n -= d[z]
		c += 1
	print(c)


import sys
import bisect
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def check(n):
	ind = bisect.bisect_right(dp, n)
	return ind - 1
for _ in range(int(ri())):
	dp = []
	dp.append(2)
	cnt = 7
	while cnt < 10 ** 9:
		dp.append(cnt)
		cnt += len(dp) * 3 + 2
	n = int(ri())
	ans = 0
	while n > 0:
		num = check(n)
		if num >= 0:
			ans += 1
			n -= dp[num]
		else:
			break
	print(ans)


from math import floor, sqrt
for _ in range(int(input())):
	An = int(input())
	count = 0
	while An >= 2:
		N = floor((sqrt(24 * An + 1) - 1) / 6)
		An -= int(N * (3 * N + 1) / 2)
		count += 1
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	k = 0
	while n >= 2:
		l = 0
		r = n
		while r - l > 1:
			x = (r + l) // 2
			if (2 + 2 + 3 * (x - 1)) * x // 2 <= n:
				l = x
			else:
				r = x
		n = n - (2 + 2 + 3 * (l - 1)) * l // 2
		k += 1
	print(k)


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda : list(map(int, cin().split()))

def chars():
	s = cin()
	return list(s[:len(s) - 1])

def pl(a):
	for val in a:
		cout(val + '\n')
(t,) = mp()
for _ in range(t):
	(n,) = mp()
	count = 0
	while n > 1:
		x = int(((24 * n + 1) ** 0.5 - 1) / 6)
		n -= 2 * x + 3 * x * (x - 1) // 2
		count += 1
	cout(str(count) + '\n')


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
print = stdout.write
for _ in range(int(input())):
	n = int(input())
	cou = 0
	while n > 1:
		x = 1
		while (x + 1) * x + (x - 1) * x // 2 <= n:
			x += 1
		n -= (x - 1) * x + (x - 1) * (x - 2) // 2
		cou += 1
	print(str(cou) + '\n')


t = int(input())
for test in range(t):
	n = int(input())
	used = 0
	c = 0
	while n > 1:
		height = 1
		req = 2
		while req <= n:
			used += req
			n -= req
			height += 1
			req = height * 2 + (height - 1)
		c += 1
	print(c)


for i in range(int(input())):
	a = int(input())
	d = a
	t = 0
	index = 0
	n = d
	count = 0
	if a < 2:
		print(0)
		continue
	while n > 0:
		count += 1
		a = n
		if n < 2 and count > 1:
			count -= 1
			break
		for j in range(0, a):
			ctr = 0
			ctr += 2 + 3 * j
			a -= ctr
			if a == 0:
				index = 0
				t = n
				break
			elif a < 0:
				index = j
				break
		if index > 0:
			t = 2 * index + 3 * int(index * (index - 1) / 2)
		n -= t
	print(count)


from bisect import bisect_right
a = []
for h in range(1, 10 ** 5):
	a.append(h * (1 + 3 * h) // 2)
for _ in range(int(input())):
	n = int(input())
	c = 0
	while n > 1:
		u = bisect_right(a, n)
		n -= a[u - 1]
		c += 1
	print(c)


y = int(input())
ans = []
for i in range(y):
	n = int(input())
	a = 0
	j = 1
	t = [0]
	f = 0
	if n < 2:
		ans.append(0)
		continue
	while True:
		t.append(int(j * (j + 1) + j * (j - 1) / 2))
		f = int(j * (j + 1) + j * (j - 1) / 2)
		j += 1
		if f > n:
			break
	n = n - t[-2]
	a += 1
	j = 1
	while n > 1:
		if t[j] > n:
			n = n - t[j - 1]
			a += 1
			j = 1
		j += 1
	ans.append(a)
for i in ans:
	print(i)


t = int(input())
for svghj in range(t):
	n = int(input())
	answer = 0
	while n > 1:
		answer += 1
		l = 1
		r = n ** 0.5 + 1
		r = int(r)
		while r > l + 1:
			d = (r + l) // 2
			c = d * (d + 1) * 1.5 - d
			c = int(c)
			if c > n:
				r = d
			else:
				l = d
		c = l * (l + 1) * 1.5 - l
		c = int(c)
		n -= c
	print(answer)


from math import sqrt
for _ in range(int(input())):
	p = int(input())
	cont = 0
	x = 2
	while p > 2:
		delta = 1 + 24 * p
		x = int((-1 + sqrt(delta)) / 6)
		p -= (3 * x ** 2 + x) / 2
		cont += 1
	if p == 2:
		cont += 1
	print(cont)


import io
import os
from bisect import bisect_right
numSticks = []
for h in range(10 ** 5):
	numTriangles = h * h
	numSticks.append((numTriangles * 3 + 3 * h) // 2 - h)
assert numSticks[-1] > 10 ** 9

def solve(N):
	count = 0
	while N:
		index = bisect_right(numSticks, N)
		assert numSticks[index] > N
		assert numSticks[index - 1] <= N
		if numSticks[index - 1] == 0:
			break
		N -= numSticks[index - 1]
		count += 1
	return count
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	ans = solve(N)
	print(ans)


import bisect
arr = [0 for i in range(10 ** 5)]
for i in range(1, 10 ** 5 + 1):
	arr[i - 1] = (3 * i * i + i) // 2
t = int(input())
for you in range(t):
	n = int(input())
	count = 0
	while bisect.bisect_right(arr, n) > 0:
		count += 1
		n = n - arr[bisect.bisect_right(arr, n) - 1]
	print(count)


for _ in range(int(input())):
	n = int(input())
	count = 0
	while n > 1:
		x = 1
		var = 1
		while (3 * (x * x) + x) // 2 <= n:
			var = (3 * (x * x) + x) // 2
			x += 1
		count += 1
		n -= var
	print(count)


import sys
import math

def readStr():
	return sys.stdin.readline().rstrip()

def readInts():
	return list(map(int, readStr().split(' ')))

def pira(n):
	h = math.ceil(math.sqrt(2 / 3 * n))
	while 3 / 2 * h ** 2 + 1 / 2 * h > n:
		h -= 1
	return 3 / 2 * h ** 2 + 1 / 2 * h

def main(n):
	i = 0
	while True:
		ni = pira(n)
		if not ni:
			break
		i += 1
		n -= ni
	return i
(t,) = readInts()
for _ in range(t):
	(n,) = readInts()
	x = main(n)
	print(x)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')

def cards(x):
	level_x = 2 * x + (x - 1)
	return level_x
maxi = 50000
this = [0] * maxi
this[0] = cards(1)
for i in range(1, maxi):
	this[i] = cards(i + 1) + this[i - 1]
for _ in range(int(input())):
	n = int(input())
	ans = 0
	while n > 1:
		x = upper_bound(this, n + 0.1)
		ans += 1
		n -= this[x - 1]
	print(ans)


q = int(input())
for i in range(q):
	n = int(input())
	d = 0
	cnt = 0
	while n > 1:
		d = pow(24 * n + 1, 0.5) - 1
		d = d / 6
		d = int(d)
		cards = 3 * pow(d, 2) + d
		cards = cards // 2
		n = n - cards
		cnt += 1
	print(cnt)


def solve():
	t = int(input())
	for _ in range(t):
		n = int(input())
		count = 0
		while n > 0:
			if n == 1:
				break
			k = 1
			while k * (3 * k + 1) // 2 <= n:
				k += 1
			k -= 1
			n -= k * (3 * k + 1) // 2
			count += 1
		print(count)
solve()


from bisect import bisect_left as bl
arr = [0] * (5 * 10 ** 4 + 1)
arr[0] = 0
arr[1] = 2
arr[2] = 7
arr[3] = 15
for i in range(4, 5 * 10 ** 4 + 1):
	arr[i] = arr[i - 1] + 3 * (i - 1) + 2
for _ in range(int(input())):
	n = int(input())
	count = 0
	while n:
		b = bl(arr, n) - 1
		if n < 2:
			break
		count += 1
		n -= arr[b] if arr[b + 1] > n else arr[b + 1]
	print(count)


a = 2
i = 1
l1 = [2]
while a < 10 ** 9:
	i += 1
	a = i * (i + 1) + (i - 1) * i // 2
	l1.append(a)
l1.pop()
l1.reverse()
for _ in range(int(input())):
	n = int(input())
	ans = 0
	for i in l1:
		if n < 2:
			break
		if i <= n:
			ans += n // i
			n %= i
	print(ans)


from functools import lru_cache

@lru_cache(None)
def f(i):
	if i == 0:
		return 0
	else:
		return f(i - 1) + 3 * i - 1
for i in range(30000):
	f(i)
t = int(input())
for _ in range(t):
	n = int(input())
	ans = 0
	while n > 1:
		b = i
		x = 0
		while b > 0:
			while f(x + b) <= n:
				x += b
			b //= 2
		n -= f(x)
		ans += 1
	print(ans)


import sys

def bisect(arr, e):
	l = 0
	r = len(arr) - 1
	while l <= r:
		item = (l + r) // 2
		if arr[item] == e:
			return item
		elif arr[item] > e:
			r = item - 1
		else:
			l = item + 1
	return item
a = [2]
i = 0
while a[i] <= 10 ** 9:
	a.append(a[i] + i + 1 + (i + 2) * 2)
	i += 1
for t in range(int(sys.stdin.readline())):
	inp = int(sys.stdin.readline())
	res = 0
	while inp >= 2:
		q = bisect(a, inp)
		if a[q] > inp:
			q -= 1
		inp -= a[q]
		res += 1
	sys.stdout.write('{}\n'.format(res))