How to take n inputs and put them in lexiogical order

how to take n inputs and run code n times and output accordingly and put them in lexiogical order

lexicographical* instead of lexiogical

hi @kshitijkumar7548_da7d29c5890bbfd8,