#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
using IntPair = pair<int, int>;
vector<string> ans;
bool Cmp(const string& str1, const string& str2)
{
int sz1 = str1.size(), sz2 = str2.size();
if (sz1 == sz2)
return str1 < str2;
else
return sz1 < sz2;
}
int main()
{
int n;
cin >> n;
while (n--)
{
string str, num;
cin >> str;
int cnt = 0;
for (auto iter = str.begin(); iter != str.end(); iter++)
{
auto c = *iter;
if (isdigit(c))
{
if (num.size() == 1 &&
num.front() == '0')
num = c;
else
num += c;
}
else if (!num.empty())
{
ans.push_back(num);
num.clear();
}
}
if (!num.empty())
ans.push_back(num);
}
sort(ans.begin(), ans.end(), Cmp);
for (int i = 0; i < ans.size(); i++)
cout << ans[i] << endl;
}