#include<stdio.h>

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>

using namespace std ;


int main( void )
{
	int N ,F ;
	scanf( "%d %d" ,&N ,&F ) ;	--F ;

	int M ;
	set< string > pair ;
	multiset< string > pair_data ;

	int i ,j ,k ;
	for( i = 0 ; i < N ; ++i )
	{
		vector< string > food ;

		scanf( "%d" ,&M ) ;
		for( j = 0 ; j < M ; ++j )
		{	string in ;	cin >> in ;	food.push_back( in ) ;	}
		
		sort( food.begin() ,food.end() ) ;

		for( j = 0 ; j < M ; ++j )
		{
			for( k = j + 1 ; k < M ; ++k )
			{
				string str1 ,str2 ;
				str1 = min( food[ j ] ,food[ k ] ) ;
				str2 = max( food[ j ] ,food[ k ] ) ;

				string union_str = str1 + ' ' + str2 ;

				pair.insert( union_str ) ;
				pair_data.insert( union_str ) ;
			}
		}
	}

	vector< string > output ;
	set< string >::iterator itr ;
	for( itr = pair.begin() ; itr != pair.end() ; ++itr )
	{
		int cnt = pair_data.count( *itr ) ;

		if( cnt > F )
		{	output.push_back( *itr ) ;	}
	}

	cout << output.size() << "\n" ;
	for( i = 0 ; i < output.size() ; ++i )
	{	cout << output[ i ] << "\n" ;	}

	return 0 ;
}
