#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;


int main(){

    while(true){
	int x,y;
	int sx,sy,gx,gy;
	int dx[] = {-1,0,0,1};
	int dy[] = {0,-1,1,0};
	cin >> x >> y;
	if(x == 0 && y == 0) break;
	vector< vector<char> > map(y,vector<char>(x));
	REP(i,y)REP(j,x){
	    cin >> map[i][j];
	    if(map[i][j] == 'S'){
		sx = j;
		sy = i;
	    }else if(map[i][j] == 'G'){
		gx = j;
		gy = i;
	    }
	}

	vector< vector<bool> > u(y,vector<bool>(x,false));
	pair<int ,int> ans;
	ans.first = 100000000;
	ans.second = 0;
	REP(a,5){
	    char ds = (char)('0' + 2 + a); 
	    int c = 0;
	    int tx,ty,v;
	    queue< pair<int,int> > qx;
	    queue<int> qy;
	    qx.push( pair<int,int>(sx,0) );
	    qy.push(sy);
	    while(!qx.empty()){
		tx = qx.front().first;
		v = qx.front().second;
		ty = qy.front();
		qx.pop();
		qy.pop();
		REP(i,4){
		    int nx = tx + dx[i];
		    int ny = ty + dy[i];
		    if(nx<0 || x<=nx || ny<0 || y<=ny) continue;
		    if(c < 4 && map[ny][nx] == ds ){
			c++;
			u = vector< vector<bool> >(y,vector<bool>(x,false));
			ds = (char)( (int)(ds-'0'+1)%6 + '0');
			if(ds == '0') ds = '1';
		    }
		    if(c == 4 && map[ny][nx] == 'G'){
			break;
		    }
		    if(!u[ny][nx]){
			u[ny][nx] = true;
			qx.push( pair<int,int>(nx,v+1));
			qy.push(ny);
		    }
		}
	    }
	    if(qx.empty() && c == 4) {
		if(ans.first > v+1){
		    ans.first = v+1;
		    ans.second = a+1;
		}
	    }
	}
	if(ans.first < 100000000) cout << ans.second << " " << ans.first << endl;
	else cout << "NA" << endl;
    }
    return 0;
}