Define the belongs(Pairs) relation for finding a list of pairs of the “figure”-“list of surrounding figures” type. (Consider that if there is facts contains(A, B), contains(B, C), then figure C belongs figure A)

Please help, this code does not output what it should

```
figure(square1, red).
figure(circle, red).
figure(triangle, blue).
figure(rectangle, green).
figure(diamond, purple).
figure(square2, green).
figure(trapezium1, black).
figure(hexagon, grow).
figure(trapezium2, yellow).
figure(octagon, purple).
figure(trapezium3, red).
contains(square1, rectangle).
contains(circle, diamond).
contains(square1, hexagon).
contains(trapezium2, square2).
contains(trapezium1, triangle).
contains(triangle, square2).
contains(trapezium1, rectangle).
contains(octagon, trapezium3).
contains(rectangle, triangle).
contains(trapezium3, circle).
contains(trapezium3, square1).
figure_list(_) :- contains(A, B),
( retract(contains(A-C))
-> M = C
; M = []
),
assertz(contains(A-[B|M])),
fail.
figure_list(List) :- extract_names(List).
belongs(Pairs) :-
setof(Contains-Figure,
bagof(C, contains(Contains, C), Figure),
Pairs
).
```