Your hand is fixed, and the other three hands are dealt a thousand times within what the auction allows. Every layout is solved double dummy after every possible lead. At IMPs, a lead costs the IMPs it loses per board against the best lead. At matchpoints, on each deal your lead is compared with every other lead you could have made: 2 points for each one it does better than (declarer scores less), 1 point when it is the same, and 0 points when it does worse. If it scores 2 points against every other lead, that is worth 100%. If it beats half of them and loses to the rest, it is 50%, and so on. We average that over all the deals, and the cost of your lead is the best lead's percentage minus yours. Touching cards, like the king from K-Q, count as one lead.