#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
using namespace std;

typedef pair<int,int> pi;
#define MK make_pair
#define F first
#define S second

int dp[100][4];
pi s[100]={};


bool search(int n){
    bool j=false;
    int t=s[n].F;
    int w=s[n].S;
    int td=s[n+1].F;
    int wd=s[n+1].S;
    if(dp[n][0]!=-1 && abs(wd-w)*2<=td-t){
        j=true;
        dp[n+1][1]=dp[n][0]+abs(wd-w);
    }
    if(dp[n][0]!=-1 && w*2+wd<=td-t){
        j=true;
        if(dp[n+1][0]==-1){
            dp[n+1][0]=dp[n][0]+w+wd;
        }
        else{
            dp[n+1][0]=min(dp[n][0]+w+wd,dp[n+1][0]);
        }
    }
    
    
    if(dp[n][1]!=-1 && abs(wd-w)*3<=td-t){
        j=true;
        dp[n+1][2]=dp[n][1]+abs(wd-w);
    }
    if(dp[n][1]!=-1 && w*3+wd<=td-t){
        j=true;
        if(dp[n+1][0]==-1){
            dp[n+1][0]=dp[n][1]+w+wd;
        }
        else{
            dp[n+1][0]=min(dp[n][1]+w+wd,dp[n+1][0]);
        }
    }
    
    
    if(dp[n][2]!=-1 && w*4+wd<=td-t){
        j=true;
        if(dp[n+1][0]==-1){
            dp[n+1][0]=dp[n][2]+w+wd;
        }
        else{
            dp[n+1][0]=min(dp[n][2]+w+wd,dp[n+1][0]);
        }
    }
    return j;
}




int main(){
    while(1){
        
        
        
    
    fill(&dp[0][0],&dp[99][4],-1);
    dp[0][0]=0;
    fill(s,s+100,MK(0,0));
    int n;
    cin>>n;
        if(n==0){break;}
    int w=0;
    for(int i=1;i<=n;i++){
        cin>>s[i].S>>s[i].F;
        if(i==n){w=s[i].S;}
    }
    int ans=-1;
    for(int i=0;i<n;i++){
        if(!search(i)){ans=i; break;}
    }
        /*
        for(int i=0;i<=n;i++){
            for(int t=0;t<3;t++){
                cout<<dp[i][t]<<" ";
            }
            cout<<endl;
        }
        */
        
    if(ans!=-1){
        cout<<"NG "<<ans+1<<endl;
        continue;
    }
    int dis=1e9;
        if(dp[n][0]!=-1){dis=dp[n][0]+w;}
        if(dp[n][1]!=-1){dis=min(dis,dp[n][1]+w);}
        if(dp[n][2]!=-1){dis=min(dis,dp[n][2]+w);}
    cout<<"OK "<<dis<<endl;
        
        
        
        
        
    }
    
    return 0;
}
