Self-typing queries