The subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

You are given an integer $n$. 

You have to find a sequence $s$ consisting of digits $\{1, 3, 7\}$ such that it has exactly $n$ subsequences equal to $1337$.

For example, sequence $337133377$ has $6$ subsequences equal to $1337$:   $337\underline{1}3\underline{3}\underline{3}7\underline{7}$ (you can remove the second and fifth characters);  $337\underline{1}\underline{3}3\underline{3}7\underline{7}$ (you can remove the third and fifth characters);  $337\underline{1}\underline{3}\underline{3}37\underline{7}$ (you can remove the fourth and fifth characters);  $337\underline{1}3\underline{3}\underline{3}\underline{7}7$ (you can remove the second and sixth characters);  $337\underline{1}\underline{3}3\underline{3}\underline{7}7$ (you can remove the third and sixth characters);  $337\underline{1}\underline{3}\underline{3}3\underline{7}7$ (you can remove the fourth and sixth characters). 

Note that the length of the sequence $s$ must not exceed $10^5$.

You have to answer $t$ independent queries.


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 10$) — the number of queries. 

Next $t$ lines contains a description of queries: the $i$-th line contains one integer $n_i$ ($1 \le n_i \le 10^9$).


-----Output-----

For the $i$-th query print one string $s_i$ ($1 \le |s_i| \le 10^5$) consisting of digits $\{1, 3, 7\}$. String $s_i$ must have exactly $n_i$ subsequences $1337$. If there are multiple such strings, print any of them.


-----Example-----
Input
2
6
1

Output
113337
1337

Difficulty: HARD
Tags: String algorithms

Combinatorics

Mathematics

Constructive algorithms

Starter code:

Solutions:
T = int(input())
for _ in range(T):
	n = int(input())
	if n <= 10 ** 5 - 3:
		print('1' * n + '337')
		continue
	b = 0
	while True:
		total = (b + 2) * (b + 1) // 2
		if 0 <= n - total and n - total + b + 4 <= 10 ** 5:
			a = n - total
			print('133' + '7' * a + '3' * b + '7')
			break
		b += 1


import sys
input = sys.stdin.readline

