First, it is super important to point out that the way you framed your question suggests you are thinking of how X spells work in general backward. That is, you don't "tap lands" and get a result as your question suggests. You *always* first decide what you want X to be and that number will never change through the spellcasting process. If you want X to be 0 with those 3 cards on the field, you can do it (and it is super easy to pay for). Or, if you want X to be 1 billion, well, you can do that to (though it is tougher to pay for which means you probably won't actually get to cast it).
So, with that being said, you will end up casting Kaervek's Torch and choosing the value of X to be 9 (for example). Then Melee reduces the cost by {2} and Electromancer and Medallion each reduce it by {1]. So, the cost with the value of X in it is {9R} but with a reduction of {4} you only need to pay {5R} for an X value of 9. And, since you declared X to be 9, you will deal 9 damage.
Thanks.
So, with that being said, you will end up casting Kaervek's Torch and choosing the value of X to be 9 (for example). Then Melee reduces the cost by {2} and Electromancer and Medallion each reduce it by {1]. So, the cost with the value of X in it is {9R} but with a reduction of {4} you only need to pay {5R} for an X value of 9. And, since you declared X to be 9, you will deal 9 damage.