#include <algorithm>
#include <array>
#include <set>
#include <unordered_map>
#include <vector>
class SortString {
  public:
    vector<string> sortStrings(vector<string> str, int n) {
        // write code here
        unordered_map<string, string> groups;
        for (auto s : str) {
            string key = s;
            sort(key.begin(), key.end());
            if (!groups.count(key) ||  groups.at(key) > s) {
                groups[key] = s;
            }
        }
        vector<string>res;
        for (auto &[k, v] : groups) {
            res.emplace_back(v);
        }
        sort(res.begin(), res.end());
        return  res;

    }
};