Added reading input from stdin
Added splitting queries into nested lists