Text this: Variational principle for scale-free network motifs