The invention provides a compound for use in a method for the diagnosis and treatment of a disease state or condition mediated by TYK2 kinase, which method comprises (i) screening a patient to determine whether a disease or condition from which the patient is or may be suffering is one which would be susceptible to treatment with a compound having activity against the kinase; and (ii) where it is indicated that the disease or condition from which the patient is thus susceptible, thereafter administering to the patient an effective TYK2 inhibiting amount of the compound, wherein the compound has the formula (0):or is a salt or stereoisomer thereof; wherein:n is 0, 1 or 2;Ar1 is selected from an optionally substituted phenyl, pyridyl, thienyl and furanyl;Q1 is selected from C(=O), S(=O) and SO2;A is absent or is NR2;R1 is selected from hydrogen, an optionally substituted C1-6 non-aromatic hydrocarbon group and an optionally substituted 3- to 7-membered non-aromatic carbocyclic and heterocyclic rings containing one or two heteroatom ring members selected from O, N and S, and bridged bicyclic heterocyclic rings of seven to nine ring members of which one or two are nitrogen atoms; orNR1R2 forms an optionally substituted 4- to 7-membered non-aromatic nitrogen-containing heterocyclic ring optionally containing a second heteroatom ring member selected from nitrogen and oxygen.The invention also provides compounds for use in the diagnosis and treatment of various autoimmune and inflammatory diseases through the inhibition of TYK2 kinase.