def f(x):
	ret = int(((1 + 8 * x) ** 0.5 - 1) // 2)
	if ret * (ret + 1) // 2 <= x:
		return ret + 1
	else:
		return ret
t = int(input())
for _ in range(t):
	n = int(input())
	A = []
	while n > 1:
		A.append(f(n))
		n -= f(n) * (f(n) - 1) // 2
	if n > 0:
		A.append(2)
	if len(A) == 1:
		print('1' + '3' * A[0] + '7')
	else:
		ans = ''
		for i in range(len(A) - 1):
			a = A[i] - A[i + 1]
			ans += '7' + '3' * a
		ans += '7' + '3' * A[-1] + '1'
		print(ans[::-1])


import sys
import math as mt
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	for i in range(2, 50000):
		x = i * (i - 1) // 2
		y = n - x
		if i + y + 2 <= 10 ** 5 and y >= 0:
			if y > 0:
				print(133, end='')
				for j in range(y):
					print(7, end='')
				for j in range(i - 2):
					print(3, end='')
				print(7, end='')
			else:
				print(1, end='')
				for j in range(i):
					print(3, end='')
				print(7, end='')
			break
	print()


for _ in range(int(input())):
	n = int(input())
	ind = 2
	while True:
		if ind * (ind - 1) // 2 > n:
			ind -= 1
			break
		ind += 1
	st = '1' + '3' * 2 + '7' * (n - ind * (ind - 1) // 2) + '3' * (ind - 2) + '7'
	print(st)


import bisect
ans = [-1]
n = 0
while ans[-1] <= 1000000000:
	ans.append(n * (n + 1) // 2)
	n += 1
ans.pop(0)
for _ in range(int(input())):
	n = int(input())
	s = '1'
	lol = bisect.bisect(ans, n)
	s += '3' * lol
	bacha = n - ans[lol - 1]
	s = list(s)
	s.pop()
	s.pop()
	s.append('1' * bacha)
	s.append('337')
	print(''.join(s))


t = int(input())
for j in range(t):
	n = int(input())
	threes = 0
	while threes * (threes - 1) / 2 <= n:
		threes += 1
	threes -= 1
	remain = n - threes * (threes - 1) // 2
	s = '133' + remain * '7' + (threes - 2) * '3' + '7'
	print(s)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
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')

class SegmentTree:

	def __init__(self, data, default=-10 ** 6, func=lambda a, b: max(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)

class SegmentTree1:

	def __init__(self, data, default=10 ** 6, func=lambda a, b: min(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)
MOD = 10 ** 9 + 7

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
omod = 998244353
prime = [True for i in range(50001)]
pp = []

def SieveOfEratosthenes(n=50000):
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for i in range(50001):
		if prime[i]:
			pp.append(i)
for i in range(int(input())):
	s = int(input())
	n = (1 + (1 + 8 * s) ** 0.5) // 2
	n = int(n)
	d = s - n * (n - 1) // 2
	res = '1' + '33' + '7' * d + '3' * (n - 2) + '7'
	print(res)


import sys
input = sys.stdin.readline
from math import floor, sqrt, log
q = int(input())
for _ in range(q):
	n = int(input())
	if n == 1:
		print('1337')
		continue
	x = 2
	while x * (x - 1) // 2 < n:
		x += 1
	x -= 1
	n -= x * (x - 1) // 2
	print('133', end='')
	print('7' * n, end='')
	print('3' * (x - 2), end='')
	print('7')


def string_1337(n, L=[], first=True):
	j = int((2 * n) ** (1.0 / 3.0))
	if j < 2:
		L.extend([1] * n)
	else:
		L.append(j)
		m = j * j * (j - 1) // 2
		string_1337(n - m, L, False)
	if first:
		(L1, L2) = ([], [])
		j = -1
		for i in L:
			if i == j or (i == 1 and j == 2):
				L1[-1] += i
			else:
				L1.append(i)
				L2.append(2 if i == 1 else i)
				j = i
		m = len(L1)
		L2.append(0)
		for i in range(m):
			print('1' * L1[i], '3' * (L2[i] - L2[i + 1]), sep='', end='')
		print(7)
n = int(input())
for _ in range(n):
	string_1337(int(input()), [])


q = int(input())
for k in range(q):
	n = int(input())
	i = 0
	while i * (i - 1) / 2 <= n:
		i += 1
	b = i - 1
	a = n - b * (b - 1) // 2
	print('133' + '7' * a + '3' * (b - 2) + '7')


t = int(input())
while t:
	n = int(input())
	import math
	c3 = int(math.sqrt(n * 2))
	while c3 * (c3 - 1) <= 2 * n:
		c3 += 1
	c3 -= 1
	need = n - (c3 - 1) * c3 // 2
	ans = [1] + [3] * (c3 - 2) + [1] * need + [3, 3] + [7]
	print(''.join(map(str, ans)))
	t -= 1


import math
T = int(input())
for _ in range(T):
	arr = []
	src = int(input())
	n = src
	if n == 1:
		print('1337')
	elif n == 2:
		print('11337')
	elif n == 3:
		print('13337')
	elif n == 4:
		print('113377')
	elif n == 5:
		print('11111337')
	elif n == 6:
		print('113337')
	else:
		m = int(math.sqrt(n * 2.0))
		while m * (m - 1) // 2 <= n:
			m += 1
		m -= 1
		arr.append(m)
		n -= int(m * (m - 1) // 2)
		ans = ['1', '3', '3']
		for i in range(n):
			ans.append('7')
		cnt = 2
		for item in arr:
			ans.append('3' * (item - cnt))
		ans.append('7')
		print(''.join(ans))


def naiveSolve(n):
	return

def main():

	def getCnts(threeCnts):
		return (threeCnts * threeCnts - threeCnts) // 2
	t = int(input())
	for _ in range(t):
		n = int(input())
		threeCnts = 2
		while getCnts(threeCnts + 1) <= n:
			threeCnts += 1
		oneCnts = n - getCnts(threeCnts)
		ans = '1' + '3' * (threeCnts - 2) + '1' * oneCnts + '337'
		print(ans)
	return
import sys
input = sys.stdin.buffer.readline

def oneLineArrayPrint(arr):
	print(' '.join([str(x) for x in arr]))

def multiLineArrayPrint(arr):
	print('\n'.join([str(x) for x in arr]))

def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))

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

def makeArr(defaultValFactory, dimensionArr):
	dv = defaultValFactory
	da = dimensionArr
	if len(da) == 1:
		return [dv() for _ in range(da[0])]
	else:
		return [makeArr(dv, da[1:]) for _ in range(da[0])]

def queryInteractive(l, r):
	print('? {} {}'.format(l, r))
	sys.stdout.flush()
	return int(input())

def answerInteractive(x):
	print('! {}'.format(x))
	sys.stdout.flush()
inf = float('inf')
MOD = 10 ** 9 + 7
from math import gcd, floor, ceil
for _abc in range(1):
	main()


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	n = int(input())
	x = 0
	a = []
	while n:
		for i in range(2, n + 10):
			if i * (i - 1) // 2 > n:
				x = i - 1
				break
		n = n - x * (x - 1) // 2
		a.append(x)
	for i in range(len(a) - 1):
		a[i] -= a[i + 1]
	ans = []
	for i in a:
		ans.append('1')
		ans.append('3' * i)
	ans.append('7')
	print(''.join(ans))


t = int(input())
comb_of_three = []
for i in range(4900):
	comb_of_three.append(int(i ** 2 / 2 - i / 2))
for j in range(t):
	n = int(input())
	if n == 1:
		print('1337')
		continue
	if n == 2:
		print('11337')
		continue
	cot = []
	for f in range(4900):
		cot.append(comb_of_three[f])
	len_cot = len(cot)
	position_of_one = []
	string = []
	k = n
	s = ''
	limit = 4900
	while k > 2:
		for i in range(limit):
			if i > 0:
				if comb_of_three[i] > k:
					if k - comb_of_three[i - 1] >= 0:
						position_of_one.append(i - 1)
						k -= comb_of_three[i - 1]
						limit -= 1
				elif k - cot[len_cot - 1] >= 0:
					position_of_one.append(len_cot - 1)
					k -= cot[len_cot - 1]
					cot.pop(len_cot - 1)
					len_cot -= 1
	position_of_one.append(0)
	count_of_three = 0
	ind = len(position_of_one) - 1
	for i in range(len(position_of_one) - 1):
		string.append('1')
		for i in range(position_of_one[i] - position_of_one[i + 1]):
			string.append('3')
	if k != 0:
		for i in range(k):
			string.append('3')
		if k == 1:
			string[len(string) - 3] = '1'
		if k == 2:
			string[len(string) - 3] = '1'
			string[len(string) - 4] = '1'
	for i in range(len(string)):
		s += str(string[i])
	s += '7'
	print(s)


t = int(input())
while t:
	n = int(input())
	ch = 0
	for i in range(100000):
		if i * (i - 1) // 2 > n:
			ch = i - 1
			break
	rem = n - ch * (ch - 1) // 2
	s = '1'
	s = s + '33' + '7' * rem + '3' * (ch - 2) + '7'
	print(s)
	t -= 1


from math import sqrt
for _ in range(int(input())):
	n = int(input())
	if n < 10000:
		print('133' + n * '7')
		continue
	c = int(sqrt(n))
	b = c - 6
	a = n - c * c
	if a > c:
		a -= c
		b += 1
	print('133' + a * '7' + b * '1' + '33' + c * '7')


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()]
t = read_int()
for i in range(t):
	n = read_int()
	x = 2
	while x * (x - 1) // 2 <= n:
		x += 1
	x -= 1
	r = n - x * (x - 1) // 2
	rem = '7' * r
	ans = '133' + rem + '3' * (x - 2) + '7'
	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().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[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

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 main():
	for _ in range(ii()):
		n = ii()
		s = ''
		len = 2
		while len * (len - 1) // 2 <= n:
			len += 1
		len -= 1
		rem = n - len * (len - 1) // 2
		s += '133'
		for i in range(rem):
			s += '7'
		for i in range(len - 2):
			s += '3'
		s += '7'
		print(s)
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()


from sys import stdin, stdout
from itertools import accumulate
T = int(input())
check = [0] * 45000
s = 0
for i in range(1, 45001):
	s += i
	check[i - 1] = s
for i in range(T):
	N = int(input())
	if N in check:
		idx = check.index(N)
		idx += 2
		print('1', '3' * idx, '7', sep='', end='\n')
	else:
		target = max((num for num in check if num < N))
		three = check.index(target)
		d = N - target
		print('1', '3' * 2, '7' * d, '3' * three, '7', sep='', end='\n')


inputs = int(input())
for i in range(inputs):
	n = int(input())
	S = []
	while n > 0:
		D = 1 + 8 * n
		k_i1 = (1 + D ** (1 / 2)) / 2
		k_i2 = (1 - D ** (1 / 2)) / 2
		k_ipos = k_i1
		if k_i2 > 0:
			k_ipos = k_i2
		miin = 0
		maxx = k_ipos
		while miin != maxx and (miin + maxx) // 2 != maxx and ((miin + maxx) // 2 != miin):
			med = (miin + maxx) // 2
			if med ** 2 - med < 2 * n:
				miin = (miin + maxx) // 2
			if med ** 2 - med > 2 * n:
				maxx = (miin + maxx) // 2
		result = (miin + maxx) // 2
		if (result + 1) ** 2 - result - 1 <= 2 * n:
			result = (miin + maxx) // 2 + 1
		S.append(result)
		n -= result * (result - 1) // 2
	result = '7'
	previous = 0
	for i in range(len(S)):
		current = int(S[len(S) - 1 - i])
		result = '1' + (current - previous) * '3' + result
		previous = current
	print(result)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	y = 0
	x = 0
	min_l = 10 ** 5
	for i in range(10 ** 5):
		xx = n - i * (i + 3) // 2 - 1
		if xx >= 0 and n - xx >= 0 and (min_l >= i + xx + 4):
			x = xx
			y = i
			min_l = i + xx + 4
	print('1' + '33' + '7' * x + '3' * y + '7')


import sys
zz = 1
sys.setrecursionlimit(10 ** 5)
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def ii():
	return input().rstrip()

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def gtc(tc, ans):
	print('Case #' + str(tc) + ':', ans)

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

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

def gh():
	sys.stdout.flush()

def isvalid(i, j, n, m):
	return 0 <= i < n and 0 <= j < m

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
uu = t
while t > 0:
	t -= 1
	n = fi()
	p = n
	a = []
	s = '1'
	while p:
		l = ans = 1
		r = 10 ** 5 + 5
		while l <= r:
			mid = (l + r) // 2
			if (mid * mid - mid) // 2 <= p:
				ans = mid
				l = mid + 1
			else:
				r = mid - 1
		p -= (ans * ans - ans) // 2
		a.append(ans)
	a.sort()
	s += '3' * a[0] + '7'
	for i in range(1, len(a)):
		s += (a[i] - a[i - 1]) * '3' + '7'
	print(s)


from math import sqrt
t = int(input())
for _ in range(t):
	n = int(input())
	if n < 1000:
		print(133, *[7] * n, sep='')
		continue
	c = int(sqrt(n))
	b = n // c - 6
	a = n - (b + 6) * c
	print('133', end='')
	for _ in range(a):
		print('7', end='')
	for _ in range(b):
		print('1', end='')
	print('33', end='')
	for _ in range(c):
		print('7', end='')
	print()


from math import floor
t = int(input())
for i2 in range(t):
	n = int(input())
	if n < 20:
		print('133' + '7' * n)
		continue
	x = floor((n * 2) ** (1 / 2)) - 1
	(ma, ans) = (x, [0] * 100000)
	n -= x * (x - 1) // 2
	while n > 5:
		x = floor((n * 2) ** (1 / 2)) - 1
		n -= x * (x - 1) // 2
		ans[x] += 1
	ans[2] += n
	print('1', end='')
	for i in range(1, ma + 1):
		print('3', end='')
		print('1' * ans[ma - i], end='')
	print('7')


T = int(input())
for _ in range(T):
	n = int(input())
	t = n // 16471
	r = n - t * 16471
	print('133' + '7' * r + '3' * 180 + '7' * t)


t = int(input())
for _ in range(t):
	X = int(input())
	n = 0
	while (n + 1) * (n + 2) // 2 <= X:
		n += 1
	n -= 1
	m = X - (n + 1) * (n + 2) // 2
	print('133' + '7' * m + '3' * n + '7')


inputs = int(input())
for i in range(inputs):
	n = int(input())
	S = []
	while n > 0:
		D = 1 + 8 * n
		k_i1 = (1 + D ** (1 / 2)) / 2
		k_i2 = (1 - D ** (1 / 2)) / 2
		k_ipos = k_i1
		if k_i2 > k_ipos:
			k_ipos = k_i2
		k_i = int(k_ipos)
		S.append(k_i)
		n -= k_i * (k_i - 1) // 2
	result = '7'
	previous = 0
	for i in range(len(S)):
		current = int(S[len(S) - 1 - i])
		result = '1' + (current - previous) * '3' + result
		previous = current
	print(result)


def solve(n):
	cur = 2
	while cur * (cur + 1) // 2 <= n:
		cur += 1
	ans = [cur]
	if cur * (cur - 1) // 2 != n:
		ans.extend(solve(n - cur * (cur - 1) // 2))
	return ans
for _ in range(int(input())):
	ans = solve(int(input()))
	print('1', end='')
	for i in range(1, len(ans)):
		print('3' * (ans[i - 1] - ans[i]) + '1', end='')
	print('3' * ans[-1] + '7')


import math
for _ in range(int(input())):
	n = int(input())
	if n < 50000:
		print('1' * n + '337')
		continue
	bound = int(math.sqrt(n) + 1)
	i = bound
	j = n // bound
	ext = n % bound
	print('1' * i + '33' + '7' * (j - 6) + '1' * ext + '337')


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 gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	n = int(input())
	if n <= 6:
		print('1' * n + '337')
		continue
	y = 4
	while True:
		total = y * (y - 1) // 2
		if n - total + y + 2 <= 10 ** 5:
			print('1' + '3' * 2 + '7' * (n - total) + '3' * (y - 2) + '7')
			break
		else:
			y += 1


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	n = Int()
	start = '1'
	end = '7'
	end3 = 0
	while end3 * (end3 - 1) // 2 <= n:
		end3 += 1
	end3 -= 1
	rem = n - end3 * (end3 - 1) // 2
	start += '33' + '7' * rem
	end = '3' * (end3 - 2) + end
	print(start + end)


q = int(input())
for i in range(q):
	n = int(input())
	x = 2
	while x * (x - 1) / 2 <= n:
		x += 1
	if x * (x - 1) / 2 > n:
		x -= 1
	remain = int(n - x * (x - 1) / 2)
	print('133', end='')
	print('7' * remain, end='')
	print('3' * (x - 2) + '7')


from os import path
from io import BytesIO, IOBase
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, Counter, defaultdict as dd
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().rstrip()

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

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('0')
file = 1

def ceil(a, b):
	return (a + b - 1) // b

def solve():
	x = []
	for i in range(2, 10005):
		x.append(i * (i - 1) // 2)
	for _ in range(ii()):
		n = ii()
		p = []
		for i in range(len(x) - 1, -1, -1):
			if n >= x[i]:
				n -= x[i]
				p.append(i + 2)
		p.reverse()
		s = '7' + '3' * p[0] + '1'
		if n > 0:
			s += '1'
		cnt = p[0]
		for i in p[1:]:
			rem = i - cnt
			s += '3' * rem
			s += '1'
			cnt = i
		print(s[::-1])
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


import sys
from collections import defaultdict
input = sys.stdin.readline
import math

def main():
	t = int(input())
	for _ in range(t):
		ni = int(input())
		cnt3 = 2
		while cnt3 * (cnt3 + 1) // 2 <= ni:
			cnt3 += 1
		rest = ni - cnt3 * (cnt3 - 1) // 2
		print('1' + '33' + '7' * rest + '3' * (cnt3 - 2) + '7')

def __starting_point():
	main()
__starting_point()


from os import write
t = int(input())
for _ in range(t):
	n = int(input())
	x = int((2 * n) ** (1 / 3))
	y = x
	if x * y * (y + 1) // 2 > n:
		y -= 1
	r = n - x * y * (y + 1) // 2
	result = ['1' * x]
	for y in range(y, 0, -1):
		x = r // (y * (y + 1) // 2)
		r -= x * y * (y + 1) // 2
		result.append('1' * x + '3')
	result.append('37\n')
	write(1, bytes(''.join(result), encoding='ascii'))


for _ in range(int(input())):
	n = int(input())
	(l, r) = (2, 45001)
	while r - l > 1:
		mid = (l + r) // 2
		if mid * (mid - 1) // 2 > n:
			r = mid
		else:
			l = mid
	print('133' + '7' * (n - l * (l - 1) // 2) + '3' * (l - 2) + '7')


t = int(input())
for _ in range(t):
	n = int(input())
	a = []
	d = {}
	i = 45000
	while n:
		val = i * (i - 1) // 2
		r = n // val
		if r:
			a.append(i)
			d[i] = r
			n -= val * r
		i -= 1
	out = ''
	a.append(0)
	for i in range(len(a) - 1):
		out += '1' * d[a[i]]
		out += '3' * (a[i] - a[i + 1])
	out += '7'
	print(out)


inputs = int(input())
for i in range(inputs):
	inputt = int(input())
	lista = []
	while inputt > 0:
		inp = inputt
		while inp > 0:
			D = 1 + 8 * inp
			x1 = (1 + D ** (1 / 2)) / 2
			x2 = (1 - D ** (1 / 2)) / 2
			if x1 == int(x1) and x2 == int(x2):
				pos = x1
				if x2 > 0:
					pos = x2
				lista.append(pos)
				break
			inp -= 1
		inputt -= inp
	result = '7'
	ant = 0
	for i in range(len(lista)):
		act = int(lista[len(lista) - i - 1])
		result = '1' + (act - ant) * '3' + result
		ant += act - ant
	print(result)


for _ in range(int(input())):
	n = int(input())
	if n <= 10 ** 5 - 5:
		print('133' + '7' * n)
	else:
		cf = 300
		g = n - (cf + 2) * (cf + 1) // 2
		b = g // (cf * (cf - 1) // 2)
		c = g % (cf * (cf - 1) // 2)
		print('1' + '3' * cf + '7' * b + '1' * c + '337')


import sys
import math
from collections import defaultdict, deque
import heapq
mod = 998244353

def get(n):
	y = int(math.sqrt(1 + 8 * n))
	z = (1 + y) // 2
	return z
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	rem = n
	newn = get(n)
	rem = n - newn * (newn - 1) // 2
	ans = [1]
	ans.append(3)
	ans.append(3)
	for i in range(rem):
		ans.append(7)
	for i in range(newn - 2):
		ans.append(3)
	ans.append(7)
	print(''.join((str(x) for x in ans)))


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	a = []
	for i in range(45000, 2, -1):
		if i * (i - 1) / 2 <= n:
			a.append(i)
			n -= int(i * (i - 1) / 2)
	print('133', end='')
	for i in range(n):
		print(7, end='')
	p = 2
	for x in a[::-1]:
		for i in range(x - p):
			print(3, end='')
		print(7, end='')
		p = x
	print()


import sys
input = sys.stdin.readline
from bisect import bisect_right
Q = int(input())
Query = [int(input()) for _ in range(Q)]
A = [0]
for t in range(1, 10 ** 5):
	A.append(A[-1] + t)
for n in Query:
	NUMs = []
	while n:
		i = bisect_right(A, n)
		NUMs.append(i)
		n -= A[i - 1]
	ans = '1'
	now = 0
	while NUMs:
		p = NUMs.pop()
		ans += '3' * (p - now) + '7'
		now = p
	print(ans)


from bisect import bisect
tri = []
i = 1
while i * (i + 1) // 2 <= 10 ** 9:
	tri.append(i * (i + 1) // 2)
	i += 1
q = int(input())
for _ in range(q):
	n = int(input())
	a = []
	i = bisect(tri, n)
	while tri[i - 1] < n:
		a.append(i + 1)
		n -= tri[i - 1]
		i = bisect(tri, n)
	a.append(i + 1)
	a.reverse()
	g = [a[0]]
	for i in range(len(a) - 1):
		g.append(a[i + 1] - a[i])
	ans = '7'
	for x in g:
		ans += '3' * x
		ans += '1'
	print(ans[::-1])


import math
t = int(input())
for _ in range(t):
	n = int(input())
	p = '3'
	print(1, end='')
	b = []
	while 1:
		x = math.sqrt(n * 2)
		x = int(x)
		if x * (x + 1) <= n * 2:
			y = x
		else:
			y = x - 1
		b.append(y + 1)
		n -= y * (y + 1) // 2
		if n == 0:
			break
	for i in range(0, len(b) - 1):
		b[i] = b[i] - b[i + 1]
	b.reverse()
	for i in b:
		print(i * p + '7', end='')
	print()


t = int(input())
ans_list = []
table = [i * (i - 1) // 2 for i in range(50001)]

def bisectL(l, r, A, n, limit=100000):
	for i in range(limit):
		if r - l == 1:
			return l
		elif A[(l + r) // 2] > n:
			r = (l + r) // 2
		else:
			l = (l + r) // 2
for i in range(t):
	n = int(input())
	one_list = []
	three_list = []
	while n > 0:
		j = bisectL(0, 50000, table, n)
		s = n // table[j]
		n %= table[j]
		one_list.append(s)
		three_list.append(j)
	three_list.append(0)
	ans = []
	for j in range(len(three_list) - 1):
		ans.append('1' * one_list[j])
		ans.append('3' * (three_list[j] - three_list[j + 1]))
	ans.append('7')
	ans_list.append(ans)
for a in ans_list:
	print(''.join(a))


def main():
	t = int(input())
	while t > 0:
		n = int(input())
		k = 2
		while k * (k - 1) / 2 < n:
			k += 1
		s = ''
		while k >= 2:
			while n >= k * (k - 1) / 2:
				s += '7'
				n -= k * (k - 1) / 2
			k -= 1
			s += '3'
		s += '31'
		print(s[::-1])
		t -= 1
main()


for vishal in range(int(input())):
	n = int(input())
	if n + 3 <= int(100000.0):
		print('133' + '7' * n)
		continue
	k = 3
	while k * (k - 1) / 2 <= n:
		k += 1
	k -= 1
	rem = n - k * (k - 1) // 2
	pat = '133' + '7' * rem + '3' * (k - 2) + '7'
	print(pat)
	assert len(pat) <= int(100000.0)


from sys import stdin
from sys import setrecursionlimit as SRL
SRL(10 ** 7)
rd = stdin.readline
rrd = lambda : map(int, rd().strip().split())
q = int(input())
while q:
	n = int(input())
	k = 2
	while k * (k - 1) / 2 <= n:
		k += 1
	k -= 1
	r = n - k * (k - 1) // 2
	print('1' + '33' + '7' * r + '3' * (k - 2) + '7')
	q -= 1


from sys import stdin, stdout

def get_tile_count(length, width, tile_size):
	length_count = (length + tile_size - 1) // tile_size
	width_count = (width + tile_size - 1) // tile_size
	return length_count * width_count

def get_input_as_list():
	return [int(line.rstrip()) for line in stdin][1:]

def count_subsequence_occurrences(string, subsequence='1337'):
	if len(string) < len(subsequence):
		return 0
	if len(subsequence) == 0:
		return 1
	if len(string) == len(subsequence):
		return int(string == subsequence)
	counter = 0
	for (i, c) in enumerate(string):
		if c == subsequence[0]:
			counter += count_subsequence_occurrences(string[i + 1:], subsequence[1:])
	return counter

def get_n_value(count):
	n = int((2 * count) ** (1.0 / 3.0))
	if ((n + 1) ** 3 - (n + 1) ** 2) // 2 <= count:
		return n + 1
	return n

def get_337_string_and_three_count(count):
	if count == 0:
		return ('', 0)
	if count == 1:
		return ('337', 2)
	n = get_n_value(count)
	(prepended_string, prepended_three_count) = get_337_string_and_three_count(count - (n ** 3 - n ** 2) // 2)
	return (prepended_string + '3' * (n - prepended_three_count) + '7' * n, n)

def get_1337_string(count):
	(substring_337, _) = get_337_string_and_three_count(count)
	return '1' + substring_337
for input_count in get_input_as_list():
	stdout.write(get_1337_string(input_count) + '\n')


from collections import deque

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

def read_ints():
	return map(int, input().split(' '))
t = read_int()
for case_num in range(t):
	n = read_int()
	a = 1
	i = 1
	q = deque()
	while n >= a:
		n -= a
		if a > 1:
			q.appendleft('13')
			while a >= 50000 and n >= a:
				n -= a
				q.appendleft('1')
		i += 1
		a += i
	ans = ''.join(list(q)) + '1' * (n + 1) + '337'
	print(ans)


t = int(input())
array_of_33 = [i * (i - 1) // 2 for i in range(100000)]
for q in range(t):
	n = int(input())
	count3 = 2
	for i in range(2, 10000):
		if array_of_33[i] <= n:
			count3 = i
		else:
			break
	count = array_of_33[count3]
	j = 0
	i = count3
	s = ''
	while n > 0:
		if (j + 1) * i * (i - 1) // 2 <= n:
			j += 1
		else:
			s += '1' * j
			n -= j * i * (i - 1) // 2
			s += '3'
			i -= 1
			j = 0
	s += '3' * i
	s += '7'
	print(s)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, 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)

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)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

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 countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

def find(k):
	if k == 1:
		return 2
	else:
		st = 1
		end = k
		ans = 1
		while st <= end:
			mid = (st + end) // 2
			d = mid * mid - mid
			d //= 2
			if d == k:
				return mid
			elif d < k:
				ans = mid
				st = mid + 1
			else:
				end = mid - 1
		return ans
for i in range(int(input())):
	n = int(input())
	ans = ''
	q = []
	prev = 0
	r = 0
	while n > 0:
		prev = r
		r = find(n)
		q.append(r)
		if len(q) >= 2:
			q[-2] -= q[-1]
		n -= r * (r - 1) // 2
	q.reverse()
	ans = '1'
	for i in q:
		ans += '3' * i + '7'
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for you in range(t):
	n = int(input())
	i = 0
	while i * (i + 3) // 2 < n:
		i += 1
	i -= 1
	z = n - i * (i + 3) // 2
	print(1, end='')
	print('33', end='')
	print((z - 1) * '7', end='')
	print('3' * i, end='')
	print('7')


import math

def findRoots(a, b, c):
	d = 0
	d = b * b - 4 * a * c
	sqrt_val = math.sqrt(abs(d))
	if d > 0:
		d = max((-b + sqrt_val) / (2 * a), (-b - sqrt_val) / (2 * a))
	elif d == 0:
		d = -b / (2 * a)
	return d
N = int(input())
for i in range(N):
	c = int(input())
	a = 1
	b = -1
	f = -2 * (c - 2)
	e = ''
	if c <= 10 ** 5 - 3:
		e = '1' * c + '337'
	else:
		x1 = findRoots(a, b, f) // 1
		x2 = c - x1 * (x1 - 1) // 2
		x1 = int(x1)
		x2 = int(x2)
		e = '1' + '3' * (x1 - 2) + '1' * x2 + '337'
	print(e)


from sys import stdin, stdout
import heapq
import cProfile, math
from collections import Counter, defaultdict, deque
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
import sys
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)
fac_warm_up = False
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7

class MergeFind:

	def __init__(self, n):
		self.parent = list(range(n))
		self.size = [1] * n
		self.num_sets = n
		self.lista = [[_] for _ in range(n)]

	def find(self, a):
		to_update = []
		while a != self.parent[a]:
			to_update.append(a)
			a = self.parent[a]
		for b in to_update:
			self.parent[b] = a
		return self.parent[a]

	def merge(self, a, b):
		a = self.find(a)
		b = self.find(b)
		if a == b:
			return
		if self.size[a] < self.size[b]:
			(a, b) = (b, a)
		self.num_sets -= 1
		self.parent[b] = a
		self.size[a] += self.size[b]
		self.lista[a] += self.lista[b]

	def set_size(self, a):
		return self.size[self.find(a)]

	def __len__(self):
		return self.num_sets

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def prime_factors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

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

def fibonacci_modP(n, MOD):
	if n < 2:
		return 1
	return (cached_fn(fibonacci_modP, (n + 1) // 2, MOD) * cached_fn(fibonacci_modP, n // 2, MOD) + cached_fn(fibonacci_modP, (n - 1) // 2, MOD) * cached_fn(fibonacci_modP, (n - 2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n, p):
	if p <= n:
		return 0
	res = p - 1
	for i in range(n + 1, p):
		res = res * cached_fn(InverseEuler, i, p) % p
	return res

def binary(n, digits=20):
	b = bin(n)[2:]
	b = '0' * (digits - len(b)) + b
	return b

def is_prime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

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

def warm_up_fac(MOD):
	global factorial_modP, fac_warm_up
	if fac_warm_up:
		return
	factorial_modP = [1 for _ in range(fac_warm_up_size + 1)]
	for i in range(2, fac_warm_up_size):
		factorial_modP[i] = factorial_modP[i - 1] * i % MOD
	fac_warm_up = True

def InverseEuler(n, MOD):
	return pow(n, MOD - 2, MOD)

def nCr(n, r, MOD):
	global fac_warm_up, factorial_modP
	if not fac_warm_up:
		warm_up_fac(MOD)
		fac_warm_up = True
	return factorial_modP[n] * (pow(factorial_modP[r], MOD - 2, MOD) * pow(factorial_modP[n - r], MOD - 2, MOD) % MOD) % MOD

def get_int():
	return int(stdin.readline().strip())

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

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

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

def binary_search(i, li):
	fn = lambda x: li[x] - x // i
	x = -1
	b = len(li)
	while b >= 1:
		while b + x < len(li) and fn(b + x) > 0:
			x += b
		b = b // 2
	return x
TestCases = True
optimise_for_recursion = True

def make(x):
	global li
	if x == 2:
		return ('11337', 2)
	ind = bisect_left(li, x)
	if li[ind] == x:
		return ('1' + '3' * (ind + 2) + '7', ind + 2)
	else:
		ind -= 1
		(x, y) = make(x - li[ind])
		z = '1' + '3' * (ind + 2 - y) + x
		return (z, ind + 2)

def main():
	global li
	n = get_int()
	li = [i * (i - 1) // 2 for i in range(2, 10 ** 5)]
	print(make(n)[0])
if TestCases:
	for i in range(get_int()):
		main()
else:
	main() if not optimise_for_recursion else threading.Thread(target=main).start()


def bin_s(i, j, values, arr):
	while i < j:
		m = (i + j) // 2
		if arr[m] > values:
			j = m - 1
		else:
			i = m + 1
	if arr[i] > values:
		return i - 1
	else:
		return i
store = [0] * 10 ** 5
for i in range(2, 10 ** 5):
	store[i] = i * (i - 1) // 2
for _ in range(int(input())):
	n = int(input())
	stack = []
	i = 0
	j = 10 ** 5 - 1
	while n > 0:
		j = bin_s(2, j, n, store)
		stack.append(j)
		n -= store[j]
	stack.append(0)
	l = len(stack)
	stack = stack[::-1]
	st = '1'
	for i in range(1, len(stack)):
		st += '3' * (stack[i] - stack[i - 1])
		st += '7'
	print(st)


from heapq import heappush, heappop
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations
import sys
import bisect
sys.setrecursionlimit(10 ** 6)

def SI():
	return input().split()

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

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

def LI():
	return [int(i) for i in input().split()]
YN = ['Yes', 'No']
YNeos = 'YNeos'
GYN = ['Yes', 'trumpet']
mo = 10 ** 9 + 7
imp = 'IMPOSSIBLE'
t = I()
for _ in range(t):
	n = I()
	y = int((8 * 10 ** 4) ** 0.5)
	Y = y ** 2 + y + 1
	x = n // Y
	z = n % Y
	ans = '1' * x + '3' * y + '7' + '1' * z + '337'
	print(ans)


def closest(arr, pos):
	n = len(arr)
	low = 0
	up = n - 1
	while up >= low:
		mid = (up + low) // 2
		if arr[mid] == pos:
			return mid
		elif arr[mid] > pos:
			if arr[mid - 1] < pos:
				return mid - 1
			else:
				up = mid - 1
		elif arr[mid + 1] > pos:
			return mid
		else:
			low = mid + 1
t = int(input())
n = 1
a = []
while n < 100000:
	a.append(n * (n + 1) // 2)
	n += 1
for i in range(t):
	n = int(input())
	s = ['1', '3', '3']
	no3 = closest(a, n)
	no7 = n - a[no3]
	s.extend(['7'] * no7)
	s.extend(['3'] * no3)
	s.append('7')
	print(''.join(s))


for i in range(int(input())):
	n = int(input())
	x = 0
	while (x + 1) * x // 2 <= n:
		x += 1
	rem = n - x * (x - 1) // 2
	print('133' + '7' * rem + '3' * (x - 2) + '7')


from math import sqrt
t = int(input())
for i in range(0, t):
	n = int(input())
	if n < 10000:
		print('133' + n * '7')
		continue
	x = int(sqrt(2 * n))
	while x * (x - 1) > 2 * n:
		x -= 1
	while x * (x + 1) <= 2 * n:
		x += 1
	dif = n - int(x * (x - 1) / 2)
	print('133' + dif * '7' + (x - 2) * '3' + '7')


for _ in range(int(input())):
	n = int(input())
	l = 2
	while l * (l + 1) // 2 <= n:
		l += 1
	n -= l * (l - 1) // 2
	print('133' + '7' * n + '3' * (l - 2) + '7')


T = int(input())
for i in range(0, T):
	n = int(input())
	j = 0
	while j * (j - 1) / 2 <= n:
		j += 1
	j -= 1
	r = int(n - j * (j - 1) / 2)
	st = '1'
	for k in range(0, j):
		st += '3'
	st = list(st)
	st = st[:3] + ['7'] * r + st[3:] + ['7']
	print(''.join(st))


import sys
import math
input = sys.stdin.readline
arr = []
for i in range(1, 100000):
	arr.append(i * (i + 1) // 2)

def bs(l, r, x):
	if r >= l:
		mid = l + (r - l) // 2
		if arr[mid] <= x and arr[mid + 1] > x:
			return mid
		elif arr[mid] > x:
			return bs(l, mid - 1, x)
		else:
			return bs(mid + 1, r, x)
t = int(input())
for i in range(t):
	n = int(input())
	d = bs(0, len(arr) - 1, n)
	diff = n - arr[d]
	ans = ['1', '3', '3']
	for j in range(diff):
		ans.append('7')
	for j in range(d):
		ans.append('3')
	ans.append('7')
	print(''.join(ans))


import bisect
arr = [0, 0] + [i * (i - 1) // 2 for i in range(2, 100000)]
for t in range(int(input())):
	n = int(input())
	if n <= 10:
		print('1' + '33' + '7' * n)
		continue
	i = bisect.bisect_right(arr, n) - 1
	k = arr[i]
	ans = '1' + '33' + '7' * (n - k) + '3' * (i - 2) + '7'
	print(ans)


from sys import stdin
t = int(stdin.readline())
for case in range(t):
	n = int(stdin.readline())
	c = 0
	out = [1, 3]
	num = 1
	adder = 2
	while c < n:
		out.append(3)
		c += num
		num += 1
	if c > n:
		(out[0], out[1]) = (out[1], out[0])
		c -= num - 1
		out.pop()
		out.pop()
		out += [1] * (n - c)
		out += [3, 3]
	out += [7]
	print(''.join([str(x) for x in out]))


def main():
	import sys
	input = sys.stdin.readline
	for _ in range(int(input())):
		N = int(input())
		m = int((N - 1) ** 0.5)
		k = N - m ** 2
		if m <= 6:
			ans = [1] * N
			ans.append(3)
			ans.append(3)
			ans.append(7)
		else:
			a = m
			b = m - 6
			c = k
			d = 1
			while a + b + c + d + 4 > 10 ** 5:
				b += 1
				c -= m
			ans = [1] * a
			ans.append(3)
			ans.append(3)
			ans.extend([7] * b)
			ans.extend([1] * c)
			ans.append(3)
			ans.append(3)
			ans.append(7)
		print(''.join(map(str, ans)))
main()


import sys
t = int(sys.stdin.readline().strip())
for i in range(0, t):
	n = int(sys.stdin.readline().strip())
	c = 4 * 10 ** 2
	d = n // (c * (c - 1) // 2)
	b = n % (c * (c - 1) // 2)
	print('133' + '7' * b + '3' * (c - 2) + '7' * d)


def string_1337(n, L=[], first=True):
	j = int((2 * n) ** 0.5)
	if j * (j + 1) // 2 <= n:
		j += 1
	m = j * (j - 1) // 2
	print('1', '33', '7' * (n - m), '3' * (j - 2), '7', sep='')
n = int(input())
for _ in range(n):
	string_1337(int(input()), [])


from sys import stdin, stdout, setrecursionlimit
input = stdin.readline
inf = float('inf')
from functools import cmp_to_key
from collections import defaultdict as dd
from collections import Counter, deque
from heapq import *
import math
from math import floor, ceil, sqrt

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

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

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

def getls():
	return list(map(str, input().strip().split()))

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

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	for _ in range(geta()):
		n = geta()
		three = 2
		while three * (three - 1) // 2 <= n:
			three += 1
		three -= 1
		extra_7 = n - three * (three - 1) // 2
		ans = '1' + '3' * 2 + '7' * extra_7 + '3' * (three - 2) + '7'
		print(ans)
solve()


import sys
input = sys.stdin.readline

def getInt():
	return int(input())

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

def getArr():
	return list(map(int, input().split()))
c = []
i = 2
r = 1
while r < 10 ** 9:
	i += 1
	r = i * (i - 1) // 2
	c.append(r)
n = getInt()
res = {1: 0, 3: 0, 7: 0}
for _ in range(n):
	p = getInt()
	if p == 1:
		print('1337')
	elif p == 2:
		print('11337')
	else:
		for i in range(len(c) - 1, -1, -1):
			if c[i] <= p:
				index = i
				break
		print('1' + '3' * (index + 1), end='')
		print('1' * (p - c[index]) + '337')


import bisect
Q = int(input())
A = [n * (n - 1) // 2 for n in range(10 ** 5)]
x = bisect.bisect(A, 10 ** 9)
for testcases in range(Q):
	t = int(input())
	if t == 1:
		print(1337)
		continue
	x = bisect.bisect_left(A, t)
	ANS = '1' + '3' * (x - 1 - 2) + '1' * (t - A[x - 1]) + '337'
	print(ANS)


for _ in range(int(input())):
	n = int(input())
	t1 = 0
	while t1 * (t1 + 1) // 2 <= n:
		t1 += 1
	n -= t1 * (t1 - 1) // 2
	print('133' + '7' * n + (t1 - 2) * '3' + '7')


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		x = 2
		while x * (x + 1) // 2 <= n:
			x += 1
		rem = n - x * (x - 1) // 2
		print('1' + '33' + '7' * rem + '3' * (x - 2) + '7')
	return
main()