import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
ArrayList<String> list = new ArrayList<>();
while (scanner.hasNextLine()) {
String nextLine = scanner.nextLine();
if (nextLine.equals("")) {
break;
}
list.add(nextLine);
}
/*密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有长度大于2的不含公共元素的子串重复 (注:其他符号不含空格或换行*/
ArrayList<String> result = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
String str = list.get(i);
int length = str.length();
if (length < 8) {
result.add("NG");
continue;
}
String s = str.replaceAll(" ", "");
char[] chars = s.toCharArray();
int upCase = 0;
int lwCase = 0;
int number = 0;
int x = 0;
for (int j = 0; j < chars.length; j++) {
if (chars[j] >= 'A' && chars[j] <= 'Z') {
upCase++;
continue;
}
if (chars[j] >= 'a' && chars[j] <= 'z') {
lwCase++;
continue;
}
if (chars[j] >= '0' && chars[j] <= '9') {
number++;
continue;
}
x++;
}
int count = 0;
if (upCase != 0) {
count++;
}
if (lwCase != 0) {
count++;
}
if (number != 0) {
count++;
}
if (x != 0) {
count++;
}
if (count < 3) {
result.add("NG");
continue;
}
boolean b = false;
for (int j = 0; j < str.length() - 2; j++) {
if(b){
break;
}
String substring1 = str.substring(j, j + 3);
String substring2 = "";
for (int k = 0; k < str.length() - 2; k++) {
if (j == k) {
continue;
}
substring2 = str.substring(k, k + 3);
if (substring1.equals(substring2)) {
result.add("NG");
b = true;
break;
}
}
}
if (result.size() != i + 1) {
result.add("OK");
}
}
for (int i = 0; i < result.size(); i++) {
System.out.println(result.get(i));
}
}
}