#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	int n, f; cin >> n >> f;
	map<pair<string, string>, int> ma;
	rep(i, n) {
		int m; cin >> m;
		VS item(m); rep(j, m)cin >> item[j];
		for (int j = 0; j < m; j++) {
			for (int k = j + 1; k < m; k++) {
				string str1 = item[j], str2 = item[k];
				if (str1 > str2)swap(str1, str2);
				ma[mp(str1, str2)]++;
			}
		}
	}

	vector<pair<string, string>> p;
	for (auto aa : ma) {
		if (aa.second >= f)p.pb(aa.first);
	}
	sort(all(p));

	Cout(sz(p));
	for (auto aa : p) {
		Cout2(aa.first, aa.second);
	}
}
