title: Most elegant way to expand card hand suits
body: <p>I'm storing 4-card hands in a way to treat hands with different suits the same, e.g.:</p>
  
  <pre><code>9h 8h 7c 6c
  </code></pre>
  
  <p>is the same as</p>
  
  <pre><code>9d 8d 7h 6h
  </code></pre>
  
  <p>since you can replace one suit with another and have the same thing. It's easy to turn these into a unique representation using wildcards for suits. THe previous would become:</p>
  
  <pre><code>9A 8A 7B 6B
  </code></pre>
  
  <p>My question is - what's the most elegant way to turn the latter back into a list of the former? For example, when the input is <code>9A 8A 7B 6B</code>, the output should be:</p>
  
  <pre><code>9c 8c 7d 6d
  9c 8c 7h 6h
  9c 8c 7s 6s
  9h 8h 7d 6d
  9h 8h 7c 6c
  9h 8h 7s 6s
  9d 8d 7c 6c
  9d 8d 7h 6h
  9d 8d 7s 6s
  9s 8s 7d 6d
  9s 8s 7h 6h
  9s 8s 7c 6c
  </code></pre>
  
  <p>I have some ugly code that does this on a case-by-case basis depending on how many unique suits there are. It won't scale to hands with more cards. Also in a situation like:</p>
  
  <pre><code>7A 7B 8A 8B
  </code></pre>
  
  <p>it will have duplicates, since in this case <code>A=c</code> and <code>B=d</code> is the same as <code>A=d</code> and <code>B=c</code>.</p>
  
  <p>What's an elegant way to solve this problem efficiently? I'm coding in C, but I can convert higher-level code down to C.</p>