#include <cstdio>
#include <cstring>
int main(int argc, char** argv) {
int n;
scanf("%d",&n);
while(n!=0){
int i,j;
int data[1000];
int ptr = 1;
for(i=1; i<=n; i=i+1){
scanf("%d", &data[i]);
}
int d[7];
for(d[1]=1; d[1]<=n-5; d[1]=d[1]+1){
for(d[2]=d[1]+1; d[2]<=n-4; d[2]=d[2]+1){
for(d[3]=d[2]+1; d[3]<=n-3; d[3]=d[3]+1){
for(d[4]=d[3]+1; d[4]<=n-2; d[4]=d[4]+1){
for(d[5]=d[4]+1; d[5]<=n-1; d[5]=d[5]+1){
for(d[6]=d[5]+1; d[6]<=n; d[6]=d[6]+1){
for(j=1; j<=6; j=j+1){
printf("%d ", data[d[j]]);
}
printf("\n");
}
}
}
}
}
}
scanf("%d",&n);
}
return 0;
}
//才不用什麼DFS呢哼