The present invention provides: a heterocyclic compound and an intermediate thereof, the compound having an excellent controlling effect against harmful arthropods and being represented by formula (I) (in the formula, R2 represents a C1-C6 alkyl group which may be substituted with at least one halogen atom, n represents 0, R3 represents a C1-C6 chain hydrocarbon group which may have at least one substituent selected from group B, q represents 0, Het represents groups represented by formulas Het 1 and Het 2, A1 represents a nitrogen atom or CR6, and Q2 represents an oxygen atom); and a composition containing the compound and at least one selected from the group consisting of group (a), group (b), group (c), group (d), and group (e) specified in the description.