#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);
 
int h, w;
string s[1010];
int sx, sy;
int gx, gy;

struct Point
{
    int y, x;
    Point(){};
    Point(int y, int x):y(y), x(x){};
    int getDistMan(const Point& p){
        return abs(x-p.x)+abs(y-p.y);
    }
};

vector<Point> p[5];

int dp[5][5][1010]; //initial__now__i_banme

int main(){
    while(cin>>w>>h && w && h){
        rep(i, 5) p[i].clear();
        rep(i, h) cin>>s[i];
        rep(i, h){
            rep(j, w){
                if(s[i][j]=='S'){
                    sy = i;
                    sx = j;
                    continue;
                }
                if(s[i][j]=='G'){
                    gy = i;
                    gx = j;
                    continue;
                }
                for(int k = 0; k < 5; k++){
                    if(s[i][j]==(char)(k+'1')){
                        p[k].pb(Point(i, j));
                        break;
                    }
                }
            }
        }
        // cout<<sy<<" "<<sx<<endl;
        // cout<<gy<<" "<<gx<<endl;
        // rep(i, 5){
        //     cout<<" "<<i<<" : ";
        //     rep(j, p[i].size()) cout<<" ("<<p[i][j].y<<" "<<p[i][j].x<<")";
        //     cout<<endl;
        // }
        // cout<<endl;

        vi ans(5, INF);
        int now, prv, last;
        for(int i = 0; i < 5; i++){//initial_Patimon_kind
            for(int j = 0; j < 5; j++){
                for(int k = 0; k < 1010; k++) dp[i][j][k] = INF;
            }
            last = (i+4)%5;
            for(int j = 1; j < 5; j++){
                now = (i+j)%5;
                prv = (i+j-1)%5;
                for(int k = 0; k < p[now].size(); k++){
                    if(j==1){
                        dp[i][now][k] = p[now][k].getDistMan(Point(sy, sx));
                        continue;
                    }
                    for(int l = 0; l < p[prv].size(); l++){
                        dp[i][now][k] = min(dp[i][now][k], dp[i][prv][l]+p[now][k].getDistMan(p[prv][l]));
                    }
                }
            }
            //cout<<" "<<i<<endl;
            for(int j = 0; j < p[last].size(); j++){
                ans[i] = min(ans[i], dp[i][last][j]+p[last][j].getDistMan(Point(gy, gx)));
                //cout<<" "<<dp[i][last][j];
            }
            //cout<<endl;
            //cout<<dp[0][2][0]<<endl;
        }
        //cout<<*max_element(all(ans))<<endl;
        //cout<<ans[1]<<endl;
        //cout<<dp[1][3][2]<<endl;
        //cout<<p[3].size()<<endl;
        int tmp = INF, idx = 0;
        for(int i = 0; i < 5; i++){
            if(tmp > ans[i]){
                tmp = ans[i];
                idx = i;
            }
        }
        if(tmp == INF){
            cout<<"NA"<<endl;
            continue;
        }
        cout<<idx+1<<" "<<tmp<<endl;
    }
}

Measured memory_bytes: 2416