I have the following problem as an assignment: to construct a combinatory term of type $$(p \rightarrow r) \rightarrow (p \rightarrow (q \rightarrow r))$$ using the polymorphic $\mathbb{K}, \mathbb{S}$ combinators. I know the relevant definitions, but am not sure how to start tackling the problem.
Could someone please post a combinatory term for a simpler type, for example $$(p \rightarrow q) \rightarrow (p \rightarrow r)$$ or even $$((p \rightarrow q) \rightarrow r)$$ if the former is too similar to the actual problem (I don't know how much of a blowup in size there is from type to combinators) and explain how to derive it? I'd like to complete my actual assignment problem on my own, so a worked example for something similar and simpler would set me on the right path to do that, I think. Alternatively, any recommendations for relevant resources already available online would also be much appreciated.
Thanks!
Edit: as originally posted, the type of the first term was incorrect (there was a $q$ in place of the first $r$). As it was, the question would've been impossible - since of course $(p \rightarrow q) \rightarrow (p \rightarrow (q \rightarrow r))$ (which was the original, typoed version) is not a theorem of any reasonable logic.