Listing: FUZZY.PAS   
 const max = 40; 
 var a:array[1..max,1..4,0..max] of    Byte; 
 type mat=array[1..max] of Boolean;    
 var b,c:mat; 
 n,start,stop:Byte; 
 ntest:Integer; 
 
 procedure init; 
 var i,j,k,t:Byte; 
 begin 
 Readln(start,stop); 
 for i:=1 to n do 
 for j:=1 to 4 do 
 begin 
 Read(k); 
 if k=0 
 
then
 begin 
a[i,j,0]:=0; Readln 
 end 
 else begin 
 t:=1; 
 a[i,j,t]:=k; 
 while not SeekEoln do 
 
begin
Read(k); 
 Inc(t); 
 a[i,j,t]:=k 
 end; 
 Readln; a[i,j,0]:=t 
 end 
 end 
 end; 
 function doit(s:string):Boolean; 
 var i,j,t:Byte; 
 begin 
 for i:=1 to max 
do
b[i]:=false; 
 b[start]:=true; 
 while s<>'' do 
 begin 
 j:=0; 
 if s[1]='N' then j:=1; 
 if s[1]='E' then j:=2; 
 if s[1]='S' then j:=3; 
 if s[1]='W' then j:=4; 
 Delete(s,1,1); 
 for i:=1 to max 
do
c[i]:=false; 
 if j=0 then Continue; 
 for i:=1 to n do 
 if b[i] 
then
 for t:=1 to a[i,j,0] 
do
c[a[i,j,t]]:=true; 
 b:=c 
 end; 
 doit:=b[stop] 
 end; 
 
 procedure process; 
 var s:string; 
 i,t:Byte; 
 begin 
 Readln(t); 
 for i:=1 to t do 
 begin 
 Readln(s); 
 if doit(s) 
 then Writeln('YES') 
 else Writeln('NO') 
 end; 
 Readln 
 end; 
 Begin 
 Assign(input,'A.DAT'); Reset(input); 
 Readln(n); 
 ntest:=1; 
 while n<>0 do 
 begin 
 init; 
 Writeln('Fuzzylad #',ntest,':'); 
 process; 
 Writeln; 
 Readln(n); 
 Inc(ntest) 
 end; 
 Close(input) 
 End.