I would like to arrange the following items, forming the longest chain possible starting with 12-8 and matching the numbers end to end.
My items are 7-4, 11-8, 11-11
Think of the numbers as vertices and the pairs as edges of a graph (so there may be some multi-edges). Now your problem is reduced to finding the longest path in the graph where vertices (but not edges) may be repeated.