using namespace std;
#include <bits/stdc++.h>

int numRealChar(string& s);

int main() {

    string line;
    getline(cin, line);
    int nC = stoi(line);

    // Process cases.
    for (int i=0; i<nC; i++) {

        getline(cin, line);
        int n = stoi(line);

        string band;
        getline(cin, band);

        int limit = numRealChar(band);
        set<string> longsongs;

        for (int i=0; i<n; i++) {
            getline(cin, line);
            int thislen = numRealChar(line);
            if (thislen==limit)
                longsongs.insert(line);
        }

        cout << band << ":" << endl;
        for (auto x: longsongs)
            cout << x << endl;
    }

    return 0;
}

int numRealChar(string& s) {
    int res =0;
    for (int i=0; i<s.size(); i++)
        if (s[i] != ' ')
            res++;
    return res;
}
