Removed the use of carry dictionary.
Generalized the code to take query as a user input.
Added main()