#include<bits/stdc++.h>

using namespace std;

int swap(int *x,int *y)

{

int temp=*x;

*x=*y;

```
*y=temp;
```

}

int count1(int a[])

{

int count=0;

int p=a[0]+a[2];

p=p*10;

count=p+a[1]+a[3];

return count;

}

int solve(int a[])

{

int first=0,t,p;

```
for(int i=0;i<4;i++)
{
if(first<=a[i])
{
first=a[i];
t=i;
}
}
if(t==0 || t==2)
{ if(a[t+1]>a[(t+2)%4])
{
swap(&a[t+1],&a[(t+2)%4]);
}
p=count1(a);
}
else
{
swap(&a[t],&a[(t+1)%4]);
p=count1(a);
}
return p;
```

}

int main()

{

int t;

cin>>t;

while(t–)

{

int a,b;

cin>>a>>b;

```
int arr[4];
arr[1]=a%10;
a=a/10;
arr[0]=a%10;
arr[3]=b%10;
b=b/10;
arr[2]=b%10;
int k=solve(arr);
cout<<k<<"\n";
}
```

}