public static void main(String[] args) throws Exception
    {
        //add your code here
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i=0; i<20; i++) list.add(Integer.parseInt(reader.readLine()));

        ArrayList<Integer> listBase3 = new ArrayList<Integer>();
        ArrayList<Integer> listBase2 = new ArrayList<Integer>();
        ArrayList<Integer> listBase1 = new ArrayList<Integer>();

        for (int i=0; i<list.size(); i++)
        {
            if (list.get(i) % 3 == 0) listBase3.add(list.get(i));
            if (list.get(i) % 2 == 0) listBase2.add(list.get(i));
            if (!(list.get(i) % 3 == 0)&&!(list.get(i) % 2 == 0)) listBase1.add(list.get(i));
        }

        printList(listBase3);
        printList(listBase2);
        printList(listBase1);
    }