changed and b indexing to train and query for clarity