A General Framework for Clustering and Distribution Matching with Bandit Feedback