give array query positive integer 1 m process queriesi i0 iquerieslength1 accord follow rulesin begin permutation p123mfor current find position queriesi permutation p indexing 0 begin permutation p Notice position queriesi p result queriesireturn array contain result give query example 1input query 3121 m 5output 2121 Explanation the query process follow for i0 queriesi3 P12345 position 3 p 2 3 begin p result P31245 for i1 queriesi1 P31245 position 1 p 1 1 begin p result P13245 for i2 queriesi2 P13245 position 2 p 2 2 begin p result P21345 for i3 queriesi1 P21345 position 1 p 1 1 begin p result P12345 therefore array contain result 2121 example 2input query 4122 m 4output 3120example 3input query 75583 m 8Output 65075 Constraints1 m 1031 querieslength m1 queriesi m