Process for preparing 5-substituted quinolone and naphthyridonecarboxylic acid derivatives