In the example both charges are positive; this equation is applicable to any charge configuration (as the product of the charges will be either positive or negative according to their (dis)similarity). If one of the charges were to be negative in the earlier example, the work taken to wrench that charge away to infinity would be exactly the same as the work needed in the earlier example to push that charge back to that same position. This is easy to see mathematically, as reversing the boundaries of integration reverses the sign.