#include <iostream>
#include <algorithm>
#define INF 1000000000;
using namespace std;
int n,dis[41],t[41],maxball,ans,memo[3][41];

void saiki(int x,int now,int ball,int sum,int kai){
  maxball=max(maxball,kai);
  if(kai==n&&!ball)ans=min(ans,sum);

  if(ball)saiki(0,now+x*(1+ball),0,sum+x,kai);
  if(ball==3||kai==n) return;
  
  int nx=dis[kai];
  int nsum=sum+abs(x-nx);
  int nnow=now+abs(x-nx)*(1+ball);
  if(nnow<=t[kai]&&memo[ball][kai]>nsum){
    memo[ball][kai]=nsum;
    saiki(nx,t[kai],ball+1,nsum,kai+1);
  }
}

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<3;i++)
      for(int j=0;j<n;j++) memo[i][j]=INF;
    for(int i=0;i<n;i++)cin >>dis[i]>>t[i];
  
    maxball=0,ans=INF;
    saiki(0,0,0,0,0);
    if(maxball==n)cout <<"OK "<<ans<<endl;
    else cout<<"NG "<<maxball+1<<endl;
  }
  return 0;
}