Construct a line graph / conjugate graph Introduction

Given an undirected graph G, we can construct a graph L(G) (called the line graph or conjugate graph) that represents the connections between edges in G. This is done by creating a new vertex in L(G) for every edge in G and connecting these vertices if the edges they represent have a vertex in common.

Here's an example from Wikipedia showing the construction of a line graph (in green).






As another example, take this graph G with vertices A, B, C, and D.

    A
    |
    |
B---C---D---E


We create a new vertex for each edge in G. In this case, the edge between A and C is represented by a new vertex called AC.

   AC

 BC  CD  DE


And connect vertices when the edges they represent have a vertex in common. In this case, the edges from A to C and from B to C have vertex C in common, so vertices AC and BC are connected.

   AC
  /  \
 BC--CD--DE


This new graph is the line graph of G!

See Wikipedia for more information.

Challenge

Given the adjacency list for a graph G, your program should print or return the adjacency list for the line graph L(G). This is code-golf, so the answer with the fewest bytes wins!

Input

A list of pairs of strings representing the the edges of G. Each pair describes the vertices that are connected by that edge.


Each pair (X,Y) is guaranteed to be unique, meaning that that the list will not contain (Y,X) or a second (X,Y).


For example:

[("1","2"),("1","3"),("1","4"),("2","5"),("3","4"),("4","5")]
[("D","E"),("C","D"),("B","C"),("A","C")]


Output

A list of pairs of strings representing the the edges of L(G). Each pair describes the vertices that are connected by that edge.


Each pair (X,Y) must be unique, meaning that that the list will not contain (Y,X) or a second (X,Y).
For any edge (X,Y) in G, the vertex it creates in L(G) must be named XY (the names are concatenated together in same order that they're specified in the input).


For example:

[("12","13"),("12","14"),("12","25"),("13","14"),("13","34"),("14","34"),("14","45"),("25","45"),("34","45")]
[("DE","CD"),("CD","CB"),("CD","CA"),("BC","AB")]


Test Cases

[] -&gt; []

[("0","1")] -&gt; []

[("0","1"),("1","2")] -&gt; [("01","12")]

[("a","b"),("b","c"),("c","a")] -&gt; [("ab","bc"),("bc","ca"),("ca","ab")]

[("1","2"),("1","3"),("1","4"),("2","5"),("3","4"),("4","5")] -&gt; [("12","13"),("12","14"),("12","25"),("13","14"),("13","34"),("14","34"),("14","45"),("25","45"),("34","45")]
Ruby, 51 bytes



-&gt;a{a.combination(2){|x,y|p [x*'',y*'']if(x&amp;y)[0]}}


Try it online!

For each combination of two edges, if they have a vertex in common (i.e. if the first element of their intersection is non-nil), print an array containing the two edges to STDOUT.