import java.util.*; public class Exercise67{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); int[] q = {1, 4, 9, 6}; ArrayList confirm = new ArrayList(); confirm.add(0); confirm.add(1); confirm.add(2); confirm.add(3); whole: while(true){ System.out.println(q[0] + " " + q[1] + " " + q[2] + " " + q[3]); System.out.flush(); int p = sc.nextInt(); int h = sc.nextInt(); if (p == 4){ break whole; }else if (p + h == 4){ q[confirm.get(confirm.size() - 1)] = changeNum(q[confirm.get(confirm.size() - 1)], q); } for (int i = 0; i < 4; i++){ if (confirm.indexOf(i) == -1){ continue; } eachNum: for (int j = 0; j < 10; j++){ if (checkMN(plus(q[i]), q)){ q[i] = plus(q[i]); continue; }else{ q[i] = plus(q[i]); System.out.println(q[0] + " " + q[1] + " " + q[2] + " " + q[3]); System.out.flush(); int pd = sc.nextInt(); int hd = sc.nextInt(); if (pd == 4){ break whole; }else if(p + 1 == pd){ p = pd; confirm.remove(confirm.indexOf(i)); break eachNum; }else if(p - 1 == pd){ if (q[i] > 0){ q[i]--; confirm.remove(confirm.indexOf(i)); break eachNum; }else{ q[i] = 9; confirm.remove(confirm.indexOf(i)); break eachNum; } }else if (pd + hd == 4){ q[confirm.get(confirm.size() - 1)] = changeNum(q[confirm.get(confirm.size() - 1)], q); } } } } } } private static boolean checkMN(int num, int[] array){ boolean flag = false; for (int i = 0; i < 4; i++){ if (num == array[i]){ flag = true; } } return flag; } private static int plus(int num){ int newNum = 0; if (num < 9){ newNum = num + 1; }else{ newNum = 0; } return newNum; } private static int changeNum(int num, int[] array){ if (checkMN(num, array)){ if (num > 0){ num -= 2; }else{ num = 9; } return changeNum(num, array); }else{ return num; } } }