#include using namespace std; using ll = long long; const bool adhoc_comparator(const string &a, const string &b) { ll check_len = min(a.size(), b.size()); for (ll i = 0; i < check_len; i++) { if (a[i] != b[i]) { return a[i] > b[i]; } } return a.size() < b.size(); } int main() { ll n, k; cin >> n >> k; vector v(n); for (ll i = 0; i < n; i++) { cin >> v[i]; } sort(v.begin(), v.end(), adhoc_comparator); for (ll i = 0; i < k; i++) { for (ll j = 0; j < n; j++) { cout << v[j]; } cout << endl; next_permutation(v.begin(), v.end(), adhoc_comparator); } cout << endl; }