#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)

const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};

bool in_range(int x, int mn, int mx) { return mn <= x && x < mx; }
bool in_range(int x, int y, int w, int h) { return in_range(x, 0, w) && in_range(y, 0, h); }

struct State { int x, y, c; };

int H, W, dst[1010][1010][55], sx, sy, gx, gy;
string grid[1010];

int solve(int init_c) {
	memset(dst, -1, sizeof(dst));
	
	queue< State > que;
	que.push(State{sx, sy, 1 << init_c});
	
	dst[sy][sx][1 << init_c] = 0;
	
	while (!que.empty()) {
		State s = que.front(); que.pop();
		
		if (s.c == (1 << 5) - 1 && s.x == gx && s.y == gy) {
			return dst[s.y][s.x][s.c];
		}
		
		int step = dst[s.y][s.x][s.c];
		
		for_(d,0,4) {
			int nx = s.x + dx[d], ny = s.y + dy[d];
			
			if (!in_range(nx, ny, W, H)) continue;
			
			int nc = s.c;
			
			if (isdigit(grid[ny][nx])) {
				int c = (grid[ny][nx] - '1');
				int b = (c + 4) % 5;
				
				if (s.c >> b & 1) nc |= 1 << c;
			}
			
			if (dst[ny][nx][nc] == -1) {
				dst[ny][nx][nc] = step + 1;
				que.push(State{nx, ny, nc});
			}
		}
	}
	
	return (int)1e9;
}

int main() {
	while (cin >> W >> H, W) {		
		for_(i,0,H) {
			cin >> grid[i];
			for_(j,0,W) {
				if (grid[i][j] == 'S') { sx = j; sy = i; }
				if (grid[i][j] == 'G') { gx = j; gy = i; }
			}
		}
		
		int ansc = 0, mini = (int)1e9;
		
		for_(i,0,5) {
			int res = solve(i);
			
			if (mini > res) {
				mini = res;
				ansc = i;
			}
		}
		
		if (mini < (int)1e9) cout << ansc + 1 << " " << mini << endl;
		else cout << "NA" << endl;
	}
}