#include <bits/stdc++.h>
using namespace std;
const string a[120] = {"", "", "1", "7", "4", "2", "0", "8", "10", "18", "22", "20", "28", "68", "88", "108", "188", "200", "208"};
int n, T;
string tmp;
int main()
{
cin >> T;
while (T--)
{
tmp = "";
cin >> n;
if (n == 1)
{
cout << "-1\n";
continue;
}
if (n == 6)
{
cout << "6\n";
continue;
}
while (n >= 19)
{
tmp.push_back('8');
n -= 7;
}
string t = a[n];
reverse(t.begin(), t.end());
tmp = tmp + t;
reverse(tmp.begin(), tmp.end());
cout << tmp << '\n';
}
return 0;
}
当火柴数量大于8根时候,一般情况下数量越大组成数值越大,但是10根组成22与11根组成20不符合这样的规律,因此,10+7根18根组成228与11+7组成208就不符合最优,17->200 18->208,所有最后会剩下10根或11根的转换成17根与18根处理。那么总体符合每次选择7根构成8,位数最少,数值最小的规律。