#include <bits/stdc++.h>

using namespace std;


int main()
{
  map< pair< string, string >, int > cnt;
  int N, F;

  cin >> N >> F;
  for(int i = 0; i < N; i++) {
    int M;
    cin >> M;
    vector< string > QQ(M);
    for(int j = 0; j < M; j++) cin >> QQ[j];
    for(int j = 0; j < M; j++) {
      for(int k = 0; k < j; k++) cnt[minmax(QQ[j], QQ[k])]++;
    }
  }

  int ret = 0;
  for(auto &s : cnt) ret += s.second >= F;
  cout << ret << endl;
  for(auto &s : cnt) if(s.second >= F) cout << s.first.first << " " << s.first.second << endl;
}