Usefull functions for manipulating a list in mathematica
To get distinct elements in a list use Union or DeleteDublicates
To construct a new matrix by grouping rows according to identical values in some of the coloums use GatherBy
To make combinations of elements in a list use Subsets