#include<iostream>
#include<vector>
#include<map>
#include<cstdlib>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int w,h;while(cin>>w>>h,w){
		int sy,sx,gy,gx,py[5][1000]={0},px[5][1000]={0},np[5]={0};
		rep(i,h){
			char buf[1001];cin>>buf;
			rep(j,w){
				if(buf[j]=='S')sy=i,sx=j;
				if(buf[j]=='G')gy=i,gx=j;
				if('0'<buf[j]&&buf[j]<'6'){
					int e=buf[j]-'1';
					py[e][np[e]]=i,px[e][np[e]]=j;
					np[e]++;
				}
			}
		}
		int cost[5][5][1000],ans=1<<20,ae;
		rep(i,5)rep(j,5)rep(k,1000)cost[i][j][k]=1<<20;
		for(int s_=1;s_<6;s_++){
			int s=s_%5;
			rep(i,np[s])cost[s][s][i]=abs(py[s][i]-sy)+abs(px[s][i]-sx);
			rep(i_,3){
				int i=(s+i_)%5,ni=(i+1)%5;
				rep(j,np[ni])rep(k,np[i])cost[s][ni][j]=min(cost[s][ni][j],
					cost[s][i][k]+abs(py[ni][j]-py[i][k])+abs(px[ni][j]-px[i][k])
				);
			}
			int l=(s+3)%5;
			rep(i,np[l]){
				int c=cost[s][l][i]+abs(gy-py[l][i])+abs(gx-px[l][i]);
				if(ans>c)ae=s,ans=c;
			}
		}
		if(ans==1<<20)cout<<"NA"<<endl;
		else cout<<(ae+4)%5+1<<" "<<ans<<endl;
	}
	return 0;
}