Prove that if f is a real function on a measurable space X such that {x:f(x) is greater than or equal to r} is measurable for every rational r, then f is measurable.

I am pretty certain I have to use the density of the rationals, but I don't see how.