This paper studies the fitting problem inspired by ontology-mediated queries. Given a set of positive and negative examples $(\mathcal{A},q)$ (where $\mathcal{A}$ is an ABox and $q$ is a Boolean query), the problem is to find an ontology $\mathcal{O}$ such that $\mathcal{A} \cup \mathcal{O} \vDash q$ for all positive examples and $\mathcal{A} \cup \mathcal{O}\not\vDash q$ for all negative examples. We consider $\mathcal{ALC}$ and $\mathcal{ALCI}$ as ontology languages, and atomic queries (AQs), conjunction queries (CQs), and their unions (UCQs) as query languages. Consequently, we provide an effective characterization of all the resulting fitting problems and determine the computational complexity of determining whether a fitting ontology exists. This problem is shown to be ${\scriptsize CO}NP$ for AQs and all CQs, and $2E{\scriptsize XP}T{\scriptsize IME}$-complete for CQs and UCQs. These results hold for both $\mathcal{ALC}$ and $\mathcal{ALCI}$.