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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

typedef long long lint;

const int iINF = 1L << 30;
const lint lINF = 1LL << 60;

int n, p[55], t[55];

void solve() {
	int dp[50][4];
	minit(dp, -1);
	
	if (p[0] > t[0]) {
		cout << "NG " << 1 << endl;
		return;
	}
	
	dp[1][1] = p[0];
	for_(i,1,n) {
		for_(k,1,4) {
			if (dp[i][k] == -1) continue;
			bool flag = false;
			
			int pos = p[i - 1];
			int time = t[i - 1];
			
			int dist = abs(p[i] - pos);
			int nxt = dist * (k + 1);
			
			if (k < 3 && time + nxt <= t[i]) {
				flag = true;
				if (dp[i + 1][k + 1] == -1) dp[i + 1][k + 1] = dp[i][k] + dist;
				else dp[i + 1][k + 1] = min(dp[i + 1][k + 1], dp[i][k] + dist);
			}
			
			dist = pos + p[i];
			nxt = pos * (k + 1) + p[i];
			if (time + nxt <= t[i]) {
				flag = true;
				if (dp[i + 1][1] == -1) dp[i + 1][1] = dp[i][k] + dist;
				else dp[i + 1][1] = min(dp[i + 1][1], dp[i][k] + dist);
			}
			
			if (!flag) dp[i][k] = iINF;
		}
	}
	
	int ans = iINF;
	for_(k,0,4) if (dp[n][k] != -1) ans = min(ans, dp[n][k] + p[n - 1]);
	if (ans != iINF) {
		cout << "OK " << ans << endl;
	} else {
		for_rev(i,n - 1, 0) {
			for_(k,0,4) {
				if (dp[i][k] == iINF) {
					cout << "NG " << i + 1 << endl;
					return;
				}
			}
		}
	}
}

int main() {
	while (cin >> n, n) {
		for_(i,0,n) cin >> p[i] >> t[i];
		solve();
	}
	return 0;
}