#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, F;
typedef pair<string, string> P;
P mp(string x, string y) {
  if (x > y) swap(x, y);
  return P(x, y);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> F;
  map<P, int> ctr;
  rep(i, N) {
    int m;
    cin >> m;
    vector<string> vs;
    rep(j, m) {
      string buf;
      cin >> buf;
      for (string &s : vs) ctr[mp(s, buf)]++;
      vs.pb(buf);
    }
  }
  vector<P> ans;
  for (auto p : ctr) {
    if (p._2 >= F) ans.pb(p._1);
  }
  assert(is_sorted(all(ans)));
  cout << ans.size() << "\n";
  for (auto p : ans) cout << p._1<< " " <<p._2<<"\n";
  return 0;
}