#include<bits/stdc++.h>
#define rint register int
#define fu(i,a,b,d,c) for(rint i=a;i<=(b)&&c;i+=d)
#define fd(i,a,b,d,c) for(rint i=a;i>=(b)&&c;i-=d)
using namespace std;
const int L = 3,
R = 3,
N = 5,
M = 5,
K = 3,
P = 2,
LIMIT = 10,
TIMEL = 50;
inline int read(){
char c=0,f=1;int num=0;
while(c<'0'||c>'9'&&c!='-')((c=getchar())=='-')&&(f=-f);
while(c>='0'&&c<='9')num=(num<<1)+(num<<3)+(c^48),c=getchar();
return num*f;
}
int random(int a,int b){
return ((rand())%(b-a+1))+a;
}
int PIPE[55][55],cnt;
void PipeProduce(){
memset(PIPE,0,sizeof(PIPE));
fu(i,2,N,1,1){
fu(j,1,M-1,1,1){
int tp=random(0,3);
if(tp&1){
PIPE[i][j]+=1;
PIPE[i-1][j]+=4;
}
if(tp&2){
PIPE[i][j]+=2;
PIPE[i][j+1]+=8;
}
}
}
fu(i,1,N,1,1)fu(j,1,M,1,1)if(PIPE[i][j])cnt++;
if(cnt<=K)PipeProduce();
}
signed main(){
freopen("mouse.in","w",stdout);
srand(time(NULL));
printf("%d %d %d %d\n",L,R,N,M);
PipeProduce();
fu(i,1,N,1,1){
fu(j,1,M,1,1)printf("%d ",PIPE[i][j]);
putchar('\n');
}
printf("%d\n",K);
fu(i,1,K,1,1){
int pos=random(1,N*M);
#define toX (pos-1)/N+1
#define toY (pos-1)%N+1
while(!PIPE[toX][toY])pos=random(1,N*M);
int facing = random(1,4);
char fac=0;
if(facing==1)fac='N';
if(facing==2)fac='E';
if(facing==3)fac='S';
if(facing==4)fac='W';
int sex=random(1,2);
printf("%d %d %c %c\n",toX,toY,fac,sex==1?'X':'Y');
}
printf("%d %d\n",P,LIMIT);
int LasTime=1;
fu(i,1,P,1,1){
int pos=random(1,N*M);
#define toX (pos-1)/N+1
#define toY (pos-1)%N+1
while(!PIPE[toX][toY])pos=random(1,N*M);
int tp=random(1,4);
int tm=random(LasTime,(TIMEL-3)*i/P);
LasTime=tm;
printf("%d %d %d %d\n",tp,tm,toX,toY);
}
printf("%d\n",TIMEL);
}