def str_check() -> str:
"""
param str1:
return: str
"""
import sys
res = []
for str_input in sys.stdin:
str_input = str_input.strip() # 去除换行符
if not str_input: # 如果输入空行,结束循环
break
if len(str_input) <= 8:
res.append("NG")
continue
str_count = {"upper": 0, "lower": 0, "num": 0, "other": 0}
has_repeat = False
for i in range(len(str_input)):
cur_str = str_input[i]
if cur_str.isdigit():
str_count["num"] = 1
elif cur_str.isalpha():
if cur_str.isupper():
str_count["upper"] = 1
else:
str_count["lower"] = 1
else:
str_count["other"] = 1
# 检查重复子串,i的前三个字符串是否在i后面的字符串里
if i >= 3:
if str_input[i - 3 : i] in str_input[i:]:
has_repeat = True
break
if has_repeat:
res.append("NG")
elif sum(str_count.values()) < 3:
res.append("NG")
else:
res.append("OK")
print("\n".join(res))
str_check()