#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long a[n];
    for(long long i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    long long m;
    cin>>m;
    long long b[m];
    for(long long j=0;j<m;j++){
        cin>>b[j];
    }
    long long sum;
    long long pum;
    for(long long i=0;i<m;i++){
        sum=0;
        pum=0;
        for(long long j=n-1;j>=(n-b[i]+1);j--){
            sum+=a[j];
        }
        for(long long k=0;k<(n-b[i]);k++){
            pum+=a[k];
        }
        cout<<sum+pum<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int m;
    cin>>m;
    int b[m];
    for(int j=0;j<m;j++){
        cin>>b[j];
    }
    int sum;
    int pum;
    for(int i=0;i<m;i++){
        sum=0;
        pum=0;
        for(int j=n-1;j>=(n-b[i]+1);j--){
            sum+=a[j];
        }
        for(int k=0;k<(n-b[i]);k++){
            pum+=a[k];
        }
        cout<<sum+pum<<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;

#define ebar_khela_jombe_besh   int main (void)
#define jitsen_bhai		        return 0
#define sf                  	scanf
#define pf                  	printf
#define ssf                 	sscanf
#define spf                 	sprintf
#define fsf                 	fscanf
#define fpf                 	fprintf
#define fast                	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define scase               	sf ("%d",&tc)
#define sn                  	sf ("%d",&n)
#define whilecase           	while (tc--)
#define eof                 	while (cin >> n)
#define forloop             	for (pos=1; pos<=tc; pos++)
#define arrayloop           	for (i=0; i<n; i++)
#define cinstr              	cin >> str
#define getstr              	getline (cin,str)
#define pcase               	pf ("Case %d: ",pos)
#define vi                  	vector <int>
#define si                  	set <int>
#define vs                  	vector <string>
#define pii                 	pair <int,int>
#define mii                 	map <int,int>
#define pb                  	push_back
#define in                  	insert
#define llu                 	unsigned long long
#define lld                 	long long
#define U                   	unsigned int
#define endl                	"\n"

const int MOD = 1000000007;
const int MAX = 1000005;

int SetBit (int n, int x) { return n | (1 << x); }
int ClearBit (int n, int x) { return n & ~(1 << x); }
int ToggleBit (int n, int x) { return n ^ (1 << x); }
bool CheckBit (int n, int x) { return (bool)(n & (1 << x)); }

lld arr[300005];

ebar_khela_jombe_besh
{
    /*
    	freopen ("input.txt","r",stdin);
    	freopen ("output.txt","w",stdout);
    */

    lld n,i,m,q;

    sf ("%lld",&n);

    for (i=1; i<=n; i++)
        sf ("%lld",&arr[i]);

    sort (arr,arr+n+1);

    for (i=1; i<=n; i++)
        arr[i] += arr[i-1];

    sf ("%lld",&m);

    for (i=1; i<=m; i++)
    {
        sf ("%lld",&q);
        pf ("%lld\n",arr[n]-arr[n-q+1]+arr[n-q]);
    }

    jitsen_bhai;
}
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long a[n];
    for(long long i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    long long m;
    cin>>m;
    long long b[m];
    for(long long j=0;j<m;j++){
        cin>>b[j];
    }
    long long sum;
    long long pum;
    for(long long i=0;i<m;i++){
        sum=0;
        pum=0;
        for(long long j=n-1;j>=(n-b[i]+1);j--){
            sum+=a[j];
        }
        for(long long k=0;k<(n-b[i]);k++){
            pum+=a[k];
        }
        cout<<sum+pum<<endl;
    }
}
*/


#include<bits/stdc++.h>
using namespace std;
int main()
{

   int n,m;
    cin>>n;
  int arr[n];

   long long int sum1=0,sum2=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cin>>m;
    unsigned long long int q[m];

    for(int i=0;i<m;i++)
    {
        cin>>q[i];
    }
    sort(arr,arr+n);

    int k=0;

        again:
    for(int i=n-1,j=1;j<q[k];i--,j++)
    {
        sum1+=arr[i];

    }
    for(int i=0;i<n-q[k];i++)
    {
        sum2+=arr[i];

    }
    cout<<sum1+sum2<<endl;
    sum1=0; sum2=0;
    k++;
    if(k<m)
    {
        goto again;
    }
    else return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

   int n,m;
    cin>>n;
  int arr[n];
  long long  sum[100000];

   long long sum1=0,sum2=0 ;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cin>>m;
     long long int q[m];

    for(int i=0;i<m;i++)
    {
        cin>>q[i];
    }
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
                {
                    sum2+=arr[i];
                    sum[i]=sum2;
                }

    int k=0;

        while(k<m){

                sum1=sum[n-1]-sum[n-q[k]];
                if((n-1-q[k])>=0)
                {
                    sum1+=sum[n-1-q[k]];
                }

    cout<<sum1<<endl;
    sum1=0;
    k++;
        }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

   int n,m;
    cin>>n;
  int arr[n];

   long long int sum1=0,sum2=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cin>>m;
    unsigned long long int q[m];

    for(int i=0;i<m;i++)
    {
        cin>>q[i];
    }
    sort(arr,arr+n);

    int k=0;

        while(k<m){
    for(int i=n-1,j=1;j<q[k];i--,j++)
    {
        sum1+=arr[i];

    }
    for(int i=0;i<n-q[k];i++)
    {
        sum2+=arr[i];

    }
    cout<<sum1+sum2<<endl;
    sum1=0; sum2=0;
    k++;
        }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

   int n,m;
    cin>>n;
  int arr[n];
  int sum[100000];

   long long int sum1=0,sum2=0 ;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cin>>m;
     long long int q[m];

    for(int i=0;i<m;i++)
    {
        cin>>q[i];
    }
    sort(arr,arr+n);
    for(int i=0;i<n;i++)
                {
                    sum2+=arr[i];
                    sum[i]=sum2;
                }

    int k=0;

        while(k<m){

                sum1=sum[n-1]-sum[n-q[k]]+sum[n-1-q[k]];

    cout<<sum1<<endl;
    sum1=0;
    k++;
        }

    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

    unsigned long long int n,m;
    cin>>n;
    unsigned long long int arr[n],sum1=0,sum2=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cin>>m;
    unsigned long long int q[m];

    for(int i=0;i<m;i++)
    {
        cin>>q[i];
    }
    sort(arr,arr+n);

    int k=0;

        again:
    for(int i=n-1,j=1;j<q[k];i--,j++)
    {
        sum1+=arr[i];

    }
    for(int i=0;i<n-q[k];i++)
    {
        sum2+=arr[i];

    }
    cout<<sum1+sum2<<endl;
    sum1=0; sum2=0;
    k++;
    if(k<m)
    {
        goto again;
    }
    else return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{

   int n,m;
    cin>>n;
  int arr[n];
  long long  sum[n+1];

   long long sum1=0,sum2=0 ;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cin>>m;
     long long q;

    sort(arr,arr+n);
    sum[0] = arr[0];
    for(int i=1;i<n;i++)
                {
                    sum[i]= sum[i-1]+arr[i];

                }

    int k=0;

        while(k<m){
            cin>>q;
                sum1=sum[n-1]-sum[n-q];
                if((n-1-q)>=0)
                {
                    sum1+=sum[n-1-q];
                }

    cout<<sum1<<endl;
    sum1=0;
    k++;
        }

    return 0;

}


<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
	<FileVersion major="1" minor="6" />
	<Project>
		<Option title="1132B" />
		<Option pch_mode="2" />
		<Option compiler="gcc" />
		<Build>
			<Target title="Debug">
				<Option output="bin/Debug/1132B" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Debug/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-g" />
				</Compiler>
			</Target>
			<Target title="Release">
				<Option output="bin/Release/1132B" prefix_auto="1" extension_auto="1" />
				<Option object_output="obj/Release/" />
				<Option type="1" />
				<Option compiler="gcc" />
				<Compiler>
					<Add option="-O2" />
				</Compiler>
				<Linker>
					<Add option="-s" />
				</Linker>
			</Target>
		</Build>
		<Compiler>
			<Add option="-Wall" />
			<Add option="-fexceptions" />
		</Compiler>
		<Unit filename="main.cpp" />
		<Extensions>
			<code_completion />
			<envvars />
			<debugger />
			<lib_finder disable_auto="1" />
		</Extensions>
	</Project>
</CodeBlocks_project_file>


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    int m;
    cin>>m;
    int b[m];
    for(int i=0; i<m; i++)
        cin>>b[i];
    sort(a, a+n);
    long long T=0;
    for(int i=0; i<n; i++)
            T+=a[i];
    for(int i=0; i<m; i++)
        cout<<T-a[n-b[i]-1]<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    int m;
    cin>>m;
    int b[m];
    for(int i=0; i<m; i++)
        cin>>b[i];
    sort(a, a+n);
    long long T=0;
    for(int i=0; i<n; i++)
            T+=a[i];
    for(int i=0; i<m; i++)
        cout<<T-a[n-b[i]]<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    int m;
    cin>>m;
    int b[m];
    for(int i=0; i<m; i++)
        cin>>b[i];
    sort(a, a+ n, greater<int>());
    long long T=0;
    for(int i=n-1; i>=0 ; i++)
            T+=a[i];
    for(int i=0; i<m; i++)
        cout<<T-a[b[i]-1]<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
void quicksort(int a[], int left, int right)
{
    int chot=a[(right+left)/2];
    int i=left;
    int j=right;
    while (i<=j)
    {
        while(a[i]>chot)
            i++;
        while(a[j]<chot)
            j--;
        if(i<=j)
        {
            swap(a[i], a[j]);
            i++;
            j--;
        }
    }
    if(left<j)
        quicksort(a, left, j);
    if(right>i)
        quicksort(a, i, right);
}
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    int m;
    cin>>m;
    int b[m];
    for(int i=0; i<m; i++)
        cin>>b[i];
    quicksort(a,0, n-1);
    long long T=0;
    for(int i=0; i<n; i++)
            T+=a[i];
    for(int i=0; i<m; i++)
        cout<<T-a[b[i]-1]<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    int m;
    cin>>m;
    int b[m];
    for(int i=0; i<m; i++)
        cin>>b[i];
    sort(a, a+ n);
    long long T=0;
    for(int i=0; i<n; i++)
            T+=a[i];
    for(int i=0; i<m; i++)
        cout<<T-a[b[i]-1]<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{

    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    int m;
    cin>>m;
    int b[m];
    for(int i=0; i<m; i++)
        cin>>b[i];
    sort(a, a+ n);
    long long T=0;
    for(int i=0; i<n; i++)
            T+=a[i];
    for(int i=0; i<m; i++)
        cout<<T-a[b[i]+1]<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main(){
  int num=0,cop=0,sum=0,temp=0;
  int in[300005],q[300005];

  scanf("%d\n",&num);
  for(int i=0;i<num;i++) {
    scanf("%d",&in[i]);
    sum+=in[i];
  }
   scanf("%d",&cop);
  for(int j=0;j<cop;j++) scanf("%d",&q[j]);
  sort(in,in+num,greater<long>());

  temp = sum;

  for(int z=0;z<cop;z++){
    sum = sum - in[q[z]-1];
    printf("%d\n",sum);
    sum = temp;
  }
  return 0;
}


import sys
from bisect import bisect_right

sys.stdin = open( 'input.txt', 'r' )
sys.stdout = open( 'output.txt', 'w' )

n = int( raw_input() )
c = map( int, raw_input().split(' ') )
c.sort()
r = n - 1
#print c
for i in range(n-1):
	j = bisect_right(c, 2*c[i])
	#print i, j - 1
	r = min( r, n - (j - i) )
print r


import sys
sys.stdin = open( 'input.txt', 'r' )
sys.stdout = open( 'output.txt', 'w' )

n = int( raw_input() )
c = map( int, raw_input().split(' ') )
c.sort()
for i in range(n-1, -1, -1):
	if c[i] <= 2*c[0]:
		print n - i - 1
		break


import sys

sys.stdin = open('input.txt')
sys.stdout = open('output.txt', 'w')

n = int(raw_input())
c = map(int, raw_input().split())
c.sort()
ans = n
i, j = 0, 0
while i < len(c):
	while j < len(c) and c[j] <= 2 * c[i]: j += 1
	ans = min(ans, n - (j - i))
	i += 1
print ans


import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
n=input()
a=sorted(map(int,raw_input().split()))
e=n
while e>0 and a[e-1]>a[0]*2:e-=1
t=e
i=0
while i<e:
  while e<n and a[e]<=a[i+1]*2:e+=1
  i+=1
  t=max(t,e-i)
print n-t


import bisect
import sys

def main():
    f = open('input.txt')
    sys.stdout = open('output.txt','w')
    n = int(f.readline())
    c = sorted((map(int, f.readline().strip('\n').split())))

    if c[-1] <= c[1]*2:
        print(0)
        exit()
    res = 100001
    for i in range(n):
        if i > (n/2): break
        res = min(res,bisect.bisect(c,c[i]))
    print(res)
main()


import bisect
import sys

def main():
    f = open('input.txt')
    sys.stdout = open('output.txt','w')
    n = int(f.readline())
    c = sorted((map(int, f.readline().strip('\n').split())))

    if c[-1] <= c[0]*2:
        print(0)
        exit()
    res = 100001
    for i in range(n):
#        if c[i] > (c[-1]/2): break
        res = min(res,n - bisect.bisect(c,c[i]*2) + i)
    print(res)

main()


import bisect
import sys

def main():
    f = open('input.txt')
    sys.stdout = open('output.txt','w')
    n = int(f.readline())
    c = sorted((map(int, f.readline().strip('\n').split())))

    if c[-1] <= c[1]*2:
        print(0)
        exit()
    res = 100001
    print(c)
    for i in range(n):
        if c[i] > (c[-1]/2): break
        res = min(res,n - bisect.bisect(c,c[i]*2) + i)
    print(res)

main()


import bisect

def main():
    f = open('input.txt')
    o = open('output.txt','w')
    n = int(f.readline())
    c = sorted((map(int, f.readline().strip('\n').split())))

    if c[-1] <= c[1]*2:
        print(0)
        exit()
    res = 100001
    for i in range(n):
        if i > (n/2): break
        res = min(res,bisect.bisect(c,c[i]))
    o.write(str(res))
main()


import bisect
import sys

def main():
    f = open('input.txt')
    sys.stdout = open('output.txt','w')
    n = int(f.readline())
    c = sorted((map(int, f.readline().strip('\n').split())))

    if c[-1] <= c[1]*2:
        print(0)
        exit()
    res = 100001
    for i in range(n):
        if c[i] > (c[-1]/2): break
        res = min(res,n - bisect.bisect(c,c[i]*2) + i)
    print(res)

main()


with open("input.txt", "r") as inFile, open("output.txt", "w") as outFile:
    inFile.readline()
    numbers = sorted([int(x) for x in inFile.readline().split()])
    lt, rt = 0, len(numbers) - 1
    while rt > 0 and numbers[lt] * 2 < numbers[rt]:
        rt -= 1
    max_range = rt + 1 - lt
    while lt < len(numbers) - 1:
        lt += 1
        changed = False
        while rt < len(numbers) - 1 and numbers[lt] * 2 >= numbers[rt + 1]:
            rt += 1
            changed = True
        if not changed:
            break
        diff = rt + 1 - lt
        if diff > max_range:
            max_range = diff
    outFile.write(str(len(numbers) - max_range))


with open("input.txt", "r") as inFile, open("output.txt", "w") as outFile:
    inFile.readline()
    numbers = sorted([int(x) for x in inFile.readline().split()])
    print numbers
    lt, rt = 0, len(numbers) - 1
    while rt > 0 and numbers[lt] * 2 < numbers[rt]:
        rt -= 1
    max_range = rt + 1 - lt
    while lt < len(numbers) - 1:
        lt += 1
        changed = False
        while rt < len(numbers) - 1 and numbers[lt] * 2 >= numbers[rt + 1]:
            rt += 1
            changed = True
        diff = rt + 1 - lt
        if diff > max_range:
            max_range = diff
    outFile.write(str(len(numbers) - max_range))
    print (str(len(numbers) - max_range))


print(raw_input())
if False:
    numbers = sorted([int(x) for x in raw_input().split()])
    lt, rt = 0, len(numbers) - 1
    while rt > 0 and numbers[lt] * 2 < numbers[rt]:
        rt -= 1
    max_range = rt + 1 - lt
    while lt < len(numbers) - 1:
        lt += 1
        changed = False
        while rt < len(numbers) - 1 and numbers[lt] * 2 >= numbers[rt + 1]:
            rt += 1
            changed = True
        if not changed:
            break
        diff = rt + 1 - lt
        if diff > max_range:
            max_range = diff
    print (len(numbers) - max_range)


with open("input.txt", "r") as inFile, open("output.txt", "w") as outFile:
    inFile.readline()
    numbers = sorted([int(x) for x in inFile.readline().split()])
    lt, rt = 0, len(numbers) - 1
    while rt > 0 and numbers[lt] * 2 < numbers[rt]:
        rt -= 1
    max_range = rt + 1 - lt
    while lt < len(numbers) - 1:
        lt += 1
        changed = False
        while rt < len(numbers) - 1 and numbers[lt] * 2 >= numbers[rt + 1]:
            rt += 1
            changed = True
        if not changed:
            break
        diff = rt + 1 - lt
        if diff > max_range:
            max_range = diff
    outFile.write (len(numbers) - max_range)


raw_input()
numbers = sorted([int(x) for x in raw_input().split()])
lt, rt = 0, len(numbers) - 1
while rt > 0 and numbers[lt] * 2 < numbers[rt]:
    rt -= 1
max_range = rt + 1 - lt
while lt < len(numbers) - 1:
    lt += 1
    changed = False
    while rt < len(numbers) - 1 and numbers[lt] * 2 >= numbers[rt + 1]:
        rt += 1
        changed = True
    if not changed:
        break
    diff = rt + 1 - lt
    if diff > max_range:
        max_range = diff
print (len(numbers) - max_range)


#!/usr/bin/env python
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
def sort(List,st,en):
    if en-st<0: return
    p=_sort(List,st,en)
    if(p-st-1>0):sort(List,st,p-1)
    if(en-p-1>0):sort(List,p+1,en)
def _sort(List,l,r):
    key=List[l]
    while l<r:
        while l<r and _cmp(key,List[r]): r-=1
        if l<r: List[l]=List[r]
        while l<r and _cmp(List[l],key): l+=1
        if l<r: List[r]=List[l]
    List[l]=key
    return l
def _cmp(x,y): #自定义比较函数,相等返回true
    return x<=y
    #return x[0]>y[0] or (x[0]==y[0] and x[1]>=y[1])

n=input()
num=map(int,raw_input().split())
sort(num,0,n-1)
Max=0
j=0
for i in range(n):
    while j<n and num[j]<=2*num[i]: j+=1
    Max=max(Max,j-i)
print n-Max


#!/usr/bin/env python
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
List=[]
def qsort(st,en):
    if en-st<=0: return
    p=my_qsort(st,en)
    if(p-st-1>0):qsort(st,p-1)
    if(en-p-1>0):qsort(p+1,en)
def my_qsort(l,r):
    global List
    key=List[l]
    while l<r:
        while l<r and my_cmp(key,List[r]): r-=1
        if l<r: List[l]=List[r]
        while l<r and my_cmp(List[l],key): l+=1
        if l<r: List[r]=List[l]
    List[l]=key
    return l
def my_cmp(x,y):
    return x<=y
n=input()
num=map(int,raw_input().split())
List=num
qsort(0,n-1)
Max=0
j=0
for i in range(n):
    while j<n and num[j]<=2*num[i]: j+=1
    Max=max(Max,j-i)
print n-Max


#!/usr/bin/env python
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
def sort(List,st,en):
    if en-st<0: return
    p=_sort(List,st,en)
    if(p-st-1>0):sort(List,st,p-1)
    if(en-p-1>0):sort(List,p+1,en)
def _sort(List,l,r):
    key=List[l]
    while l<r:
        while l<r and _cmp(key,List[r]): r-=1
        if l<r: List[l]=List[r]
        while l<r and _cmp(List[l],key): l+=1
        if l<r: List[r]=List[l]
    List[l]=key
    return l
def _cmp(x,y): #自定义比较函数,相等返回true
    return x<=y
    #return x[0]>y[0] or (x[0]==y[0] and x[1]>=y[1])
def work():
    n=input()
    num=map(int,raw_input().split())
    sort(num,0,n-1)
    Max=0
    j=0
    for i in range(n):
        while j<n and num[j]<=2*num[i]: j+=1
        Max=max(Max,j-i)
    print n-Max
work()


#!/usr/bin/env python
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
def qsort(List,st,en):
    if en-st<=0: return
    #print List[st:en+1]
    p=my_qsort(List,st,en)
    if(p-st-1>0):qsort(List,st,p-1)
    if(en-p-1>0):qsort(List,p+1,en)
def my_qsort(List,l,r):
    key=List[l]
    while l<r:
        while l<r and my_cmp(key,List[r]): r-=1
        if l<r: List[l]=List[r]
        while l<r and my_cmp(List[l],key): l+=1
        if l<r: List[r]=List[l]
    List[l]=key
    return l
def my_cmp(x,y):
    return x<=y
n=input()
num=map(int,raw_input().split())
qsort(num,0,n-1)
Max=0
j=0
for i in range(n):
    while j<n and num[j]<=2*num[i]: j+=1
    Max=max(Max,j-i)
print n-Max


#!/usr/bin/env python
'''
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
'''
List=[]
def qsort(st,en):
    if en-st<=0: return
    p=my_qsort(st,en)
    if(p-st-1>0):qsort(st,p-1)
    if(en-p-1>0):qsort(p+1,en)
def my_qsort(l,r):
    global List
    key=List[l]
    while l<r:
        while l<r and my_cmp(key,List[r]): r-=1
        if l<r: List[l]=List[r]
        while l<r and my_cmp(List[l],key): l+=1
        if l<r: List[r]=List[l]
    List[l]=key
    return l
def my_cmp(x,y):
    return x<=y
n=input()
num=map(int,raw_input().split())
List=num
qsort(0,n-1)
Max=0
j=0
for i in range(n):
    while j<n and num[j]<=2*num[i]: j+=1
    Max=max(Max,j-i)
print n-Max


#!/usr/bin/env python
'''
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
'''
def sort(List,st,en):
    if en-st<0: return
    p=_sort(List,st,en)
    if(p-st-1>0):sort(List,st,p-1)
    if(en-p-1>0):sort(List,p+1,en)
def _sort(List,l,r):
    key=List[l]
    while l<r:
        while l<r and _cmp(List[r],key): r-=1
        if l<r: List[l]=List[r]
        while l<r and _cmp(key,List[l]): l+=1
        if l<r: List[r]=List[l]
    List[l]=key
    return l
def _cmp(x,y): #自定义比较函数
    return x>y
    #return x[0]>y[0] or (x[0]==y[0] and x[1]>=y[1])
def work():
    n=input()
    num=map(int,raw_input().split())
    num.sort()
    Max=0
    j=0
    for i in range(n):
        while j<n and num[j]<=2*num[i]: j+=1
        Max=max(Max,j-i)
    print n-Max
work()


#!/usr/bin/env python
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
def sort(List,st,en):
    if en-st<0: return
    p=_sort(List,st,en)
    if(p-st-1>0):sort(List,st,p-1)
    if(en-p-1>0):sort(List,p+1,en)
def _sort(List,l,r):
    key=List[l]
    while l<r:
        while l<r and _cmp(List[r],key): r-=1
        if l<r: List[l]=List[r]
        while l<r and _cmp(key,List[l]): l+=1
        if l<r: List[r]=List[l]
    List[l]=key
    return l
def _cmp(x,y): #自定义比较函数
    return x>y
    #return x[0]>y[0] or (x[0]==y[0] and x[1]>=y[1])
def work():
    n=input()
    num=map(int,raw_input().split())
    num.sort()
    Max=0
    j=0
    for i in range(n):
        while j<n and num[j]<=2*num[i]: j+=1
        Max=max(Max,j-i)
    print n-Max
work()


#!/usr/bin/env python
'''
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
'''
def sort(List,st,en):
    if en-st<0: return
    p=_sort(List,st,en)
    if(p-st-1>0):sort(List,st,p-1)
    if(en-p-1>0):sort(List,p+1,en)
def _sort(List,l,r):
    key=List[l]
    while l<r:
        while l<r and _cmp(key,List[r]): r-=1
        if l<r: List[l]=List[r]
        while l<r and _cmp(List[l],key): l+=1
        if l<r: List[r]=List[l]
    List[l]=key
    return l
def _cmp(x,y): #自定义比较函数,相等返回true
    return x<=y
    #return x[0]>y[0] or (x[0]==y[0] and x[1]>=y[1])

n=int(input())
#print n
num=map(int,raw_input().split())
sort(num,0,n-1)
Max=0
j=0
for i in range(n):
    while j<n and num[j]<=2*num[i]: j+=1
    Max=max(Max,j-i)
print n-Max


#!/usr/bin/env python
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
n=input()
num=map(int,raw_input().split())
num.sort()
Max=0
j=0
for i in range(n):
    while j<n and num[j]<=2*num[i]: j+=1
    Max=max(Max,j-i)
print n-Max


#!/usr/bin/env python
'''
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
'''
def qsort(List,st,en):
    if en-st<=0: return
    #print List[st:en+1]
    p=my_qsort(List,st,en)
    if(p-st-1>0):qsort(List,st,p-1)
    if(en-p-1>0):qsort(List,p+1,en)
def my_qsort(List,l,r):
    key=List[l]
    while l<r:
        while l<r and my_cmp(key,List[r]): r-=1
        if l<r: List[l]=List[r]
        while l<r and my_cmp(List[l],key): l+=1
        if l<r: List[r]=List[l]
    List[l]=key
    return l
def my_cmp(x,y):
    return x<=y
n=input()
num=map(int,raw_input().split())
qsort(num,0,n-1)
Max=0
j=0
for i in range(n):
    while j<n and num[j]<=2*num[i]: j+=1
    Max=max(Max,j-i)
print n-Max


import sys
def io():
    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")
io()
n = int(sys.stdin.readline())
a = map(int, sys.stdin.readline().split())
a.sort()
ans = n + 10
i = j = 0
while j < n:
    while i < n and a[j] * 2 >= a[i]: i += 1
    ans = min(ans, j + n - i)
    j += 1
print ans


from collections import Counter
from sys import stdin
stdin = open("input.txt", "r")
n = int(raw_input())
c = Counter(map(int, raw_input().split()))
res = [a for a in (sum((c[y] for y in c.keys() if y > 2 * x)) for x in c.keys()) if a > 0]
if len(res) > 0:
    print min(res)
else:
    print 0


import sys

sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")

raw_input()
N = 5000 + 1

a = [0] * N
for i in map(int, raw_input().split()):
    a[i] += 1
b = a[:]
for i in xrange(1, N):
    a[i] += a[i - 1]
for i in reversed(xrange(N - 1)):
    b[i] += b[i + 1]

s, mins = 0, sys.maxint
for i in xrange(1, N):
    if i + i < N:
        mins = min(mins, a[i - 1] + b[2 * i + 1])

print mins


import sys

sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")

N = 5000
n = int(raw_input())
a = [0] * (N + 1)
for i in map(int, raw_input().split()):
    a[i] += 1
b = a[:]
for i in xrange(1, N + 1):
    a[i] += a[i - 1]
s = n
for i in xrange(1, N / 2 + 1):
    s = min(s, a[i - 1] + n - a[2 * i])

print s


from collections import Counter
import sys
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
n = int(raw_input())
c = Counter(map(int, raw_input().split()))
res = [a for a in (sum((c[y] for y in c.keys() if y > 2 * x or y < x)) for x in c.keys())]
if len(res) > 0:
    print min(res)
else:
    print 0


from collections import Counter
import sys
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
n = int(raw_input())
c = Counter(map(int, raw_input().split()))
print sorted(c.items())
res = [a for a in (sum((c[y] for y in c.keys() if y > 2 * x or y < x)) for x in c.keys()) if a > 0]
print res
if len(res) > 0:
    print min(res)
else:
    print 0


import sys

sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")

raw_input()
N = 5000 + 1

a = [0] * N
for i in map(int, raw_input().split()):
    a[i] += 1
b = a[:]
for i in xrange(1, N):
    a[i] += a[i - 1]
for i in reversed(xrange(N - 1)):
    b[i] += b[i + 1]

s, mins = 0, sys.maxint
for i in xrange(1, N / 2):
    mins = min(mins, a[i - 1] + b[2 * i + 1])

print mins


import sys

sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")

raw_input()
N = 5000 + 1

a = [0] * N
for i in map(int, raw_input().split()):
    a[i] += 1
b = a[:]
for i in xrange(1, N):
    a[i] += a[i - 1]
for i in reversed(xrange(N - 1)):
    b[i] += b[i + 1]

s, mins = 0, sys.maxint
for i in xrange(1, N):
    if i + i < N - 1:
        mins = min(mins, a[i - 1] + b[2 * i + 1])

print mins


import sys

sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")

n = int(raw_input())
c = [0] * 5001
for a in map(int, raw_input().split()):
    c[a] += 1

s, mins = 0, sys.maxint
for a in xrange(1, len(c)):
    if c[a] > 0:
        mins = min(mins, s + sum((c[b] for b in xrange(2 * a + 1, len(c)))))
        s += c[a]

print mins


from collections import Counter
n = int(raw_input())
c = Counter(map(int, raw_input().split()))
res = [a for a in (sum((c[y] for y in c.keys() if y > 2 * x)) for x in c.keys()) if a > 0]
if len(res) > 0:
    print min(res)
else:
    print 0


from collections import Counter
import sys
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
n = int(raw_input())
c = Counter(map(int, raw_input().split()))
res = [a for a in (sum((c[y] for y in c.keys() if y > 2 * x or y < x)) for x in c.keys()) if a > 0]
if len(res) > 0:
    print min(res)
else:
    print 0


from collections import Counter
import sys
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
n = int(raw_input())
c = Counter(map(int, raw_input().split()))
res = [a for a in (sum((c[y] for y in c.keys() if y > 2 * x)) for x in c.keys()) if a > 0]
if len(res) > 0:
    print min(res)
else:
    print 0


f = open("input.txt")
data = f.readlines()
n = int(data[0].rstrip())
inp = map(int,data[1].rstrip().split())
count=[0]*10010
cum_count=[0]*10010
for i in inp:
    count[i]+=1
for i in xrange(1,10010):
    cum_count[i]=cum_count[i-1]+count[i]
ans = n+1
cur = 0
for i in xrange(1,5001):
    ans = min(cur+cum_count[10009]-cum_count[2*i],ans)
    cur+=count[i]
f.close()
f=open("output.txt","w")
f.write(str(ans)+"\n")
f.close()


f = open("input.txt")
data = f.readlines()
n = int(data[0].rstrip())
inp = map(int,data[1].rstrip().split())
count=[0]*10010
cum_count=[0]*10010
for i in inp:
    count[i]+=1
for i in xrange(1,10010):
    cum_count[i]=cum_count[i-1]+count[i]
ans = n+1
cur = 0
for i in xrange(1,5010):
    ans = min(cur+cum_count[10009]-cum_count[2*i],ans)
    cur+=count[i]
f.close()
f=open("output.txt")
f.write(str(ans)+"\n")
f.close()


import sys
sys.stdin=open("input.txt")
sys.stdout=open("output.txt", 'w')
n=input()
c=[0]*5001
for e in map(int, raw_input().split()):
    c[e]+=1
print n-max([(sum(c[i:2*i+1]),i) for i in range(2501)])[0]


n=int(raw_input())
a=map(int,raw_input().split())
a.sort()
m=1000000
arr=[0]*10001
for x in a:
	arr[x]+=1
for i in range(1,10001):
	arr[i]+=arr[i-1]
#print arr[1:10]
for i in range(0,n):
	x=arr[2*a[i]]-i
	x=n-x
	if(m>x):
		m=x
if(m!=1000000):
	print m
else:
	print 0


n=int(raw_input())
a=map(int,raw_input().split(" "))
a.sort()
m=1000000
arr=[0]*10001
for x in a:
	arr[x]+=1
for i in range(1,10001):
	arr[i]+=arr[i-1]
#print arr[1:10]
for i in range(0,n):
	x=arr[2*a[i]]-i
	x=n-x
	if(m>x):
		m=x
if(m!=1000000):
	print m
else:
	print 0


import sys
sys.stdin=open("input.txt")
sys.stdout=open("output.txt", 'w')
n=int(raw_input())
a=map(int,raw_input().split())
a.sort()
m=1000000
arr=[0]*10001
for x in a:
	arr[x]+=1
for i in range(1,10001):
	arr[i]+=arr[i-1]
#print arr[1:10]
for i in range(0,n):
	x=arr[2*a[i]]-i
	x=n-x
	if(m>x):
		m=x
if(m!=1000000):
	print m
else:
	print 0


lines = tuple(open('input.txt', 'r'))
output = open('output.txt','w')
n = int(lines[0])
values = map(int, lines[1].split())
values.sort()
x = values[0]
index = 0
for i in range(n):
    if values[n - i - 1] <= 2 * x:
        index = i
        break
print str(index)
output.write('%d' % index)


n = int(raw_input())
values = map(int, raw_input().split())
values.sort()
index = 0
for i in range(n):
    if values[n - i - 1] <= 2 * values[0]:
        index = i
        break
print index


n = int(raw_input())
values = map(int, raw_input().split())
values.sort()
x = values[0]
index = 0
for i in range(n):
    if values[n - i - 1] <= 2 * x:
        index = i
        break
print index


def count_elements(value, count):
    array = count[value: 2 * value + 1]
    count2 = 0
    for item in array:
        if item != 0:
            count2 += item
    return count2
lines = tuple(open('input.txt', 'r'))
output = open('output.txt','w')
n = int(lines[0])
values = map(int, lines[1].split())
count = [0] * (5001)
sum_array = [0] * (50001)
max_present = 0
index = 0
for value in values:
    count[value] += 1
for i in range(1, 5001):
    sum_array[i] = sum_array[i - 1] + count[i]
for i in range(1, 2501):
    current_present = sum_array[2 * i] - sum_array[i - 1]
    if(current_present > max_present):
        max_present = current_present
output.write('%d' % (n - max_present))


def count_elements(value, count):
    array = count[value: 2 * value + 1]
    count2 = 0
    for item in array:
        if item != 0:
            count2 += item
    return count2
lines = tuple(open('input.txt', 'r'))
output = open('output.txt','w')
n = int(lines[0])
values = map(int, lines[1].split())
count = [0] * (5001)
result = []
index = 0
for value in values:
    count[value] += 1
for value in values:
    result.append(count_elements(value, count))
output.write('%d' % (n - index))


def getCombinations(array,k):
    new_array = []
    for i in xrange(k):
        new_array.append(0)

    return getCombinationsUtil(array,0,new_array,0,k)

def getCombinationsUtil(array,array_index,current_combo, current_combo_index,k):
    if current_combo_index == k:
        return [current_combo[:]]

    if array_index >= len(array):
        return []
    current_combo[current_combo_index] = array[array_index]
    comb1 = getCombinationsUtil(array,array_index+1,current_combo,current_combo_index+1,k)
    comb2 = getCombinationsUtil(array,array_index+1,current_combo,current_combo_index,k)
    return comb1 + comb2

lines = tuple(open('input.txt', 'r'))
output = open('output.txt','w')
n = int(lines[0])
values = map(int, lines[1].split())
values.sort()
index = 0
for i in range(2, n + 1):
    found = False
    combinations = getCombinations(values, n + 2 - i)
    for comb in combinations:
        if comb[n + 1 - i] <= 2 * comb[0]:
            found = True
            index = n - i + 2
            break
    if found:
        break
output.write('%d' % (n - index))


def count_elements(value, count):
    array = count[value: 2 * value + 1]
    count2 = 0
    for item in array:
        if item != 0:
            count2 += item
    return count2
lines = tuple(open('input.txt', 'r'))
output = open('output.txt','w')
n = int(lines[0])
values = map(int, lines[1].split())
count = [0] * (5001)
sum_array = [0] * (50001)
max_present = 0
index = 0
for value in values:
    count[value] += 1
for i in range(1, 5000):
    sum_array[i] = sum_array[i - 1] + count[i]
for i in range(1, 2501):
    current_present = sum_array[2 * i] - sum_array[i - 1]
    if(current_present > max_present):
        max_present = current_present
output.write('%d' % (n - max_present))


def count_elements(value, count):
    array = count[value: 2 * value + 1]
    count2 = 0
    for item in array:
        if item != 0:
            count2 += item
    return count2
lines = tuple(open('input.txt', 'r'))
output = open('output.txt','w')
n = int(lines[0])
values = map(int, lines[1].split())
count = [0] * (5001)
result = []
index = 0
for value in values:
    count[value] += 1
for value in values:
    result.append(count_elements(value, count))
print n - max(result)


def count_elements(value, count):
    array = count[value: 2 * value + 1]
    count2 = 0
    for item in array:
        if item != 0:
            count2 += item
    return count2
lines = tuple(open('input.txt', 'r'))
output = open('output.txt','w')
n = int(lines[0])
values = map(int, lines[1].split())
count = [0] * (5001)
result = []
for value in values:
    count[value] += 1
for value in values:
    result.append(count_elements(value, count))
output.write('%d' % (n - max(result)))


import sys
from bisect import bisect_right

sys.stdin=open("input.txt", "r")
sys.stdout=open("output.txt", "w")

n = int(raw_input())
cs = map(int, raw_input().split())
cs.sort()

minn = int(10e9)
for i in range(len(cs)):
    u = cs[i]
    v = 2*u
    j = bisect_right(cs, v)
    total = i + (len(cs)-j)
    if total < minn:
        minn = total

print minn


def binary_search(start, end, target):
  mid = (start + end)/2
  if start >= end:
    return start
  elif c[mid+1] <= target:
    return binary_search(mid+1, end, target)
  elif c[mid] > target:
    return binary_search(start, mid, target)
  else:
    return mid

def linear_search(start, target):
  for i in range(start, n-1):
    if c[i] <= target < c[i+1]:
      return i
      break
  return n-1

infile = open("input.txt","r")
outfile = open("output.txt","w")

n = int(infile.readline())
c = map(int, infile.readline().split())
c.sort()

min_diff = n
start = 0
for i in range(n):
  start = linear_search(start, 2*c[i])
  diff = i + (n - 1 - start)
  if diff < min_diff:
    min_diff = diff
  if start == n-1:
    break

outfile.write('%d'%min_diff)
infile.close()
outfile.close()


#def binary_search(start, end, target):
#  mid = (start + end)/2
#  if start >= end:
#    return start
#  elif c[mid+1] <= target:
#    return binary_search(mid+1, end, target)
#  elif c[mid] > target:
#    return binary_search(start, mid, target)
#  else:
#    return mid

infile = open("input.txt","r")
outfile = open("output.txt","w")

n = int(infile.readline())
c = map(int, infile.readline().split())
c.sort()

min_diff = n
start = 0
end = 0

for start in range(n):
  target = 2*c[start]
  while end < n-1 and not c[end] <= start < c[end+1]:
    end += 1
  min_diff = min(min_diff, start + n - 1 - end)
  if end == n:
    break

outfile.write('%d'%min_diff)
infile.close()
outfile.close()


infile = open("input.txt","r")
outfile = open("output.txt","w")

n = int(infile.readline())
c = map(int, infile.readline().split())
c.sort()

min_diff = n
end = 0

for start in range(n):
  target = 2*c[start]
  while end < n-1 and not (c[end] <= target < c[end+1]):
    end += 1
  if end == n-1 and target > c[-1]:
    min_diff = min(min_diff, start + n - end)
    break
  else:
    min_diff = min(min_diff, start + n - 1 - end)
    if end == n-1:
      break

outfile.write('%d'%min_diff)
infile.close()
outfile.close()


def binary_search(start, end, target):
  mid = (start + end)/2
  if start >= end:
    return start
  elif c[mid+1] <= target:
    return binary_search(mid+1, end, target)
  elif c[mid] > target:
    return binary_search(start, mid, target)
  else:
    return mid

infile = open("input.txt","r")
outfile = open("output.txt","w")

n = int(infile.readline())
c = sorted(map(int, infile.readline().split()))

min_diff = n
start = 0
for i in range(n):
  start = binary_search(start, n-1, 2*c[i])
  diff = i + (n - 1 - start)
  if diff < min_diff:
    min_diff = diff

outfile.write('%d'%min_diff)
infile.close()
outfile.close()


infile = open("input.txt","r")
outfile = open("output.txt","w")

n = int(infile.readline())
c = map(int, infile.readline().split())
c.sort()

min_diff = n
end = 0

for start in range(n):
  target = 2*c[start]
  if target > c[-1]:
    min_diff = min(min_diff, start)
    break

  while end < n-1 and not (c[end] <= target < c[end+1]):
    end += 1
  min_diff = min(min_diff, start + n - 1 - end)

outfile.write('%d'%min_diff)
infile.close()
outfile.close()


def binary_search(start, end, target):
  mid = (start + end)/2
  if start >= end:
    return start
  elif c[mid+1] <= target:
    return binary_search(mid+1, end, target)
  elif c[mid] > target:
    return binary_search(start, mid, target)
  else:
    return mid

def linear_search(start, target):
  for i in range(start, n-1):
    if c[i] <= target < c[i+1]:
      return i
      break
  return n-1

infile = open("input.txt","r")
outfile = open("output.txt","w")

n = int(infile.readline())
c = sorted(map(int, infile.readline().split()))

min_diff = n
start = 0
for i in range(n):
  start = linear_search(start, 2*c[i])
  diff = i + (n - 1 - start)
  if diff < min_diff:
    min_diff = diff

outfile.write('%d'%min_diff)
infile.close()
outfile.close()


def binary_search(start, end, target):
  mid = (start + end)/2
  if start >= end:
    return start
  elif c[mid+1] <= target:
    return binary_search(mid+1, end, target)
  elif c[mid] > target:
    return binary_search(start, mid, target)
  else:
    return mid

def linear_search(start, target):
  for i in range(start, n-1):
    if c[i] <= target < c[i+1]:
      return i
      break
  return n-1

infile = open("input.txt","r")
outfile = open("output.txt","w")

n = int(infile.readline())
c = sorted(map(int, infile.readline().split()))

min_diff = n
start = 0
for i in range(n):
  start = linear_search(start, 2*c[i])
  diff = i + (n - 1 - start)
  if diff < min_diff:
    min_diff = diff
  if start == n-1:
    break

outfile.write('%d'%min_diff)
infile.close()
outfile.close()


#def binary_search(start, end, target):
#  mid = (start + end)/2
#  if start >= end:
#    return start
#  elif c[mid+1] <= target:
#    return binary_search(mid+1, end, target)
#  elif c[mid] > target:
#    return binary_search(start, mid, target)
#  else:
#    return mid

def linear_search(start, target):
  for i in range(start, n-1):
    if c[i] <= target < c[i+1]:
      return i
  return n-1

infile = open("input.txt","r")
outfile = open("output.txt","w")

n = int(infile.readline())
c = map(int, infile.readline().split())
c.sort()

min_diff = n
start = 0
i = 0
while start < n-1:
  start = linear_search(start, 2*c[i])
  min_diff = min(min_diff, i + n - 1 - start)
  i += 1

outfile.write('%d'%min_diff)
infile.close()
outfile.close()


f=open('input.txt','r')
g=open('output.txt','w')

n=int(f.readline())
c=map(int,f.readline().split())

c.sort()
b1,l1,w1=0,n-1,0
b2,l2,w2=0,n-1,0

while c[b1]*2<c[l1]:
    b1+=1
    w1+=1

while c[b2]*2<c[l2]:
    l2-=1
    w2+=1

print min(w1,w2)


f=open('input.txt','r')
g=open('output.txt','w')

n=int(f.readline())
c=map(int,f.readline().split())

c.sort()
b1,l1,w1=0,n-1,0
b2,l2,w2=0,n-1,0

while c[b1]*2<c[l1]:
    b1+=1
    w1+=1

while c[b2]*2<c[l2]:
    l2-=1
    w2+=1

g.write(str(min(w1,w2)))

f.close()
g.close()


import sys
sys.stdin=open("input.txt")
sys.stdout=open("output.txt", 'w')
n=input()
c=[0]*5001
for e in map(int, raw_input().split()):
    c[e]+=1
print n-max([(sum(c[i:2*i+1]),i) for i in range(2501)])[0]


f=open('input.txt','r')
g=open('output.txt','w')

n=int(f.readline())
c=map(int,f.readline().split())

c.sort()
b1,l1,w1=0,n-1,0
b2,l2,w2=0,n-1,0
b3,l3,w3=0,n-1,0

while c[b1]*2<c[l1]:
    b1+=1
    w1+=1

while c[b2]*2<c[l2]:
    l2-=1
    w2+=1

o=True
while c[b3]*2<c[l3]:
    if o:
        b3+=1
    else:
        l3-=1
    o= not o
    w3+=1

g.write(str(min(w1,w2,w3)))

f.close()
g.close()


n = int(raw_input())

data = list(map(int, raw_input().split()))

data.sort()
ans = n
for i in range(0, n-1):
    if i and data[i] == data[i-1]:
        continue
    left = i+1
    right = n
    key = 2*data[i]
    while left<right:
        mid = int((left+right)/2)
        if key >= data[mid]:
            left = mid + 1
        else:
            right = mid
    if left >= n or data[left] <= key:
        ans = min(ans, i+n-left)
    else:
        ans = min(ans, i+n-left+1)
    if left>=n:
        break
if n <= 1:
    print '0'
else:
    print ans


from bisect import bisect_right
import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n = int(raw_input())
data = list(map(int, raw_input().split()))
data.sort()
ans = n
for i in range(n):
    ans = min(ans, i+n-bisect_right(data,data[i]*2))
print ans


n = int(raw_input())
data = list(map(int, raw_input().split()))
data.sort()
ans = n
for i in range(0, n-1):
    if i>0 and data[i] == data[i-1]:
        continue
    left = i+1
    right = n
    key = 2*data[i]
    while left<right:
        mid = int((left+right)/2)
        if key >= data[mid]:
            left = mid + 1
        else:
            right = mid
    if left >= n or data[left] > key:
        ans = min(ans, i+n-left)
    else:
        ans = min(ans, i+n-left+1)
    if left>=n:
        break
if n <= 1:
    print '0'
else:
    print ans


import sys
n = int(raw_input())

data = list(map(int, raw_input().split()))

data.sort()
ans = n
for i in range(0, n-1):
    if i and data[i] == data[i-1]:
        continue
    left = i+1
    right = n
    key = 2*data[i]
    while left<right:
        mid = int((left+right)/2)
        if key >= data[mid]:
            left = mid + 1
        else:
            right = mid
    if left >= n or data[left] <= key:
        ans = min(ans, i+n-left)
    else:
        ans = min(ans, i+n-left+1)
    if left>=n:
        break
if n <= 1:
    print '0'
else:
    print ans


from bisect import bisect_right
n = int(raw_input())
data = sorted(map(int, raw_input().split()))
ans = n
for i in range(n):
    ans = min(ans, i+n-bisect_right(data,data[i]*2))
print ans


from bisect import bisect_right

n = int(raw_input())
data = list(map(int, raw_input().split(' ')))
data.sort()
ans = n
for i in range(n):
    ans = min(ans, i+n-bisect_right(data,data[i]*2))
print ans


from bisect import bisect_right

n = int(raw_input())
data = list(map(int, raw_input().split()))
data.sort()
ans = n
for i in range(n):
    ans = min(ans, i+n-bisect_right(data,data[i]*2))
print ans


n = int(raw_input())
data = list(map(int, raw_input().split(' ')))
data.sort()
ans = n
for i in range(0, n-1):
    if i>0 and data[i] == data[i-1]:
        continue
    left = i+1
    right = n
    key = 2*data[i]
    while left<right:
        mid = int((left+right)/2)
        if key >= data[mid]:
            left = mid + 1
        else:
            right = mid
    if left >= n or data[left] > key:
        ans = min(ans, i+n-left)
    else:
        ans = min(ans, i+n-left+1)
    if left>=n:
        break
if n <= 1:
    print '0'
else:
    print ans


#from bisect import bisect_right
import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n = int(raw_input())
data = list(map(int, raw_input().split()))
data.sort()
x=0
y=1
ans = n
while x<n and y<n:
    while y<n and 2*data[x]>=data[y]:
        y+=1
    #print x+n-y
    ans = min(ans, x+n-y)
    x+=1
print ans


n = int(raw_input())

data = list(map(int, raw_input().split()))

data.sort()
ans = n
for i in range(0, n-1):
    print i, data[i]
    if i and data[i] == data[i-1]:
        continue
    left = i+1
    right = n
    key = 2*data[i]
    while left<right:
        mid = int((left+right)/2)
        if key >= data[mid]:
            left = mid + 1
        else:
            right = mid
    if left >= n or data[left] <= key:
        ans = min(ans, i+n-left)
    else:
        ans = min(ans, i+n-left+1)
    if left>=n:
        break
if n <= 1:
    print '0'
else:
    print ans


#from bisect import bisect_right
import sys
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
n = int(raw_input())
data = list(map(int, raw_input().split()))
data.sort()
x=0
y=1
ans = n
while x<n and y<n:
    while y<n and 2*data[x]>=data[y]:
        y+=1
    #print x+n-y
    ans = min(ans, x+n-y)
    x+=1
print ans


from Queue import * # Queue, LifoQueue, PriorityQueue
from bisect import * #bisect, insort
from datetime import *
from collections import * #deque, Counter,OrderedDict,defaultdict
import calendar
import heapq
import math
import copy
import itertools
import sys
myread = lambda : map(int,raw_input().split())
def solver():

    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")

    n = input()

    num = [0] * (5000+1)

    for i in myread():
        num[i] += 1

    for i in range(1,n+1):
        num[i] += num[i-1]

    ans = n

    for i in range(n/2 + 1):
        ans = min(ans,num[i-1] + n - num[2*i])

    print ans

if __name__ == "__main__":
    solver()


from Queue import * # Queue, LifoQueue, PriorityQueue
from bisect import * #bisect, insort
from datetime import *
from collections import * #deque, Counter,OrderedDict,defaultdict
import calendar
import heapq
import math
import copy
import itertools
myread = lambda : map(int,raw_input().split())
def solver():

    fin = open("input.txt","r")
    fout = open("output.txt","w")

    n = int(fin.readline()[:-1])
    num = fin.readline()[:-1]
    num = map(int,num.split())

    num.sort()
    ans = n
    for i in range(n):
        if ans <= i:
            break
        lp = i
        up = n - 1
        now_num = num[i]
        while lp != up:
            mid = (lp + up) / 2 + 1
            if 2 * now_num < num[mid]:
                up = mid - 1
            else:
                lp = mid

        ans = min(ans,n-(up-i)-1)

    fout.write(str(ans))

if __name__ == "__main__":
    solver()


from Queue import * # Queue, LifoQueue, PriorityQueue
from bisect import * #bisect, insort
from datetime import *
from collections import * #deque, Counter,OrderedDict,defaultdict
import calendar
import heapq
import math
import copy
import itertools
import sys
myread = lambda : map(int,raw_input().split())
def solver():

    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")

    n = input()
    num = myread()

    num.sort()
    ans = n
    for i in range(n):
        if ans <= i:
            break
        lp = i
        up = n - 1
        now_num = num[i]
        while lp != up:
            mid = (lp + up) / 2 + 1
            if 2 * now_num < num[mid]:
                up = mid - 1
            else:
                lp = mid

        ans = min(ans,n-(up-i)-1)

    fout.write(str(ans))

if __name__ == "__main__":
    solver()


from Queue import * # Queue, LifoQueue, PriorityQueue
from bisect import * #bisect, insort
from datetime import *
from collections import * #deque, Counter,OrderedDict,defaultdict
import calendar
import heapq
import math
import copy
import itertools
import sys
myread = lambda : map(int,raw_input().split())
def solver():

    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")

    n = input()

    num = [0] * (5000+1)

    for i in myread():
        num[i] += 1

    for i in range(1,5000+1):
        num[i] += num[i-1]

    ans = n

    for i in range(1,5000/2 + 1):
        ans = min(ans,num[i-1] + n - num[2*i])

    print ans

if __name__ == "__main__":
    solver()


from Queue import * # Queue, LifoQueue, PriorityQueue
from bisect import * #bisect, insort
from datetime import *
from collections import * #deque, Counter,OrderedDict,defaultdict
import calendar
import heapq
import math
import copy
import itertools
myread = lambda : map(int,raw_input().split())
def solver():

    fin = open("input.txt","r")
    fout = open("output.txt","w")

    n = int(fin.readline()[:-1])
    num = fin.readline()[:-1]
    num = map(int,num.split())

    num.sort()
    ans = n
    for i in range(n):
        lp = i
        up = n - 1
        now_num = num[i]
        while lp != up:
            mid = (lp + up) / 2 + 1
            if 2 * now_num < num[mid]:
                up = mid - 1
            else:
                lp = mid

        ans = min(ans,n-(up-i)-1)

    fout.write(str(ans))

if __name__ == "__main__":
    solver()


from Queue import * # Queue, LifoQueue, PriorityQueue
from bisect import * #bisect, insort
from datetime import *
from collections import * #deque, Counter,OrderedDict,defaultdict
import calendar
import heapq
import math
import copy
import itertools
import sys
myread = lambda : map(int,raw_input().split())
def solver():

    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")

    n = input()

    num = [0] * (5000+1)

    for i in myread():
        num[i] += 1

    for i in range(1,n+1):
        num[i] += num[i-1]

    ans = n

    for i in range(n/2 + 1):
        ans = min(ans,num[i-1] + n - num[2*i + 1])

    print ans

if __name__ == "__main__":
    solver()


import sys
sys.stdin=open("input.txt")
sys.stdout=open("output.txt", 'w')
n=input()
c=[0]*5001
for e in map(int, raw_input().split()):
    c[e]+=1
print n-max([(sum(c[i:2*i+1]),i) for i in range(2501)])[0]


n=input()
c=[0]*5001
for e in map(int, raw_input().split()):
    c[e]+=1
print n-max([(sum(c[i:2*i+1]),i) for i in range(2501)])[0]


import sys
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n = input()
c = [0] * 5001
for x in map(int, raw_input().split()):
	c[x] += 1
for i in range(1, 5001):
	c[i] += c[i - 1]
r = n
for i in range(1, 2501):
	r = min(r, c[i - 1] + n - c[i * 2])
print r


import sys
from bisect import *
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n = input()
a = sorted(map(int, raw_input().split()))
r = n
for i in range(n):
	r = min(r, n - bisect_right(a, a[i] * 2) + i)
print r


with open('input.txt') as file:
    n = int(file.readline())
    a = sorted(map(int, file.readline().split()))

ret = float('inf')
size = len(a)
left = right = 0
while right < size:
    while right < size and (a[right] + a[left] - 1) / a[left] <= 2:
        right += 1
    ret = min(ret, left + size - right)
    while right < size and (a[right] + a[left] - 1) / a[left] > 2:
        left += 1

with open('output.txt', 'w') as file:
    file.write('%d' % ret)


import re

class Task:
    c = []

    answer = ''

    def getData(self):
        n = int(raw_input().strip())
        self.c = [int(x) for x in raw_input().strip().split(' ')]

    def solve(self):
        c = sorted(self.c)
        l, r, answer = 0, 1, len(c) - 1
        while r < len(c):
            if c[r] <= c[l] * 2:
                r += 1
            else:
                l += 1
            answer = min(answer, len(c) - (r - l))
        self.answer = answer

    def printAnswer(self):
        print self.answer

task = Task()
task.getData()
task.solve()
task.printAnswer()


import re

class Task:
    c = []

    answer = 0

    def getData(self):
        fin = open('input.txt', 'r')
        fin.readline()
        self.c = [int(x) for x in fin.readline().strip().split(' ')]

    def solve(self):
        c = sorted(self.c)
        l, r, answer = 0, 1, len(c) - 1
        while r < len(c):
            if c[r] <= c[l] * 2:
                r += 1
            else:
                l += 1
            answer = min(answer, len(c) - (r - l))
        self.answer = answer

    def printAnswer(self):
        fout = open('output.txt', 'w')
        fout.write(str(self.answer))

task = Task()
task.getData()
task.solve()
task.printAnswer()


import re

class Task:
    c = []

    answer = ''

    def getData(self):
        raw_input()
        self.c = [int(x) for x in raw_input().strip().split(' ')]

    def solve(self):
        c = sorted(self.c)
        l, r, answer = 0, 1, len(c) - 1
        while r < len(c):
            if c[r] <= c[l] * 2:
                r += 1
            else:
                l += 1
            answer = min(answer, len(c) - (r - l))
        self.answer = answer

    def printAnswer(self):
        print self.answer

task = Task()
task.getData()
task.solve()
task.printAnswer()


import re

class Task:
    c = []

    answer = ''

    def getData(self):
        n = input()
        self.c = [int(x) for x in raw_input().strip().split(' ')]

    def solve(self):
        c = sorted(self.c)
        l, r, answer = 0, 1, len(c) - 1
        while r < len(c):
            if c[r] <= c[l] * 2:
                r += 1
            else:
                l += 1
            answer = min(answer, len(c) - (r - l))
        self.answer = answer

    def printAnswer(self):
        print self.answer

task = Task()
task.getData()
task.solve()
task.printAnswer()


import bisect
import sys
sys.stdin=open('input.txt','r')
sys.stdout=open('output.txt','w')
n = input()
a = map(int, raw_input().split())
a.sort()
ans = n
for i in xrange(n):
	val = i + n - bisect.bisect_right(a,a[i]*2)
	ans = min(ans, val)
print ans


import sys
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
n = int(raw_input())
c = map(int, raw_input().split())
c.sort()
max_number = 0
for i in xrange(n):
    large = c[i] * 2
    begin = i
    end = n - 1
    while begin < end:
        middle = (begin + end) / 2
        if c[middle] < large:
            begin = middle + 1
        elif c[middle] > large:
            end = middle - 1
        else:
            begin = middle
            end = middle
    while end < n - 1 and c[end] == c[end + 1]:
        end += 1
    number = end - i + 1
    if number > max_number:
        max_number = number
print n - max_number


import sys
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
n = int(raw_input())
c = map(int, raw_input().split())
c.sort()
c_double = []
for i in xrange(n):
    c_double.append(c[i] * 2)
i = 0
j = 0
max_ = 0
while i < n and j < n:
    while j < n and c[j] <= c_double[i]:
        j += 1
    max_ = max(max_, j - i)
    i += 1
print n - max_


# ---------------------------------------------------
# -- Codeforces #253 - Problem B (Physics Practical)
# -- http://codeforces.com/contest/253/problem/B
# -- Author: James Lawson <mail@jameslawson.io>
# --------------------------------------------------

from sys import stdin, stdout

def main(xs):
  count = 0
  N = len(xs)
  xs.sort()

  start, end = 0, N
  while (end - start > 1) and (2*xs[start] < xs[end - 1]):
    left_diff = xs[start + 1] - xs[start]
    right_diff = xs[end - 1] - xs[end - 2]
    if left_diff > right_diff:
      start += 1
      count += 1
    else:
      end -= 1
      count += 1

  return count

if __name__ == '__main__':
  stdin = open('input.txt', 'r')
  stdout = open('output.txt', 'w')
  _ = stdin.readline()
  xs = map(int, stdin.readline().rstrip().split())
  result = main(xs)
  stdout.write(str(result) + '\n')


# ---------------------------------------------------
# -- Codeforces #253 - Problem B (Physics Practical)
# -- http://codeforces.com/contest/253/problem/B
# -- Author: James Lawson <mail@jameslawson.io>
# --------------------------------------------------

from sys import stdin, stdout
from bisect import bisect_right

def main(xs):
  min_removed = float('+inf')
  xs.sort()
  N = len(xs)

  for i in range(N):
    j = bisect_right(xs, 2*xs[i])
    keep = j - i
    removed = N - keep
    min_removed = min(min_removed, removed)

  return min_removed

if __name__ == '__main__':
  stdin = open('input.txt', 'r')
  stdout = open('output.txt', 'w')
  _ = stdin.readline()
  xs = map(int, stdin.readline().rstrip().split())
  result = main(xs)
  stdout.write(str(result) + '\n')


n = int(raw_input())
c = map(int, raw_input().split())
c.sort()
c.append(100000)
i = 0; j = 0; ans = 0
for i in range(n):
	while c[j] <= 2*c[i]: j += 1
	ans = max(ans, j-i)

print(n-ans)


fin = open('input.txt', 'r')
fout = open('output.txt', 'w')
n = int(fin.readline())
c = map(int, fin.readline().split())
c.sort()
c.append(100000)
i = 0; j = 0; ans = 0
for i in range(n):
	while c[j] <= 2*c[i]: j += 1
	ans = max(ans, j-i)
	# print i,j

fout.write(str(n-ans))


import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Main implements Runnable
{
    static class InputReader
    {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(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 String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
        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 *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
                return res * sgn;
        }

        public double nextDouble()
        {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-')
            {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.')
            {
                c = read();
                double m = 1;
                while (!isSpaceChar(c))
                {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString()
        {
            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 String next()
        {
            return readString();
        }

        public interface SpaceCharFilter
        {
            public boolean isSpaceChar(int ch);
        }
    }

    // if modulo is required set value accordingly
    public static long[][] matrixMultiply2dL(long t[][],long m[][])
    {
        long res[][]= new long[t.length][m[0].length];

        for(int i=0;i<t.length;i++)
        {
            for(int j=0;j<m[0].length;j++)
            {
                res[i][j]=0;
                for(int k=0;k<t[0].length;k++)
                {
                    res[i][j]+=t[i][k]+m[k][j];
                }
            }
        }

        return res;
    }

    static long combination(long n,long r)
    {
        long ans=1;
        for(long i=0;i<r;i++)
        {
            ans=(ans*(n-i))/(i+1);
        }
        return ans;
    }

    public static void main(String args[]) throws Exception
    {
        new Thread(null, new Main(),"Main",1<<27).start();
    }
    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);
        int t = sc.nextInt();
        while(t-->0){
            int n = sc.nextInt();
            char fnum[] = new char[n];
            char snum[] = new char[n];
            int ind = n;
            boolean f = false;
            String x = sc.next();
            char a[] = x.toCharArray();
            for (int i=0;i<n;i++) {
                char c = a[i];
                if(c=='0'){
                    fnum[i] = '0';
                    snum[i] = '0';
                }
                else if(c=='1'){
                    ind = i;
                    f = true;
                    break;
                }
                else{
                    fnum[i] = '1';
                    snum[i] = '1';
                }
            }
            if(f){
                fnum[ind] = '1';
                snum[ind] = '0';
                for (int i=ind+1; i<n; i++) {
                    fnum[i] = '0';
                    snum[i] = a[i];
                }
            }
            System.out.println(String.valueOf(fnum));
            System.out.println(String.valueOf(snum));
        }
        System.out.flush();
        w.close();
    }
}
//https://codeforces.com/problemset/problem/1311/B
//https://codeforces.com/problemset/problem/1326/B


import java.util.Scanner;

public class xor {

	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		while(t-- > 0)
		{
			int n = s.nextInt();
			String q = s.next();
			StringBuilder a = new StringBuilder("");
			StringBuilder b= new StringBuilder("");
			for(int i=0;i<n;i++)
			{
				int temp = Integer.parseInt(q.charAt(i)+"");
				if(temp==0) {
					int t1 = getVal(a.toString(),b.toString(),0,0);
					int t2 = getVal(a.toString(),b.toString(),1,2);
					int t3 = getVal(a.toString(),b.toString(),2,1);
					int sm = small(t1,t2,t3);
					if(sm == 1) {
						a.append(0);
						b.append(0);
					}
					else if(sm == 2) {
						a.append(1);
						b.append(2);
					}
					else {
						a.append(2);
						b.append(1);
					}

				}
				else if(temp==1) {
					int t1 = getVal(a.toString(),b.toString(),0,1);
					int t2 = getVal(a.toString(),b.toString(),1,0);
					int t3 = getVal(a.toString(),b.toString(),2,2);
					int sm = small(t1,t2,t3);
					if(sm == 1) {
						a.append(0);
						b.append(1);
					}
					else if(sm == 2) {
						a.append(1);
						b.append(0);
					}
					else {
						a.append(2);
						b.append(2);
					}
				}
				else {
					int t1 = getVal(a.toString(),b.toString(),0,2);
					int t2 = getVal(a.toString(),b.toString(),2,0);
					int t3 = getVal(a.toString(),b.toString(),1,1);
					int sm = small(t1,t2,t3);
					if(sm == 1) {
						a.append(0);
						b.append(2);
					}
					else if(sm == 2) {
						a.append(2);
						b.append(0);
					}
					else {
						a.append(1);
						b.append(1);
					}
				}
			}
			System.out.println(a.toString());
			System.out.println(b.toString());
		}

	}

	private static int small(int t1, int t2, int t3) {
		if(t1<t2) {
			if(t1<t3) {
				return 0;
			}
			else {
				return 3;
			}
		}
		else if(t2<t3) {
			return 2;
		}
		else return 3;
	}

	private static int getVal(String s1, String s2, int i, int j) {
		s1 += i;
		s2 += j;
		int st1 = Integer.parseInt(s1);
		int st2 = Integer.parseInt(s2);
		return Math.abs(st1-st2);
	}

}


import java.util.Scanner;

public class xor {

	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		while(t-- > 0)
		{
			int n = s.nextInt();
			String q = s.next();
			StringBuilder a = new StringBuilder("");
			StringBuilder b= new StringBuilder("");
			for(int i=0;i<n;i++)
			{
			    int temp = Integer.parseInt(q.charAt(i)+"");
				if(temp==0) {
					a.append(0);
					b.append(0);
				}
				else if(temp==1) {
					int t1 = getVal(a.toString(),b.toString(),0,1);
					int t2 = getVal(a.toString(),b.toString(),1,0);
					if(t1 < t2) {
						a.append(0);
						b.append(1);
					}
					else {
						a.append(1);
						b.append(0);
					}
				}
				else {
					a.append(1);
					b.append(1);
				}
			}
			System.out.println(a.toString());
			System.out.println(b.toString());
		}

	}

	private static int getVal(String s1, String s2, int i, int j) {
		s1 += i;
		s2 += j;
		int st1 = Integer.parseInt(s1);
		int st2 = Integer.parseInt(s2);
		return Math.abs(st1-st2);
	}

}


import java.util.Scanner;

public class xor {

	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		while(t-- > 0)
		{
			int n = s.nextInt();
			String q = s.next();
			StringBuilder a = new StringBuilder("");
			StringBuilder b= new StringBuilder("");
			for(int i=0;i<n;i++)
			{
				int temp = Integer.parseInt(q.charAt(i)+"");
				if(temp==0) {
					a.append(0);
					b.append(0);
				}
				else if(temp==1) {
					a.append(1);
					b.append(0);
				}
				else {
					a.append(1);
					b.append(1);
				}
			}
			System.out.println(a.toString());
			System.out.println(b.toString());
		}

	}

}


import java.util.Scanner;

public class xor {

	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		while(t-- > 0)
		{
			int n = s.nextInt();
			String q = s.next();
			StringBuilder a = new StringBuilder("");
			StringBuilder b= new StringBuilder("");
			for(int i=0;i<n;i++)
			{
				int temp = Integer.parseInt(q.charAt(i)+"");
				if(temp==0) {
					a.append(0);
					b.append(0);

				}
				else if(temp==1) {
					a.append(1);
					b.append(0);
					for(int j=(i+1);j<n;j++) {
						a.append(0);
						b.append(q.charAt(j));
					}
					break;
				}
				else {

					a.append(1);
					b.append(1);
				}
			}
			System.out.println(a.toString());
			System.out.println(b.toString());
		}

	}
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class C {
	public void run() throws Exception {
		FastScanner sc = new FastScanner();

		int t = sc.nextInt();
		for (int q = 0; q<t; q++) {
			int n = sc.nextInt();
			String x = sc.next();
			String a = "", b = "";
			boolean afi = false;
			int left = 0;
			for (int i = 0; i<n; i++) {
				if (x.charAt(i) == '0') {
					a+='0';
					b+='0';
				}
				else if (x.charAt(i) == '2') {
						a+='1';
						b+='1';
				}
				else {
						a+='1';
						b+='0';
						afi = true;
						left = i;
						break;
				}
			}
			if (afi) {
				int y = left;
				b+=x.substring(y+1,x.length());
				for (int i = y+1; i<n; i++) {
					a +='0';
				}
			}

			System.out.println(a);
			System.out.println(b);
		}
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}
	public static void main (String[] args) throws Exception {
		new C().run();
	}
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class C {
	public void run() throws Exception {
		FastScanner sc = new FastScanner();

		int t = sc.nextInt();
		for (int q = 0; q<t; q++) {
			int n = sc.nextInt();
			String x = sc.next();
			String a = "", b = "";
			boolean afi = false;
			for (int i = 0; i<n; i++) {
				if (x.charAt(i) == '0') {
					a+='0';
					b+='0';
				}
				else if (x.charAt(i) == '2') {
						a+='1';
						b+='1';
				}
				else {
						a+='1';
						b+='0';
						afi = true;
						break;
				}
			}
			if (afi) {
				int y = x.indexOf('1');
				b+=x.substring(y+1,x.length());
				for (int i = y+1; i<n; i++) {
					a +='0';
				}
			}

			System.out.println(a);
			System.out.println(b);
		}
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}
	public static void main (String[] args) throws Exception {
		new C().run();
	}
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class B {
	public void run() throws Exception {
		FastScanner sc = new FastScanner();

		int test = sc.nextInt();
		outer:
		for (int q = 0; q<test; q++) {
			int n = sc.nextInt();
			String s = sc.next();
			String a = "";
			String b = "";
			boolean big = false;
			for (int i = 0; i<n; i++) {
				if (s.charAt(i) == '0') {
					a+='0';
					b+='0';
				}
				else if (s.charAt(i) == '2') {
					if (big) {
						a+='0';
						b+='2';
					}
					else {
						a+='1';
						b+='1';
					}
				}
				else {
					if (big) {
						a+='0';
						b+='1';
					}
					else {
						a+='1';
						b+='0';
						big = true;
					}
				}
			}
			System.out.println(a);
			System.out.println(b);
		}
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}
	public static void main (String[] args) throws Exception {
		new B().run();
	}
	public void shuffleArray(int[] arr) {
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
        	int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
	}
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class C {
	public void run() throws Exception {
		FastScanner sc = new FastScanner();

		int t = sc.nextInt();
		for (int q = 0; q<t; q++) {
			int n = sc.nextInt();
			String x = sc.next();
			String a = "", b = "";
			boolean afi = false;
			for (int i = 0; i<x.length(); i++) {
				if (x.charAt(i) == '0') {
					a+='0';
					b+='0';
				}
				else if (x.charAt(i) == '2') {
					if (afi) {
						a+='0';
						b+='2';
					}
					else {
					a+='1';
					b+='1';
					}
				}
				else {
					if (afi) {
						a+='0';
						b+='1';
					}
					else {
						a+='1';
						b+='0';
						afi= true;
					}
				}
			}
			System.out.println(a);
			System.out.println(b);
		}
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}
	public static void main (String[] args) throws Exception {
		new C().run();
	}
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class B {
	public void run() throws Exception {
		FastScanner sc = new FastScanner();

		int test = sc.nextInt();
		outer:
		for (int q = 0; q<test; q++) {
			int n = sc.nextInt();
			String s = sc.next();
			StringBuilder a = new StringBuilder();
			StringBuilder b = new StringBuilder();
			boolean big = false;
			for (int i = 0; i<n; i++) {
				if (s.charAt(i) == '0') {
					a.append('0');
					b.append('0');
				}
				else if (s.charAt(i) == '2') {
					if (big) {
						a.append('0');
						b.append('2');
					}
					else {
						a.append('1');
						b.append('1');
					}
				}
				else {
					if (big) {
						a.append('0');
						b.append('1');
					}
					else {
						a.append('1');
						b.append('0');
						big = true;
					}
				}
			}
			System.out.println(a);
			System.out.println(b);
		}
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}
	public static void main (String[] args) throws Exception {
		new B().run();
	}
	public void shuffleArray(int[] arr) {
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
        	int tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
	}
}


import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class C {
	public void run() throws Exception {
		FastScanner sc = new FastScanner();

		int t = sc.nextInt();
		for (int q = 0; q<t; q++) {
			int n = sc.nextInt();
			String x = sc.next();
			String a = "", b = "";
			boolean afi = false;
			for (int i = 0; i<n; i++) {
				if (x.charAt(i) == '0') {
					a+='0';
					b+='0';
				}
				else if (x.charAt(i) == '2') {
					if (afi) {
						a+='0';
						b+='2';
					}
					else {
						a+='1';
						b+='1';
					}
				}
				else {
					if (afi) {
						a+='0';
						b+='1';
					}
					else {
						a+='1';
						b+='0';
						afi= true;
					}
				}
			}
			System.out.println(a);
			System.out.println(b);
		}
	}
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

	}
	public static void main (String[] args) throws Exception {
		new C().run();
	}
}


import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		JScanner in = new JScanner();
		StringBuilder out = new StringBuilder();

		int t = in.nextInt();

		while(t-->0)
		{
			int n = in.nextInt();
			String s = in.nextLine();

			String a = "1";
			String b = "1";

			int i;
			boolean amin = false;
			for(i=1; i<n; i++)
			{
				if(s.charAt(i) == '1' && !amin)
				{
					a += '1';
					b += '0';
					amin = true;
				}
				else if(s.charAt(i) == '1' && amin)
				{
					a += '0';
					b += '1';
				}
				else if(s.charAt(i) == '2')
				{
					a += '1';
					b += '1';
				}
				else
				{
					a += '0';
					b += '0';
				}
			}
			out.append(a).append("\n");
			out.append(b).append("\n");
		}
		System.out.println(out);

	}

	//Scanner
	static class JScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		JScanner in = new JScanner();
		StringBuilder out = new StringBuilder();

		int t = in.nextInt();

		while(t-->0)
		{
			int n = in.nextInt();
			String s = in.nextLine();

			StringBuilder a = new StringBuilder("1");
			StringBuilder b = new StringBuilder("1");

			int i;
			boolean amin = false;
			for(i=1; i<n; i++)
			{
				if(s.charAt(i) == '1' && amin)
				{
					a.append("0");
					b.append("1");
				}
				else if(s.charAt(i) == '1')
				{
					a.append("1");
					b.append("0");
					amin = true;
				}
				else if(s.charAt(i) == '2' && amin)
				{
					a.append("0");
					b.append("2");
				}
				else if(s.charAt(i) == '2')
				{
					a.append("1");
					b.append("1");
				}
				else if(s.charAt(i) == '2' && amin)
				{
					a.append("1");
					b.append("1");
				}
				else
				{
					a.append("0");
					b.append("0");
				}
			}
			out.append(a).append("\n");
			out.append(b).append("\n");
		}
		System.out.println(out);

	}

	//Scanner
	static class JScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


import java.io.*;
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		JScanner in = new JScanner();
		StringBuilder out = new StringBuilder();

		int t = in.nextInt();

		while(t-->0)
		{
			int n = in.nextInt();
			String s = in.nextLine();

			String a = "1";
			String b = "1";

			int i;
			boolean amin = false;
			for(i=1; i<n; i++)
			{
				if(s.charAt(i) == '1' && amin)
				{
					a += '0';
					b += '1';
				}
				else if(s.charAt(i) == '1')
				{
					a += '1';
					b += '0';
					amin = true;
				}
				else if(s.charAt(i) == '2' && amin)
				{
					a += '0';
					b += '2';
				}
				else if(s.charAt(i) == '2')
				{
					a += '1';
					b += '1';
				}
				else if(s.charAt(i) == '2' && amin)
				{
					a += '1';
					b += '1';
				}
				else
				{
					a += '0';
					b += '0';
				}
			}
			out.append(a).append("\n");
			out.append(b).append("\n");
		}
		System.out.println(out);

	}

	//Scanner
	static class JScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tc =sc.nextInt();
      for(int i=0;i<tc;i++){
          int x = sc.nextInt();
           long n  = sc.nextLong();
           int y =x-1;
        long[] arr  = new long[x];
           for(int u = 0 ;u<x;u++){
               long z  = n%10;
                n = n/10;
                arr[y-u]= z;
           }

           boolean flag = false;
           String a="1";
           String b="1";
           for(int l = 1 ;l <x;l++){
               if(arr[l]==2&&flag==false){
                   a = a.concat("1");
                   b= b.concat("1");
               }
               else if(arr[l]==2 && flag==true){
                   a=a.concat("0");
                   b=b.concat("2");
               }
               else if(arr[l]==0){
                   a= a.concat("0");
                   b=b.concat("0");
               }
              else  if(arr[l]==1 && flag==false){
                   a=a.concat("1");
                   b=b.concat("0");
                   flag=true;
               }
               else if(arr[l]==1 && flag==true){
                   a=a.concat("0");
                   b=b.concat("1");
               }

           }
          System.out.println(a);
          System.out.println(b);
      }
    }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int tc =sc.nextInt();
      for(int i=0;i<tc;i++){
          int x = sc.nextInt();
           int n  = sc.nextInt();
           int y =x-1;
        int[] arr  = new int[x];
           for(int u = 0 ;u<x;u++){
               int z  = n%10;
                n = n/10;
                arr[y-u]= z;
           }

           boolean flag = false;
           String a="1";
           String b="1";
           for(int l = 1 ;l <x;l++){
               if(arr[l]==2&&flag==false){
                   a = a.concat("1");
                   b= b.concat("1");
               }
               else if(arr[l]==2 && flag==true){
                   a=a.concat("0");
                   b=b.concat("0");
               }
               else if(arr[l]==0){
                   a= a.concat("0");
                   b=b.concat("0");
               }
              else  if(arr[l]==1 && flag==false){
                   a=a.concat("1");
                   b=b.concat("0");
                   flag=true;
               }
               else if(arr[l]==1 && flag==true){
                   a=a.concat("0");
                   b=b.concat("1");
               }

           }
          System.out.println(a);
          System.out.println(b);
      }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      //  Scanner sc= new Scanner(System.in);
        int tc =Integer.parseInt(br.readLine());
      for(int i=0;i<tc;i++){
          int x = Integer.parseInt(br.readLine());
          String n= br.readLine();
           int y =x-1;
            char[] arr  = new char[x];
           for(int u = 0 ;u<x;u++){
             arr[u]=  n.charAt(u);
           }

           boolean flag = false;
           char[]   a = new char[x];
           char[]b = new char[x];
          a[0]='1';
            b[0]='1';
           for(int l = 1 ;l <x;l++){
               if(arr[l]=='2'&&flag==false){
                   a[l] ='1';
                   b[l]= '1';
                   continue;
               }
               else if(arr[l]=='2' && flag==true){
                   a[l]='0';
                   b[l]='2';
                   continue;
               }
               else if(arr[l]=='0'){
                   a[l]='0';
                  b[l]='0';
                   continue;
               }
              else  if(arr[l]=='1' && flag==false){
                   a[l]='1';
                   b[l]='0';
                   flag=true;
                   continue;
               }
               else if(arr[l]=='1' && flag==true){
                   a[l]='0';
                   b[l]='1';
                   continue;
               }

           }
          System.out.println(new String(a));
          System.out.println(new String(b));
      }
    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      //  Scanner sc= new Scanner(System.in);
        int tc =Integer.parseInt(br.readLine());
      for(int i=0;i<tc;i++){
          int x = Integer.parseInt(br.readLine());
          String n= br.readLine();
           int y =x-1;
            int[] arr  = new int[x];
           for(int u = 0 ;u<x;u++){
     arr[u]=Integer.parseInt(n.substring(u,u+1));
           }

           boolean flag = false;
           String a="1";
           String b="1";
           for(int l = 1 ;l <x;l++){
               if(arr[l]==2&&flag==false){
                   a = a.concat("1");
                   b= b.concat("1");
                   continue;
               }
               else if(arr[l]==2 && flag==true){
                   a=a.concat("0");
                   b=b.concat("2");
                   continue;
               }
               else if(arr[l]==0){
                   a= a.concat("0");
                   b=b.concat("0");
                   continue;
               }
              else  if(arr[l]==1 && flag==false){
                   a=a.concat("1");
                   b=b.concat("0");
                   flag=true;
                   continue;
               }
               else if(arr[l]==1 && flag==true){
                   a=a.concat("0");
                   b=b.concat("1");
                   continue;
               }

           }
          System.out.println(a);
          System.out.println(b);
      }
    }
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class TernaryXOR {
	static int mod = 1000000007;
	static long L_INF = (1L << 60L);

	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[500005]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}

	public static void main(String[] args) throws IOException {
		Reader in = new Reader();
		int i, t, n, j, k;
		t = in.nextInt();
		StringBuilder ans = new StringBuilder();
		String s;
		char c;
		while (t-- > 0) {
			n = in.nextInt();
			in.readLine();
			s = in.readLine().substring(0, n);
			StringBuilder x = new StringBuilder();
			StringBuilder y = new StringBuilder();
			i = 0;
			x.append('1');
			y.append('1');
			int b = -1;

			for (i = 1; i < n; i++) {
				c = s.charAt(i);
				if (c == '0') {
					x.append('0');
					y.append('0');
				} else if (c == '1') {
					x.append('1');
					y.append('0');
					b = i + 1;
					break;
				} else {
					x.append('1');
					y.append('1');
				}
			}
			if (b != -1) {
				for (i = b; i < n; i++) {
					x.append('0');
					y.append(s.charAt(i));
				}
			}
			ans.append(x);
			ans.append('\n');
			ans.append(y);
			ans.append('\n');
		}
		System.out.println(ans);
	}
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.*;
public class Contest1 {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int t = sc.nextInt();
        while (t-->0){
            int n = sc.nextInt();
            char[] x= sc.nextLine().toCharArray();
            char[]a = new char[n];
            char[]b = new char[n];
            int id=-1;
            for (int i =0;i<n;i++){
                if (x[i]=='1'){
                    id=i;
                    break;
                }
            }
            if (id==-1){
                for (int i =0;i<n;i++){
                    if (x[i]=='2'){
                        a[i]='1';
                        b[i]='1';
                    }
                    else {
                        a[i]='0';
                        b[i]='0';
                    }
                }
            }
            else {
                for (int i =0;i<id;i++){
                    if (x[i]=='2'){
                        a[i]='1';
                        b[i]='1';
                    }
                    else {
                        a[i]='0';
                        b[i]='0';
                    }
                }
                a[id]='1';
                b[id]='0';
                for (int i =id+1;i<n;i++){
                    a[i]='0';
                    b[i]=x[i];
                }
            }
            pw.println(a);
            pw.println(b);
        }
        pw.flush();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            String x = next();
            StringBuilder sb = new StringBuilder("0");
            double res = 0, f = 1;
            boolean dec = false, neg = false;
            int start = 0;
            if (x.charAt(0) == '-') {
                neg = true;
                start++;
            }
            for (int i = start; i < x.length(); i++)
                if (x.charAt(i) == '.') {
                    res = Long.parseLong(sb.toString());
                    sb = new StringBuilder("0");
                    dec = true;
                } else {
                    sb.append(x.charAt(i));
                    if (dec)
                        f *= 10;
                }
            res += Long.parseLong(sb.toString()) / f;
            return res * (neg ? -1 : 1);
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }

}