loop do
    require 'set'
    n = gets.to_i
    break if n == 0
    nodes = Set.new
    g = {}
    deg = Hash.new(0)
    n.times do
        s = gets.chomp
        u, v = s[0], s[-1]
        (g[u] ||= []) << v
        deg[u] += 1
        deg[v] -= 1
        nodes += [u, v]
    end
    queue = [g.keys[0]]
    reached = Set[*queue]
    until queue.empty?
        u = queue.shift
        (g[u] || []).each do |v|
            next if reached.include?(v)
            queue << v
            reached << v
        end
    end
    if reached.size < nodes.size
        puts 'NG'
    elsif deg.values.all?{|x| x == 0}
        puts 'OK'
    else
        puts 'NG'
    end
end

