Buggy python submission (verdict: Runtime Error):
alphabets = {}
alphabets_num = {}
vartexs = []
fail_check = {}

class Vartex():
    def __init__(self, string):
        global alphabets
        self.ID = string
        self.link = []
        self.arrival = 0
        alphabets[string[0]].append(self)
        alphabets_num[string[0]] += 1
        return

    def register(self, new_vartex):
        self.link.append(new_vartex)
        return

def check_all(vartexs):
    for content in vartexs:
        if not content.arrival:
            return False
    return True

def dfs(start_vartex):
    global vartexs
    start_vartex.arrival = 1
    for link_vartex in start_vartex.link:
        if link_vartex.arrival:
            if check_all(vartexs):
                return True
            else :
                continue
        else:
            if dfs(link_vartex):
                return True
            else:
                continue
    start_vartex.arrival = 0
    return False


while True:
    alphabets = {}
    alphabets_num = {}
    vartexs = []
    fail_check = {}
    for al in range(ord("a"), ord("z")+1):
        alphabets[chr(al)] = []
        alphabets_num[chr(al)] = 0
        fail_check[chr(al)] = 0

    n = int(raw_input())
    if not n:
        break

    for x in range(n):
        vartexs.append(Vartex(raw_input()))
    
    for x in range(n):
        vartex = vartexs[x]
        string = vartex.ID
        fail_check[string[-1]] += 1
        for content in alphabets[string[-1]]:
            vartex.register(content)
    
    if alphabets_num != fail_check:
        print "NG"
    else :
        start = vartexs[0]
        if dfs(start):
            print "OK"
        else:
            print "NG"

Fixed submission:
alphabets = {}          #This is dict for reference by word's first character
alphabets_num = {}      #saves numbar of that
vartexs = []            #all vertices come out in a single operation
fail_check = {}         #for the check to avoid unnecessary search
 
class Vartex():
    def __init__(self, string):
        global alphabets
        self.ID = string
        self.link = []
        self.hasArrived = False
        return
 
    def register(self, new_vartex):
        self.link.append(new_vartex)
        return

def hasAllArrived(vartexs):
    for content in vartexs:
        if not content.hasArrived:
            return False
    return True
 
def dfs(start_vartex, vartex_list):
    global vartexs

    start_vartex.hasArrived = True

    for link_vartex in start_vartex.link:
        if link_vartex.hasArrived:
            if hasAllArrived(vartex_list):
                return True
            else :
                continue
        else:
            if dfs(link_vartex, vartex_list):
                return True
            else:
                continue
    start_vartex.hasArrived = False
    return False
 
 
while True:
#initalize for global variabale
    alphabets = {}
    alphabets_num = {}
    vartexs = []
    fail_check = {}

    for al in range(ord("a"), ord("z")+1):
        alphabets[chr(al)] = []
        alphabets_num[chr(al)] = 0
        fail_check[chr(al)] = 0
 
#bug appears for some reason without this processing
    s = raw_input()
    if s == '':
        continue
 
    n = int(s)
 
    if not n:
        break
 
    for x in range(n):
        word = raw_input()
        vartex = Vartex(word)
        vartexs.append(vartex)
        alphabets[word[0]].append(vartex)
        alphabets_num[word[0]] += 1
     
    for x in range(n):
        vartex = vartexs[x]
        string = vartex.ID
        fail_check[string[-1]] += 1
        for content in alphabets[string[-1]]:
            vartex.register(content)

#list of the first characters and the last characters must be consistent

    if alphabets_num != fail_check:
        print "NG"
        continue

#depth-first search
    start = vartexs[0]
    if dfs(start, vartexs):
        print "OK"
    else:
        print "NG"

Buggy python submission (verdict: Runtime Error):
alphabets = {}
alphabets_num = {}
vartexs = []
fail_check = {}

class Vartex():
    def __init__(self, string):
        global alphabets
        self.ID = string
        self.link = []
        self.arrival = 0
        alphabets[string[0]].append(self)
        alphabets_num[string[0]] += 1
        return

    def register(self, new_vartex):
        self.link.append(new_vartex)
        return

def check_all(vartexs):
    for content in vartexs:
        if not content.arrival:
            return False
    return True

def dfs(start_vartex):
    global vartexs
    start_vartex.arrival = 1
    for link_vartex in start_vartex.link:
        if link_vartex.arrival:
            if check_all(vartexs):
                return True
            else :
                continue
        else:
            if dfs(link_vartex):
                return True
            else:
                continue
    start_vartex.arrival = 0
    return False


while True:
    alphabets = {}
    alphabets_num = {}
    vartexs = []
    fail_check = {}
    for al in range(ord("a"), ord("z")+1):
        alphabets[chr(al)] = []
        alphabets_num[chr(al)] = 0
        fail_check[chr(al)] = 0

    n = int(raw_input())
    if n == 0:
        break

    for x in range(n):
        vartexs.append(Vartex(raw_input()))
    
    for x in range(n):
        vartex = vartexs[x]
        string = vartex.ID
        fail_check[string[-1]] += 1
        for content in alphabets[string[-1]]:
            vartex.register(content)
    
    if alphabets_num != fail_check:
        print "NG"
    else :
        start = vartexs[0]
        if dfs(start):
            print "OK"
        else:
            print "NG"

Fixed submission:
alphabets = {}          #This is dict for reference by word's first character
alphabets_num = {}      #saves numbar of that
vartexs = []            #all vertices come out in a single operation
fail_check = {}         #for the check to avoid unnecessary search
 
class Vartex():
    def __init__(self, string):
        global alphabets
        self.ID = string
        self.link = []
        self.hasArrived = False
        return
 
    def register(self, new_vartex):
        self.link.append(new_vartex)
        return

def hasAllArrived(vartexs):
    for content in vartexs:
        if not content.hasArrived:
            return False
    return True
 
def dfs(start_vartex, vartex_list):
    global vartexs

    start_vartex.hasArrived = True

    for link_vartex in start_vartex.link:
        if link_vartex.hasArrived:
            if hasAllArrived(vartex_list):
                return True
            else :
                continue
        else:
            if dfs(link_vartex, vartex_list):
                return True
            else:
                continue
    start_vartex.hasArrived = False
    return False
 
 
while True:
#initalize for global variabale
    alphabets = {}
    alphabets_num = {}
    vartexs = []
    fail_check = {}

    for al in range(ord("a"), ord("z")+1):
        alphabets[chr(al)] = []
        alphabets_num[chr(al)] = 0
        fail_check[chr(al)] = 0
 
#bug appears for some reason without this processing
    s = raw_input()
    if s == '':
        continue
 
    n = int(s)
 
    if not n:
        break
 
    for x in range(n):
        word = raw_input()
        vartex = Vartex(word)
        vartexs.append(vartex)
        alphabets[word[0]].append(vartex)
        alphabets_num[word[0]] += 1
     
    for x in range(n):
        vartex = vartexs[x]
        string = vartex.ID
        fail_check[string[-1]] += 1
        for content in alphabets[string[-1]]:
            vartex.register(content)

#list of the first characters and the last characters must be consistent

    if alphabets_num != fail_check:
        print "NG"
        continue

#depth-first search
    start = vartexs[0]
    if dfs(start, vartexs):
        print "OK"
    else:
        print "NG"