rewrite lottery with specific queries