#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << (x) << "\n"
using namespace std;
using point = pair< int,int >;
using ll = long long;

int main() {
    const int table[11] = {0, 0, 1, 3, 6, 10, 15, 21, 28, 36, 45};

    int n, f, m;
    cin >> n >> f;

    int cnt = 0;
    string str;
    map< string, int > mp;
    vector< string > vec;

    REP(i, n) {
        scanf("%d", &m);

        vec.clear();
        REP(j, m) {
            cin >> str;
            vec.push_back(str);
        }

        REP(j, m - 1) {
            FOR(k, j + 1, m) {
                string tmp = min(vec[j], vec[k]) + " " + max(vec[j], vec[k]);
                if (mp.find(tmp) == mp.end()) mp[tmp] = 1;
                else mp[tmp]++;
            }
        }

    }

    for (auto p : mp) {
        if (p.second >= f) {
            cnt++;
        }
    }
    OUT(cnt);

    for (auto p : mp) {
        if (p.second >= f) {
            OUT(p.first);
        }
    }


    return 0;
}


