//排列
#include<iostream>
using namespace std;
int main() {
int len, arr[1001];
while (cin >> len) {
for (int i = 0; i < len; i++) { //輸入
cin >> arr[i];
}
for (int i = 0; i < len; i++) {//使用泡沫排序法逐一比對
for (int j = i; j < len; j++) {
if (arr[i] % 10 > arr[j] % 10) { //比個位數
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
else if (arr[i] % 10 == arr[j] % 10) { //若個位數相等,比整個數字
if (arr[i] < arr[j]) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
cout << arr[i] << " ";
}
cout << endl;
}
return 0;
}