The officer's inquiry can be unrelated to the reason for the stop. Duration of the seizure (>1H) can be an issue.
Pat-frisk may be reasonable in this context (see AZ v. Johnson: car is stopped for insurance violation, passenger is siezed and frisked because of possible Crips connection, for officer safety, gun is found). Officer safety is usually the reason.