loop do
    n = gets.to_i
    break if n == 0
    bs = n.times.map{gets.split.map(&:to_i)}
    bs.push([0,50000])
    dp = Array.new(n+1).map{Array.new(4, Float::INFINITY)}
    if bs[0][1] < bs[0][0]
        puts "NG 1"
        next
    end
    pos = bs[0][0]
    time = bs[0][1]
    dp[0][0] = pos
    bl = true
    1.upto(n-1) do |i|
        bl = false
        b = bs[i]
        dist = (pos - b[0]).abs
        dt = (time - b[1]).abs
        0.upto(3) do |j|
            next if dp[i-1][j] == Float::INFINITY
            if (pos * (j + 2)) + b[0] <= dt
                bl = true
                dp[i][0] = dp[i-1][j] + pos + b[0] if dp[i-1][j] + pos + b[0] < dp[i][0]
            end
            if dist * (j + 2) <= dt && j < 2
                bl = true
                dp[i][j+1] = dp[i-1][j] + dist if dp[i-1][j] + dist < dp[i][j+1]
            end
        end
        pos = b[0]
        time = b[1]
        if !bl
            puts "NG #{i+1}"
            break
        end
    end
    0.upto(3) do |i|
        dp[n][i] = dp[n-1][i] + bs[n-1][0]
    end
    puts "OK #{dp[n].min}" if bl
end