#include <stdio.h>

#define DEBUG 0

#define MATCHED 1
#define UN_MATCHED 0
#define LAP_1 4

/* ?????¢????????¨????§??????? */
typedef struct {
	short top_surf;
	short front_surf;
	short right_surf;
	short left_surf;
	short back_surf;
	short bottom_surf;
} hexahedron;

/* ?§???????????????????????????? */
void init_dice(hexahedron *data);

/* ?????¢???????????? */
short comp_hexahedron(hexahedron dice1, hexahedron dice2);

/* ?????¢???????????¢????????? */
void rotate(hexahedron *dice, char rotate);

/* N?????????????????¢????????? */
void rotate_N(hexahedron *dice);

/* W?????????????????¢????????? */
void rotate_W(hexahedron *dice);

/* ?????¢??¨?????¢????????????????¨??????????90?°?????¢????????? */
void rotate_clockwise(hexahedron *dice);

/* ?????¢???????????´????????????????¢???? */
short is_match_hexahedron(hexahedron dice1, hexahedron dice2);

/* ?????¢???????????¢????????´????????????????¢???? */
short is_match_facetoface(short face11, short face12, short face21, short face22);

/* ???????????°??¨????§????????????±??¨?????¢??° */
void dbg_show(char *s, hexahedron d)
{
	printf("%s\n", s);
	printf("top_surf = %hd\n", d.top_surf);
	printf("front_surf = %hd\n", d.front_surf);
	printf("right_surf = %hd\n", d.right_surf);
	printf("left_surf = %hd\n", d.left_surf);
	printf("back_surf = %hd\n", d.back_surf);
	printf("bottom_surf = %hd\n", d.bottom_surf);
}

int main(void)
{
	short n;
	scanf("%hd", &n);
	
	hexahedron hex_array[n];
	
	short ii;
	for( ii = 0; ii < n; ii++ )
	{
		init_dice(&hex_array[ii]);
		scanf("%hd %hd %hd %hd %hd %hd", &hex_array[ii].top_surf, &hex_array[ii].front_surf,
				&hex_array[ii].right_surf, &hex_array[ii].left_surf, &hex_array[ii].back_surf, &hex_array[ii].bottom_surf);
	}
	
	
	short comp_result = 0;
	for( ii = 1; ii < n; ii++ )
	{
		comp_result = comp_hexahedron(hex_array[0], hex_array[ii]);
		if( comp_result )
		{
			break;
		}
	}
	
	if( comp_result )
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}
	
	return 0;
}

/* ?§??????????????????????????????¢??° */
void init_dice(hexahedron *data)
{
	data->top_surf = 0;
	data->front_surf = 0;
	data->right_surf = 0;
	data->left_surf = 0;
	data->back_surf = 0;
	data->bottom_surf = 0;
}
	
/* ?????¢???????????? */
short comp_hexahedron(hexahedron dice1, hexahedron dice2)
{
	short ii, is_matched = 0;
	// ?????¢??¨?????¢???????????¢?????????
	for( ii = 0; ii < LAP_1; ii++ )
	{
		// ???????????¢????????´??????????¢????
		if( is_match_facetoface(dice1.top_surf, dice1.bottom_surf,
			dice2.top_surf, dice2.bottom_surf) )
		{
			is_matched = MATCHED;
			break;
		}
		// N??????????????¢
		rotate_N(&dice2);
	}
	
	// ?????¢??¨?????¢???????????¢???????????§?????????????????´???
	if( UN_MATCHED == is_matched )
	{
		for( ii = 0; ii < LAP_1; ii++ )
		{
			// ???????????¢????????´??????????¢????
			if( is_match_facetoface(dice1.top_surf, dice1.bottom_surf,
				dice2.top_surf, dice2.bottom_surf) )
			{
				is_matched = MATCHED;
				break;
			}
			// W??????????????¢
			rotate_W(&dice2);
		}
	}
	
	// ?????¢????????¢???????????¢????????¨???????????´???
	if( UN_MATCHED == is_matched )
	{
		return is_matched;
	}
	
	is_matched = UN_MATCHED;
	for( ii = 0; ii < LAP_1; ii++ )
	{
		// ?????¢????????´??????????¢????
		if( is_match_hexahedron(dice1, dice2) )
		{
			is_matched = MATCHED;
			break;
		}
		// ?????¢??¨?????¢???????????????????¨??????????90?°?????¢?????????
		rotate_clockwise(&dice2);
	}
	
	return is_matched;
}

/*
N?????????????????¢?????????
????????¢????????¢?????????
????????¢????????¢?????????
????????¢?????£??¢?????????
?????£??¢????????¢?????????
????????????????????¢??¨?????¢?????\??????????????????
*/
void rotate_N(hexahedron *dice)
{
	short temp = dice->top_surf;
	dice->top_surf = dice->front_surf;
	dice->front_surf = dice->bottom_surf;
	dice->bottom_surf = dice->back_surf;
	dice->back_surf = temp;
}

/*
W?????????????????¢?????????
????????¢????????¢?????????
????????¢????????¢?????????
????????¢????????¢?????????
????????¢????????¢????????????
?????????????????£??¢??¨?????¢?????\??????????????????
*/
void rotate_W(hexahedron *dice)
{
	short temp = dice->left_surf;
	dice->left_surf = dice->top_surf;
	dice->top_surf = dice->right_surf;
	dice->right_surf = dice->bottom_surf;
	dice->bottom_surf = temp;
}

/*
?????¢??¨?????¢???????????????????¨??????????90?°?????¢?????????
????????¢?????£??¢?????????
?????£??¢????????¢?????????
????????¢????????¢?????????
????????¢????????¢?????????
????????¢??¨?????¢?????\??????????????????
*/
void rotate_clockwise(hexahedron *dice)
{
	short temp = dice->front_surf;
	dice->front_surf = dice->right_surf;
	dice->right_surf = dice->back_surf;
	dice->back_surf = dice->left_surf;
	dice->left_surf = temp;
}

/* ?????¢???????????´????????????????¢???? */
short is_match_hexahedron(hexahedron dice1, hexahedron dice2)
{
#if DEBUG == 1
	dbg_show("dice1", dice1);
	dbg_show("dice2", dice2);
#endif
	
	// ?????¢????????¢????????´????????????????¢????
	if( !is_match_facetoface(dice1.top_surf, dice1.bottom_surf, dice2.top_surf, dice2.bottom_surf) )
	{
		return UN_MATCHED;
	}
	// ?????¢????????¢????????´????????????????¢????
	if( !is_match_facetoface(dice1.right_surf, dice1.left_surf, dice2.right_surf, dice2.left_surf) )
	{
		return UN_MATCHED;
	}
	// ?????¢????????¢????????´????????????????¢????
	if( !is_match_facetoface(dice1.front_surf, dice1.back_surf, dice2.front_surf, dice2.back_surf) )
	{
		return UN_MATCHED;
	}
	return MATCHED;
}

/* ?????¢???????????¢????????´????????????????¢???? */
short is_match_facetoface(short face11, short face12, short face21, short face22)
{
	if( face11 != face21 )
	{
		return UN_MATCHED;
	}
	if( face12 != face22 )
	{
		return UN_MATCHED;
	}
	return MATCHED;
}

Measured memory_bytes: 580