#define K scanf("%d",
#define I(x)for(x=N;--x;)
#define L(a,b,c)I(i)I(j)if(k[i][j])b=b>a?b:a,c=a<c?a:c;b-=c-1;
N=404;main(c,i,j,l,e,f,g,h,n,d){int k[N][N],m[N],o[N];for(;c;){I(i)I(j)l=k[i][j]=m[j]=o[j]=0;e=g=m[0]=o[0]=(f=h=N)/2;K&c);if(k[e][e]=c){for(;--c;K&d),d/2?i=3-d,j=2-d:(i=d-1,j=d),d=m[n]+i,n=o[n]+j,k[d][n]=m[++l]=d,o[l]=n)K&n);L(i,e,f)L(j,g,h)c=printf("%d %d\n",e,g);}}}