loop{
    degree = Hash.new(0)
    loop {
        i, j = gets.tap{|s| exit unless s}.split.map &:to_i
        break if i == 0
        degree[i] += 1
        degree[j] += 1
    }
    if degree.all?{|k, c| (k < 3) ^ c.even?}
        puts 'OK'
    else
        puts 'NG'
    end
}