function BFS(X,Y,C,S){
   var dx=[0,-1,1,0];
   var dy=[-1,0,0,1];
   var bfs=[[X,Y,C,S]];
   var obj={};
   obj[""+X+Y+S]=true;
   var cnt;
   var memo=[];
   for(var i=0;i<1000;i++){
      memo[i]=[];
      for(var j=0;j<1000;j++){  
         memo[i][j]=0;
      }
   }
   while(true){
      if(bfs.length==0){cnt=Infinity;break;}
      var leaf=bfs.shift();
      var x=leaf[0];
      var y=leaf[1];
      var c=leaf[2];
      var s=leaf[3];
      if(s==""){cnt=c;break;}
      for(var i=0;i<4;i++){
         var xx=x+dx[i];
         var yy=y+dy[i];
         var ss=s;
         if(xx<0 || yy<0 || xx>=wh[0] || yy>=wh[1])continue;
         if(yx[yy][xx]===ss[0]){
            if(memo[yy][xx]!==0 && memo[yy][xx]<c)continue;
            memo[yy][xx]=c;
            ss=ss.slice(1);
         }
         var str=""+xx+yy+ss;
         if(obj.hasOwnProperty(str))continue;
         obj[str]=true;
         bfs.push([xx,yy,c+1,ss]);
      }
   }
   return cnt;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var wh=(Arr.shift()).split(" ").map(Number);
   if(wh[0]==0 && wh[1]==0)break;
   var yx=[];
   var start=[];
   for(var i=0;i<wh[1];i++){
      var arr=(Arr.shift()).split("");
      if(arr.indexOf("S")!=-1)start=[arr.indexOf("S"),i]
      yx.push(arr);
   }
   var ans=[];
   ans.push([BFS(start[0],start[1],0,"2345G"),1]);
   ans.push([BFS(start[0],start[1],0,"3451G"),2]);
   ans.push([BFS(start[0],start[1],0,"4512G"),3]);
   ans.push([BFS(start[0],start[1],0,"5123G"),4]);
   ans.push([BFS(start[0],start[1],0,"1234G"),5]);
   ans.sort(function(a,b){
      if(a[0]===b[0])return a[1]-b[1];
      else return a[0]-b[0];
   });
   console.log((ans[0][0]==Infinity)?"NA":ans[0][1]+" "+ans[0][0]);
}