The Justice and Mercy of God

How can God be perfectly just and perfectly righteous at the same time. Is it a logical contradiction? Or is it the perfect answer to mankind's deepest questions.