public class Solution { public static volatile BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws InterruptedException { Read3Strings t1 = new Read3Strings(); Read3Strings t2 = new Read3Strings(); t1.start(); t1.join(); t2.start(); t2.join(); t1.printResult(); t2.printResult(); } public static class Read3Strings extends Thread{ public static ArrayList<String> str = new ArrayList<>(); public void run(){ try{ for(int i = 0; i<3; i++){ str.add(reader.readLine()); } }catch(IOException ex){ } } public void printResult() { String string = ""; int count = 0; for (int i = 0;i<str.size();i++) { string = string + str.get(i) + " "; if (string.length()==6){System.out.print(string.trim() + "\n"); string = ""; } count++; } } } }