Program complete. Some minor changes to be done to change the number of trains and max numbers of concurrent queries dynamically