#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int N,F;
map<pair<string,string>,int> data;
vector<string> vec;

int main(){
	cin >> N >> F;
	int t;
	data = map<pair<string,string>,int>();
	for(int I = 0; I < N; I++){
		cin >> t;
		vec = vector<string>(t);
		for(int j = 0; j < t; j++){
			cin >> vec[j];
		}
		for(int i = 0; i < t; i++){
			for(int j = i+1; j < t; j++){
				pair<string,string> pr;
				if(vec[i] < vec[j]){
					pr.first = vec[i];
					pr.second = vec[j];
				}
				else{
					pr.first = vec[j];
					pr.second = vec[i];
				}

				map<pair<string,string>,int>::iterator itr = data.find(pr);
				if(itr == data.end()){
					data[pr] = 1;
				}
				else{
					itr->second += 1;
				}
			}
		}
	}
	vector<pair<string,string> > ans = vector<pair<string,string> >();
	for(map<pair<string,string>,int>::iterator itr = data.begin(); itr != data.end(); itr++){
		if(itr->second >= F){
			ans.push_back(itr->first);
		}
	}
	sort(ans.begin(),ans.end());
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++){
		cout << ans[i].first << " " << ans[i].second << endl;
	}
	return 0;
}