import java.io.*;
import java.util.*;
import java.lang.*;
private int a[];
private int top;
private int size;
size=n;
a=new int[size];
for(int i=0;i<size;i++){
a[i]=0;
}
top=-1;
}
public boolean push(int k){
if(top<size-1){
a[++top]=k;
return true;
}else{
//System.out.println("Overflow error");
return false;
}
}
public boolean pop(){
if(top>-1){
top--;
return true;
}else{
//System.out.println("Underflow error");
return false;
}
}
public int getSize(){
return size;
}
public int getTop(){
return top;
}
public int peak(){
return a[top];
}
public boolean isEmpty(){
return top==-1;
}
public void print(){
char[] line = new char[top+1];
for(int i=0;i<=top;i++){
line[i] = (char)(a[i]+'0');
}
}
}
class Queue{
private int a[];
private int front;
private int rear;
private int size;
public Queue(int n){
size=n;
a= new int[size];
front=-1;
rear=-1;
}
public boolean enqueue(int k){
if(isFull()){
System.
out.
println("Overflow Error"); return false;
}
if(isEmpty()){
++rear;
}
++front;
if(front==size){
front=0;
}
a[front]=k;
return true;
}
public boolean dequeue(){
if(isEmpty()){
System.
out.
println("Underflow Error"); return false;
}
if(front==rear){
front=-1;
rear=-1;
}else{
++rear;
if(rear==size){
rear=0;
}
}
return true;
}
public boolean isFull(){
return rear==front+1||(rear==0 && front==size-1);
}
public boolean isEmpty(){
return rear==-1 && front==-1;
}
public int getFront(){
return front;
}
public int getRear(){
return rear;
}
public int getSize(){
return size;
}
public int peakFront(){
return a[front];
}
public int peakRear(){
return a[rear];
}
public void print(){
if(front==-1 && rear==-1){
return;
}
int i=rear-1;
do{
i++;
if(i==size){
i=0;
}
}while(i!=front);
}
}
public class Main{
int t
= Integer.
parseInt(br.
readLine());
for(int t_=0;t_<t;t_++){
int n
= Integer.
parseInt(br.
readLine());
char[] line = br.readLine().toCharArray();
for(int i=0;i<line.length;i++){
if ((line[i] >= '0') & (line[i] <='9')){
digits.push(line[i]-'0');
}
}
Queue popped=new Queue(n);
popped.enqueue(digits.peak());
digits.pop();
int next;
boolean flag=false;
while(!digits.isEmpty()){
next=digits.peak();
if(next>=popped.peakFront()){
popped.enqueue(next);
digits.pop();
}else{
flag=true;
break;
}
}
if(flag){
int a=digits.peak();
digits.pop();
Queue temp=new Queue(n);
int b=0;
while(!popped.isEmpty()){
if(popped.peakRear()<a || !flag){
temp.enqueue(popped.peakRear());
popped.dequeue();
}else{
temp.enqueue(a);
b=popped.peakRear();
popped.dequeue();
flag=false;
}
}
if(flag){
}else{
digits.push(b);
while(!temp.isEmpty()){
digits.push(temp.peakRear());
temp.dequeue();
}
digits.print();
}
}
}
br.close();
}
}