#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, F;

    map < pair < string , string >, int > mp;
    vector < pair < string , string > > ans;
    cin >> N >> F;

    for ( int i = 0; i < N; i++ ) {
        int M;
        string S[10];
        cin >> M;
        for ( int j = 0; j < M; j++ ) {
            cin >> S[j];
        }
        for ( int j = 0; j < M; j++ ) {
            for ( int k = j + 1; k < M; k++ ) {
                string s = S[j], t = S[k];
                if ( s > t ) swap(s, t);
                auto d = make_pair(s, t);
                if ( mp.find(d) == mp.end() ) {
                    mp[d] = 1;
                } else {
                    mp[d]++;
                }
                if ( mp[d] == F ) {
                    ans.push_back(d);
                }
            }
        }
    }

    sort(begin(ans), end(ans));

    cout << ans.size() << endl;

    for ( auto &d : ans ) {
        cout << d.first << " " << d.second << endl;
    }

    return ( 0 );
}

