/*
Jackson Simoneau
SI@UCF 2026 - Intro to Competitive Programming
Contest 2

Solution to Lög: https://open.kattis.com/problems/log
*/

#include <bits/stdc++.h>
using namespace std;

int count(string &s) {
    int res = 0;
    for(char c : s) {
        if(c != ' ') res++; 
    }
    return res;
}

int main() {
    int t; cin >> t;
    while(t--) {
        int n; cin >> n;
        string name;
        getline(cin, name);
        getline(cin, name);
        int v = count(name);

        vector<string> res;
        for(int i = 0; i < n; i++) {
            string song;
            getline(cin, song);
            if(count(song) == v) res.push_back(song);
        }
        sort(res.begin(), res.end());

        cout << name << ":\n";
        for(string x : res) cout << x << endl;
    }
}