Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.*;
- import static java.lang.System.*;
- import static java.lang.Math.*;
- class Code
- {
- void run() {
- int tc=ni();
- StringBuilder sb=new StringBuilder();
- while(tc-->0) {
- int n=ni();
- String s=ns(); ni();
- int fr[] = new int[10];
- for(int i=0;i<n;i++) fr[s.charAt(i)-'0']++;
- int j=0;
- xD:
- for(int i=9;i>0;i++) {
- while(fr[i]>0) {
- int x=s.charAt(j)-'0';
- if(x==i) fr[i]--;
- else {
- sb.append(i); j++;
- while(j<n) {
- if(s.charAt(j)-'0'==x) { sb.append(x); x=-1; }
- else sb.append(s.charAt(j));
- j++;
- }
- break xD;
- }
- sb.append(x);
- j++;
- }
- }
- sb.append("\n");
- }
- out.println(sb);
- out.flush();
- out.close();
- }
- public static void main(String[] args)throws IOException {
- try {
- new Code().run();
- } catch(Exception e) {}
- }
- FastReader sc = new FastReader();
- PrintWriter out = new PrintWriter(System.out);
- String ns() { return sc.next(); }
- int ni() { return sc.nextInt(); }
- long nl() { return sc.nextLong(); }
- int[] ni(int n) {
- int a[]=new int[n];
- for(int i=0;i<n;a[i++]=ni());
- return a;
- }
- long[] nl(int n) {
- long a[]=new long[n];
- for(int i=0;i<n;a[i++]=nl());
- return a;
- }
- int[][] ni(int n,int m) {
- int a[][]=new int[n][m];
- for(int i=0;i<n;i++)
- for(int j=0;j<m;j++)
- a[i][j]=ni();
- return a;
- }
- long[][] nl(int n,int m) {
- long a[][]=new long[n][m];
- for(int i=0;i<n;i++)
- for(int j=0;j<m;j++)
- a[i][j]=nl();
- return a;
- }
- int gcd(int a, int b) {
- return b==0?a:gcd(b,a%b);
- }
- static class FastReader {
- private InputStream stream;
- private byte[] buf = new byte[1024];
- private int curChar;
- private int numChars;
- private FastReader.SpaceCharFilter filter;
- FastReader(){ this(System.in); }
- public FastReader(InputStream stream) {
- this.stream = stream;
- }
- public int read() {
- if (numChars == -1) throw new InputMismatchException();
- if (curChar >= numChars) {
- curChar = 0;
- try {
- numChars = stream.read(buf);
- } catch (IOException e) {
- throw new InputMismatchException();
- }
- if (numChars <= 0) return -1;
- }
- return buf[curChar++];
- }
- public int nextInt() {
- int c = read();
- while (isSpaceChar(c)) c = read();
- int sgn = 1;
- if (c == '-') {
- sgn = -1;
- c = read();
- }
- int res = 0;
- do {
- if (c < '0' || c > '9') throw new InputMismatchException();
- res *= 10;
- res += c - '0';
- c = read();
- }
- while (!isSpaceChar(c));
- return res * sgn;
- }
- public long nextLong() {
- int c = read();
- while (isSpaceChar(c)) c = read();
- int sgn = 1;
- if (c == '-') {
- sgn = -1;
- c = read();
- }
- long res = 0;
- do {
- if (c < '0' || c > '9') throw new InputMismatchException();
- res = res*1L*10;
- res += c - '0';
- c = read();
- }
- while (!isSpaceChar(c));
- return res *1L* sgn;
- }
- public String next() {
- int c = read();
- while (isSpaceChar(c)) c = read();
- StringBuilder res = new StringBuilder();
- do {
- res.appendCodePoint(c);
- c = read();
- } while (!isSpaceChar(c));
- return res.toString();
- }
- public boolean isSpaceChar(int c) {
- if (filter != null) return filter.isSpaceChar(c);
- return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
- }
- public interface SpaceCharFilter {
- public boolean isSpaceChar(int ch);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement