#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <queue>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)

using namespace std;

int main(void){
  string s;
  while(cin>>s){
    set<string> se;
    queue<pair<string,int> > q;
    se.insert(s);
    q.push(make_pair(s,0));
    int cnt = 10;
    char a[3] = {'r','g','b'};
    string ans[3];
    rep(i,3){
      rep(j,s.size()){
        ans[i] += a[i];
      }
      //cout<<ans[i]<<endl;
    }
    bool find = true;
    while(true){
      if(q.size()==0)break;
  //    cout<<q.front().first<<" "<<q.front().second<<endl;
      pair<string,int> qq = q.front(); q.pop();
      string ss = qq.first;
      int n = qq.second;
      if(ss.size()==s.size()+2 ){
        break;
      }
      cnt ++;
      bool f = false;
      rep(i,3){
        if(ans[i] == ss){
          f = true;
          find = false;
          break;
        }
      }
      if(f)break;
      n++;
      rep(i,ss.size()-1){
        if(ss[i] != ss[i+1]){
          if((ss[i] == a[0] && ss[i+1] == a[1]) || (ss[i] == a[1] && ss[i+1] == a[0])){
            string word = ss.substr(0,i) + a[2] + a[2] + ss.substr(i+2,ss.size()-i+2);
            if(se.find(word) != se.end())continue;
            se.insert(word);
            q.push(make_pair(word,n));
            se.insert(word);
          }
          if((ss[i] == a[0] && ss[i+1] == a[2]) || (ss[i] == a[2] && ss[i+1] == a[0])){
            string word = ss.substr(0,i) + a[1] + a[1] + ss.substr(i+2,ss.size()-i+2);
            if(se.find(word) != se.end())continue;
            se.insert(word);
            q.push(make_pair(word,n));
            se.insert(word);
          }
          if((ss[i] == a[2] && ss[i+1] == a[1]) || (ss[i] == a[1] && ss[i+1] == a[2])){
            string word = ss.substr(0,i) + a[0] + a[0] + ss.substr(i+2,ss.size()-i+2);
            if(se.find(word) != se.end())continue;
            se.insert(word);
            q.push(make_pair(word,n));
            se.insert(word);
          }
        }
      }
    }
    if(find)cout<<"NA"<<endl;
  }
}