#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, F, ans = 0;
  cin >> N >> F;
  map< pair<string, string>, int > mp;
  rep(i, N) {
    int M;
    cin >> M;
    vector<string> vec;
    rep(j, M) {
      string item;
      cin >> item;
      vec.push_back(item);
    }
    rep(j, M) reps(k, j+1, M) {
      auto p = minmax(vec[j], vec[k]);
      if(mp.count(p)) mp[p]++;
      else mp[p] = 1;
      if(mp[p] == F) ans++;
    }
  }

  cout << ans << endl;
  for(auto p : mp) {
    if(p.second >= F) cout << p.first.first << " " << p.first.second << endl;
  }

  return 0;
}