#include <stdio.h>
#include <stdlib.h>
int nc6( int n ) { // nC6 함수
int res = 1;
int i;
for( i = 0; i < 6; i++ )
res *= n-i;
res /= 720;
return res;
}
int dscanf( int *pnum ) {
scanf("%d", pnum);
return *pnum;
}
void main()
{
int n;
int *nums;
int dmy[6]; // dummy variable set
int i, j, k;
while( dscanf(&n) != 0 ) {
nums = (int *)malloc(sizeof(int) * n);
for( i = 0; i < n; i++ )
scanf("%d", &nums[i]);
for( i = 0; i < 6; i++ )
dmy[i] = i;
for( i = 0; i < nc6(n); i++ ) {
for( j = 0; j < 6; j++ ) {
printf("%d", nums[dmy[j]]);
if( j != 5 ) printf(" ");
else printf("\n");
}
dmy[5]++;
for( j = 0; j < 5; j++ ) {
if( dmy[5-j] == n-j ) {
dmy[5-j-1]++;
for( k = 5-j; k < 6; k++ )
dmy[k] = dmy[k-1] + 1;
}
}
}
printf("\n");
free(nums);
}
}