Visualizing diagrams needed to compute $\langle \operatorname{Tr}(A^3 (A^T)^3)\rangle$

(crossposted from mathematica.SE post)

I’m looking for help getting Mathematica code to construct diagrammatic expressions like the following, obtained by River Li as a way to compute \operatorname{Tr}(A^2 (A^T)^2) for d\times d matrix A with IID Gaussian entries.

enter image description here

The clearest explanation of such diagrams is given in Terry Tao’s RMT book, Section 2.3.4.

He describes diagrammatic procedure for computing E\operatorname{Tr}A^4:
enter image description here
enter image description here

Which gives 4 different diagram types, that can be visualized method like above.


I’d like a method which takes an expression like E \operatorname{Tr}(AAAA'A'A') where A is a d\times d matrix with IID standard normal entries, and generates a table of corresponding diagrams, like this, hand-derived by River Li.

Background

For the last 4 years I’ve been slowly organizing Mathematica-related code that helps explain Gaussian expectations (starting with 2020 post cumulants vis
, also post on wicks brackets, partition lattice). I’m estimating I’m about halfway done to a nice Wolfram Community post on combinatorics of random matrices.

With no previous experience of Graph, I tried to reproduce your diagrams using Graph, and soon met puzzling behaviour:

Graph[{Style[1 -> 1, Blue],
  1 -> 1,
  Style[1 -> 1, Red],
  Style[1 -> 1, Red, Dashed]}]

Why do all edges come out blue? Why is the Dashed ignored?

Take a look at the InputForm. It will be pretty obvious. You need to “tag” the edges so edges with identical vertices aren’t confused.

Graph[{Style[1  \!\(\*OverscriptBox[\(\[DirectedEdge]\), \(1\)]\) 1, Blue], 
1 \!\(\*OverscriptBox[\(\[DirectedEdge]\), \(2\)]\) 1, 
Style[1 \!\(\*OverscriptBox[\(\[DirectedEdge]\), \(3\)]\) 1, Red], 
Style[1 \!\(\*OverscriptBox[\(\[DirectedEdge]\), \(4\)]\) 1, Red, Dashed]}]

So they get confused, right?