const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let dataLenth = 0;
const strArr = [];
rl.on("line", function (line) {
// const tokens = line.split(' ');
// console.log(parseInt(tokens[0]) + parseInt(tokens[1]));
if (dataLenth === 0) {
dataLenth = +line;
} else {
strArr.push(line);
dataLenth--;
if (dataLenth === 0) {
strArr.sort((a, b) => {
const length = Math.min(a.length, b.length);
for (let i = 0; i < length; i++) {
if (a[i] === b[i]) {
continue;
} else if (a[i] < b[i]) {
return -1;
} else {
return 1;
}
}
return a.length > b.length ? 1: -1;
});
strArr.forEach((item) => {
console.log(item);
});
}
}
});