#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll MOD = 1e9+7;
const bool debug = 0;

int N, F;
map<pair<string, string>, int> m;

int main() {
	cin >> N >> F;
	REP(i, N) {
		int M; cin >> M;
		vector<string> item(M);
		REP(j, M) cin >> item[j];
		sort(ALL(item));
		REP(j, M) FOR(k, j + 1, M) m[make_pair(item[j], item[k])]++;
	}
	
	vector<pair<string, string> > ans;
	for (map<pair<string, string>, int>::iterator it = m.begin(); it != m.end(); ++it) {
		if (it->se >= F) ans.push_back(it->fi);
	}
	
	cout << ans.size() << endl;
	REP(i, ans.size()) cout << ans[i].fi << " " << ans[i].se << endl;
	
	return 0;
}