class IntList {

    public static IntList catenate(IntList A, IntList B) {
        IntList res = new IntList(A.first, null);
        IntList ptr = res;
        A = A.rest;
        while (A != null) {
            ptr.rest = new IntList(A.first, null);
            ptr = ptr.rest;
            A = A.rest;
        }
        ptr.rest = B;
        return res;
    }

}

class IntListTest {

    @Test
    public void testCatenate() {

        IntList A = IntList.of(1, 2, 3);
        IntList B = IntList.of(4, 5, 6);
        IntList exp = IntList.of(1, 2, 3, 4, 5, 6);
        assertEquals(exp, IntList.catenate(A, B));
        assertEquals(IntList.of(1, 2, 3), A);
    }

}