The cons function always does the same thing: it produces a cons cell of its arguments. A cons cell is simply a pair. You can get the first element of the pair with car and the second element with cdr.
For writing a literal cell, you can quote and use the notation (x . y) where x is the car and y is the cdr. Using this notation, you can write your examples as follows (but don't just take my word for it, try it in the REPL):
> '((A) . B ) ;=> ((A) . B)
> '((A) . (B)) ;=> ((A) B)
> '( A . B ) ;=> (A . B)
> '( A . (B)) ;=> (A B)
But why don't the results of the second and fourth cases print the same way that we wrote them? There are special printing conventions for cons cells, because we use cons cells to implement linked lists.
Read 14.1.2 Conses as Lists for specifics, but a list is a cons cell whose car is the first element of the list, and whose cdr is the rest of the list (i.e., another list). That means that the list (1 2 3) is the same as (using the literal dotted pair notation) (1 . (2 . (3 . nil))). You can try that in the REPL:
> '(1 . (2 . (3 . nil))) ;=> (1 2 3)
That's a very useful printing (and input) convention for a language where lists are so fundamental. I've written more about this in an answer to other questions, too: