public class Solution {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        ArrayList<Integer> list = new ArrayList();
        ArrayList<Integer> dva = new ArrayList();
        ArrayList<Integer> tri = new ArrayList();
        ArrayList<Integer> drugoe = new ArrayList();
        for(int i = 0; i < 20; i++) {
            String s = reader.readLine();
            int x = Integer.parseInt(s);
            list.add(i);
            if(x % 2 == 0 || x % 6 == 0) dva.add(x);
            if (x % 3 == 0 || x % 6 == 0) tri.add(x);
            if(x % 3 != 0 || x % 2 != 0 || x % 6 != 0) drugoe.add(x);
        }
        printList(tri);
        printList(dva);
        printList(drugoe);
    }

    public static void printList(List<Integer> list) {
        for(int i = 0; i < tri.size(); i++) {
            System.out.println(tri.get(i));
        }
        for(int i = 0; i < dva.size(); i++) {
            System.out.println(dva.get(i));
        }
        for(int i = 0; i < drugoe.size(); i++) {
            System.out.println(drugoe.get(i));
        }
    }
}