#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9+7;
ll qpow(ll a,ll k)
{
    ll ans=1;
    while(k)
    {
        if(k&1)
            ans=(ans*a)%mod;
        a=(a*a)%mod;
        k>>=1;
    }
    return ans;
}
struct node
{
    ll p;
    ll q;
    bool operator<(const node& b)const{
        return p<b.p;
    }
}a[100005];
int main()
{
    ll n;
    cin>>n;
    ll i,j=0,l;
    for(i=0;i<n;i++)
    {
        cin>>a[i].p>>a[i].q;
    }
    sort(a,a+n);
    for(i=1;i<n;i++)
    {
        if(a[i].q<a[i-1].q)
        {
            j=1;
            cout<<"Happy Alex"<<endl;
            break;
        }
    }
    if(j==0)
        cout<<"Poor Alex"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
//#pragma comment(linker, "/STACK:ll(1)024000000,ll(1)024000000") //手动加栈
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 1000050;
const int MAXM = MAXN*40;
const double pi = acos(-1.0);
const int mod = 1e9+7;
#define inf 0x3f3f3f3f3f3f3f
#define eps 10e-8
inline int read(){
	int x = 0, f = ll(1);
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-')
			f = -f;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
		x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}
//clock_t c1 = clock();
//std::cerr << "Time:" << clock() - c1 <<"ms" << std::endl;
// std::ios::sync_with_stdio(false)
//===============================================================//
struct node {
	int x,y;
}a[100005];
bool cmp(node x,node y){
	return x.x<y.x;
}
int main(){
    int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
	}
	sort(a+1,a+1+n,cmp);
	int flag=0;
	for (int i=2;i<=n;i++){
		 if (a[i].y<a[i-1].y&&a[i-1].x<a[i].x){
			flag=1;
			break;
		}
	}
	if (flag)printf("Happy Alex\n");
	else printf("Poor Alex\n");
    return 0;
}


#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
using namespace std;
const int maxn=1e5+5;
const int mod=1e9+7;
struct op{
    ll a,b;
}s[maxn];
ll cmp(op q,op w){
    return q.a<w.a;
}
int main() {
    ios;
    ll n,flag=0;
    cin>>n;
    for (int i = 1; i <= n; ++i) cin>>s[i].a>>s[i].b;
    sort(s+1,s+1+n,cmp);
    for (int i = 2; i <= n; ++i) {
        if(s[i].a>s[i-1].a&&s[i].b<s[i-1].b){
            flag=1;
            break;
        }
    }
    if(flag)
        cout<<"Happy Alex"<<endl;
    else
        cout<<"Poor Alex"<<endl;
    return 0;
}


#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc  exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\Input.txt","r",stdin);
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr strcat
#include <string>
#include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
#include <cassert>
#include <iomanip>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
//******************
clock_t __START,__END;
double __TOTALTIME;
void _MS(){__START=clock();}
void _ME(){__END=clock();__TOTALTIME=(double)(__END-__START)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;}
//***********************
#define rint register int
#define fo(a,b,c) for(rint a=b;a<=c;++a)
#define fr(a,b,c) for(rint a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db E=2.718281828;
const db PI=acos(-1.0);
const ll INF=(1LL<<60);
const int inf=(1<<30);
const db ESP=1e-9;
const int mod=(int)1e9+7;
const int N=(int)1e6+10;

int n;
int c[N];

int lowbit(int t)
{
	return t&(-t);
}
void add(int i,int t)//i处加t
{
	if(i==0)return;
	while(i<=n)
	{
		c[i]+=t;
		i+=lowbit(i);
	}
}
int sum(int i)//求i之前的前缀和
{
	int sum=0;
	while(i)
	{
		sum+=c[i];
		i-=lowbit(i);
	}
	return sum;
}

struct node
{
	int v,q;
	friend bool operator<(node a,node b)
	{
		return a.v>b.v;
	}
}a[N];

int main()
{
	sc("%d",&n);
	for(int i=1;i<=n;++i)
	{
		int v,q;
		sc("%d%d",&v,&q);
		a[i]={v,q};
	}
	sort(a+1,a+1+n);
	add(a[1].q,1);
	bool ok=0;
	for(int i=2;i<=n;++i)
	{
		int cnt=sum(a[i].q-1);
		if(a[i].v!=a[1].v&&cnt)ok=1;
		add(a[i].q,1);
	}
	if(ok)pr("Happy Alex\n");
	else pr("Poor Alex\n");
	return 0;
}

/**************************************************************************************/


#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;
struct N{
    int a,b;
}p[100005];

int cmp(N l1,N l2){
    return l1.a<l2.a;
}

int main(void){
    int n,flag=0;
	scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d",&p[i].a,&p[i].b);
    }
    sort(p,p+n,cmp);
    for(int i=1;i<n;i++){
        if(p[i].a>p[i-1].a&&p[i].b<p[i-1].b){
            flag=1;
            break;
        }
    }
	if(flag)
        printf("Happy Alex");
    else
        printf("Poor Alex");
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod = 1e9+7;
const int MOD = 1e4+7;
const int maxn = 10005;
const int MAXN = 100010;
int main()
{
    bool count=0;
    int m,a,b;
    cin>>m;
    for(int i=0; i<m; i++)
    {
        cin>>a>>b;
        if(a!=b)
        {
            count=1;
            break;
        }
    }
    if(count)
        puts("Happy Alex");
    else
        puts("Poor Alex");
    return 0;
}


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

struct computer{
	int a;
	int b;
};

int cmp(computer l1,computer l2)

{

    return l1.a<l2.a;

}

int main()
{
	int n,i;
	struct computer c[100010];
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d %d",&c[i].a,&c[i].b);
	}
	sort(c+1,c+1+n,cmp);
	int flag=0;
	for(i=1;i<=n;i++){
        if(c[i].b<c[i-1].b){
		flag=1;
		break;
		}
	}
	if(flag==1)
	cout<<"Happy Alex"<<endl;
    else
    cout<<"Poor Alex"<<endl;
    return 0;
}


#include<iostream>
using namespace std;
int n;
int a[100000],b[100000];

void quicksort(int low,int high) {
int i=low; int j=high; int t=a[(i+j)/2];
while (i<=j) {
    while (a[i]<t) ++i;
    while (a[j]>t) --j;
    if (i<=j) {
        swap(a[i],a[j]);
        swap(b[i],b[j]);
        ++i; --j;
    }
}
if (i<high) quicksort(i,high);
if (low<j) quicksort(low,j);
return;
}

int main() {
cin >> n;
for (int i=0;i<=n-1;++i) cin >>a[i]>>b[i];
quicksort(0,n-1);
for (int i=0;i<=n-2;++i)
    if (a[i]!=a[i+1] && b[i]>b[i+1]) {
        cout <<"Happy Alex";
        return 0;
    }
cout <<"Poor Alex";
return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#include<iostream>

using namespace std;

long long i, j, k, m, M, n, ans, s, co, f, len, T, r;
struct node
{
	long long x, y;
}a[100001];

int cmp(node a, node b)
{
	return a.x < b.x;
}

int main()
{
	scanf("%lld", &n);

	for (i = 1;i <= n;i++)
		scanf("%lld %lld", &a[i].x, &a[i].y);

	sort(a + 1, a + n + 1, cmp);

	for (i = 2;i <= n;i++)
		if (a[i].x > a[i - 1].x && a[i].y < a[i - 1].y)
		{
			f = 1;
			break;
		}

	if (f == 1)
		printf("Happy Alex");
	else
		printf("Poor Alex");

	return 0;
}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; cin>>n; int a[n],b[n],i;
	f(i,0,n) cin>>a[i]>>b[i];

	int c=0;
	f(i,0,n)
	if(a[i]<a[i+1] &&  b[i]>b[i+1] ) c++;

	if(c>0) cout<<"Happy Alex";
	else cout<<"Poor Alex";

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; cin>>n; int a[n],b[n],i;
	f(i,0,n) cin>>a[i]>>b[i];

	int c=0;
	f(i,0,n)
	if((a[i]<a[i+1] &&  b[i]>b[i+1]) || (a[i]>a[i+1] && b[i]<b[i+1]) ) c++;

	if(c>0) cout<<"Happy Alex";
	else cout<<"Poor Alex";

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; scanf("%d",&n); int a[n],b[n],i,j,k,o=0;

	for(i=0;i<n;i++)
	{
	scanf("%d %d",&a[i],&b[i]);
	if(a[i]!=b[i])
    {cout<<"Happy Alex"; return 0;}
   else cout<<"Poor Alex";
   return 0;
	}

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; cin>>n; int a[n],b[n],i,j;
	f(i,0,n) cin>>a[i]>>b[i];

	int c=0;
	f(i,0,n)
	f(j,0 && j!=i,n)
	if((a[i]<a[j] &&  b[i]>b[j]) || (a[i]>a[j] && b[i]<b[j]) ) c++;

	if(c>0) cout<<"Happy Alex";
	else cout<<"Poor Alex";

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; cin>>n; int a[n],b[n],i,j;
	f(i,0,n) cin>>a[i]>>b[i];

	int c=0;
	f(i,0,n)
	f(j,0 && j!=i,n)
	{
		if((a[i]<a[j] &&  b[i]>b[j]) || (a[i]>a[j] && b[i]<b[j]) ) c++;
		if(c>0) {cout<<"Happy Alex"; return 0;}
	}
	cout<<"Poor Alex";

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; cin>>n; int a[n],b[n],i,j,k,o=0;
	f(i,0,n) cin>>a[i]>>b[i];

	int c=0;
	f(i,0,n)
	f(j,i+1,n)
	{
		if((a[i]<a[j] &&  b[i]>b[j]) || (a[i]>a[j] && b[i]<b[j]) ) c++;
		if(c>0) {cout<<"Happy Alex"; return 0;}
	}
	cout<<"Poor Alex";

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; cin>>n; int a[n],b[n],i;
	f(i,0,n) cin>>a[i]>>b[i];

	int c=0;
	f(i,0,n)
	if(a[i]<a[i+1] &&  b[i]>b[i+1] || (a[i]>a[i+1] && b[i]<b[i+1]) ) c++;

	if(c>0) cout<<"Happy Alex";
	else cout<<"Poor Alex";

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; scanf("%d",&n); int a,b;

	for(i=0;i<n;i++)
	{
	scanf("%d %d",&a,&b);
	if(a<b)
    {cout<<"Happy Alex"; return 0;}
	}

 	 else cout<<"Poor Alex";
   return 0;

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; scanf("%d",&n); int a[n],b[n],i,j,k,o=0;

	for(i=0;i<n;i++)
	{
	scanf("%d %d",&a[i],&b[i]);
	if(a[i]!=b[i])
    cout<<"Happy Alex";
   else cout<<"Poor Alex";
	}

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; cin>>n; int a[n],b[n],i,j;
	f(i,0,n) cin>>a[i]>>b[i];

 int m=0,p=0;

	f(i,0,n)
	m = min(a[i],m) ,j=i;

	sort(b,b+n);
	f(i,0,n)
	if(b[j]>b[i]) p++;

	if(p>0)cout<<"Happy Alex";
	else cout<<"Poor Alex";

	/*int c=0;
	f(i,0,n)
	f(j,0 && j!=i,n)
	{
		if((a[i]<a[j] &&  b[i]>b[j]) || (a[i]>a[j] && b[i]<b[j]) ) c++;
		if(c>0) {cout<<"Happy Alex"; return 0;}
	}
	cout<<"Poor Alex";

 */

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; scanf("%d",&n); int a,b;

	for(int i=0;i<n;i++)
	{
	scanf("%d %d",&a,&b);
	if(a<b)
    {cout<<"Happy Alex"; return 0;}
	}

 	  cout<<"Poor Alex";
   return 0;

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; scanf("%d",&n); int a[n],b[n],i,j,k,o=0;
	for(i=0;i<n;i++)
	scanf("%d %d",&a[i],&b[i]);

	int c=0;
	for(i=0;i<n;i++)
	for(j=i+1;j<n;j++)
	{
		if((a[i]<a[j] &&  b[i]>b[j]) || (a[i]>a[j] && b[i]<b[j]) ) c++;
		if(c>0) {printf("Happy Alex"); return 0;}
	}
	printf("Poor Alex");

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; scanf("%d",&n); int a,b;

	for(i=0;i<n;i++)
	{
	scanf("%d %d",&a,&b);
	if(a<b)
    {cout<<"Happy Alex"; return 0;}
	}

 	  cout<<"Poor Alex";
   return 0;

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; cin>>n; int a[n],b[n],i,j,k,o=0;
	f(i,0,n) cin>>a[i]>>b[i];

 int m=0,p=0;

	f(i,0,n)
	{m = min(a[i],m), j=i;
	o = max(o,a[i]), k=i;}

	sort(b,b+n);
	f(i,0,n)
	{if(b[j]>b[i]) {p++; break;}
	if(b[k]<b[i]) {p++; break;}
	}

	if(p>0)cout<<"Happy Alex";
	else cout<<"Poor Alex";

	/*int c=0;
	f(i,0,n)
	f(j,0 && j!=i,n)
	{
		if((a[i]<a[j] &&  b[i]>b[j]) || (a[i]>a[j] && b[i]<b[j]) ) c++;
		if(c>0) {cout<<"Happy Alex"; return 0;}
	}
	cout<<"Poor Alex";

 */

}


#include<bits/stdc++.h>
#define  f(i,a,b) for( i=a;i<b;i++)

using namespace std;

int main()
{
	int n; scanf("%d",&n); int a[n],b[n],i,j,k,o=0;

	for(i=0;i<n;i++)
	{
	scanf("%d %d",&a[i],&b[i]);
	if(a[i]!=b[i])
    cout<<"Happy Alex";
   else cout<<"Poor Alex";
   return 0;
	}

}


#include<iostream>
using namespace std;

struct list{
  int a;
  int b;
};
int main(){
    int n;
    cin>>n;
    list *arr=new list[n];
    for(int i=0;i<n;i++){
    cin>>arr[i].a;
    cin>>arr[i].b;
    }
    for(int i=1;i<n;i++)
        {
        int e=arr[i].a;
        int f=arr[i].b;
        int flag=0;
        for(int j=i-1;j>=0;j--)
            {
            if(arr[j].a>e){
                arr[j+1].a=arr[j].a;
                arr[j+1].b=arr[j].b;
            }
            else
                {
                arr[j+1].a=e;
                arr[j+1].b=f;
                flag=1;
                break;
            }
        }
        if(flag==0){
          arr[0].a=e;
          arr[0].b=f;
    }
    int flag=0;
    for(int i=0;i<n-1;i++){
        if(arr[i].b>arr[i+1].b)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    cout<<"Happy Alex";
    else
    cout<<"Poor Alex";
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int m=2*n;
    int *arr=new int[m];
    for(int i=0;i<m;i++)
    cin>>arr[i];
    int count=0;
    for(int i=0;i<m-3;i+=2){
        for(int j=i+2;j<m-1;j+=2)
            if((arr[i]<arr[j]&&arr[i+1]>arr[j+1])||(arr[j]<arr[i]&&arr[j+1]>>arr[i+1]))
            count++;
    }
    if(count>=1)
    cout<<"Happy Alex";
    else
    cout<<"Poor Alex";
    return 0;
}


#include<iostream>
using namespace std;

struct list{
  long long int a;
  long long int b;
};
int main(){
    long long int n;
    cin>>n;
    list *arr=new list[n];
    for(long long int i=0;i<n;i++){
    cin>>arr[i].a;
    cin>>arr[i].b;
    }
    for(long long int i=1;i<n;i++)
        {
        long long int e=arr[i].a;
        long long int f=arr[i].b;
        long long int flag=0;
        for(long long int j=i-1;j>=0;j--)
            {
            if(arr[j].a>e){
                arr[j+1].a=arr[j].a;
                arr[j+1].b=arr[j].b;
            }
            else
                {
                arr[j+1].a=e;
                arr[j+1].b=f;
                flag=1;
                break;
            }
        }
        if(flag==0){
          arr[0].a=e;
          arr[0].b=f;
    }
        }
    long long int flag=0;
    for(long long int i=0;i<n-1;i++){
        if(arr[i].b>arr[i+1].b)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    cout<<"Happy Alex";
    else
    cout<<"Poor Alex";
    return 0;
}


#include<iostream>
using namespace std;

struct list{
  unsigned long long int a;
  unsigned long long int b;
};
int main(){
    unsigned long long int n;
    cin>>n;
    list *arr=new list[n];
    for(unsigned long long int i=0;i<n;i++){
    cin>>arr[i].a;
    cin>>arr[i].b;
    }
    for(unsigned long long int i=1;i<n;i++)
        {
        unsigned long long int e=arr[i].a;
        unsigned long long int f=arr[i].b;
        unsigned long long int flag=0;
        for(unsigned long long int j=i-1;j>=0;j--)
            {
            if(arr[j].a>e){
                arr[j+1].a=arr[j].a;
                arr[j+1].b=arr[j].b;
            }
            else
                {
                arr[j+1].a=e;
                arr[j+1].b=f;
                flag=1;
                break;
            }
        }
        if(flag==0){
          arr[0].a=e;
          arr[0].b=f;
    }
        }
    unsigned long long int flag=0;
    for(unsigned long long int i=0;i<n-1;i++){
        if(arr[i].b>arr[i+1].b)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    cout<<"Happy Alex";
    else
    cout<<"Poor Alex";
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int m=2*n;
    int *arr=new int[m];
    for(int i=0;i<m;i++)
    cin>>arr[i];
    for(int i=0;i<m-3;i+=2){
        for(int j=i+2;j<m-1;j+=2){
            if(arr[i]>arr[j]){
                int temp=arr[i];
                arr[i]=arr[j];
                arr[j]=temp;
                temp=arr[i+1];
                arr[i+1]=arr[j+1];
                arr[j+1]=temp;
            }
        }
    }
    int flag=0;
    for(int i=1;i<m-2;i+=2){
        if(arr[i]>arr[i+2])
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    cout<<"Happy Alex";
    else
    cout<<"Poor Alex";
    return 0;
}


#include<iostream>
using namespace std;

struct list{
  int a;
  int b;
};
int main(){
    int n;
    cin>>n;
    list *arr=new list[n];
    for(int i=0;i<n;i++){
    cin>>arr[i].a;
    cin>>arr[i].b;
    }
    for(int i=1;i<n;i++)
        {
        int e=arr[i].a;
        int f=arr[i].b;
        int flag=0;
        for(int j=i-1;j>=0;j--)
            {
            if(arr[j].a>e){
                arr[j+1].a=arr[j].a;
                arr[j+1].b=arr[j].b;
            }
            else
                {
                arr[j+1].a=e;
                arr[j+1].b=f;
                flag=1;
                break;
            }
        }
        if(flag==0){
          arr[0].a=e;
          arr[0].b=f;
    }
        }
    int flag=0;
    for(int i=0;i<n-1;i++){
        if(arr[i].b>arr[i+1].b)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    cout<<"Happy Alex";
    else
    cout<<"Poor Alex";
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int m=2*n;
    int *arr=new int[m];
    for(int i=0;i<m;i++)
    cin>>arr[i];
    for(int i=0;i<m-3;i+=2){
        for(int j=i+2;j<m-1;j+=2)
            if((arr[i]<arr[j]&&arr[i+1]>arr[j+1])||(arr[j]<arr[i]&&arr[j+1]>>arr[i+1]))
            count++;
    }
    if(count>=1)
    cout<<"Happy Alex";
    else
    cout<<"Poor Alex";
    return 0;
}


#include<iostream>
using namespace std;

struct list{
  int a;
  int b;
};
int main(){
    int n;
    cin>>n;
    list *arr=new list[n];
    for(int i=0;i<n;i++){
    cin>>arr[i].a;
    cin>>arr[i].b;
    }
    for(int i=1;i<n;i++)
        {
        int e=arr[i].a;
        int f=arr[i].b;
        int flag=0;
        for(int j=i-1;j>=0;j--)
            {
            if(arr[j].a>e){
                arr[j+1].a=arr[j].a;
                arr[j+1].b=arr[j].b;
            }
            else
                {
                arr[j+1].a=e;
                arr[j+1].b=f;
                flag=1;
                break;
            }
        }
        if(flag==0){
          arr[0].a=e;
          arr[0].b=f;
    }
    flag=0;
    for(int i=0;i<n-1;i++){
        if(arr[i].b>arr[i+1].b)
        {
            flag=1;
            break;
        }
    }
    if(flag==1)
    cout<<"Happy Alex";
    else
    cout<<"Poor Alex";
    return 0;
}


#include<iostream> #include<vector> #include<algorithm> #include <bits/stdc++.h> using namespace std; int main() { long long int n; cin>>n; vector<pair<long,long>>a(n); for(int i=0;i<n;++i) cin>>a[i].first>>a[i].second; sort(a.begin(),a.end()); for(int i=0;i<n;++i) { if(a[i].second>a[i+1].second && a[i].first<a[i+1].first) { cout<<"Happy Alex"; return 0; } } cout<< "Poor Alex" ; return 0; }


#include<iostream>
#include<vector>
#include<algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin>>n;
vector<pair<long,long> >a(n);
for(int i=0;i<n;++i)
    cin>>a[i].first>>a[i].second;
    sort(a.begin(),a.end());
    for(int i=0;i<n;++i) {
    if(a[i].second>a[i+1].second && a[i].first<a[i+1].first) {
    cout<<"Happy Alex"; return 0;
    }
    }
    cout<< "Poor Alex" ;
     return 0; }


#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int m=2*n;
    int *arr=new int[m];
    for(int i=0;i<m;i++)
    cin>>arr[i];
    for(int i=0;i<m-3;i+=2){
        for(int j=i+2;j<m-1;j+=2){
            if(arr[i]>arr[j]){
                int temp=arr[i];
                arr[i]=arr[j];
                arr[j]=temp;
                temp=arr[i+1];
                arr[i+1]=arr[j+1];
                arr[j+1]=temp;
            }
        }
    }
    int count=0;
    for(int i=1;i<m-2;i+=2){
        if(arr[i]>arr[i+2])
        count++;
    }
    if(count==n-1)
    cout<<"Happy Alex";
    else
    cout<<"Poor Alex";
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include<math.h>
#include <thread>
#include <chrono>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;

#define MohamedKamil  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define ull unsigned long long
typedef std::numeric_limits< double > dbl;

int main()
{
	ll n , a , b , price = 1000 , quality = -1 , flag = 0;
	cin >> n;
	vector <pair<ll, ll>> p;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (a < price)
			price = a;
		if (b > quality)
			quality = b;
		p.push_back(make_pair(a, b));
	}
	pair<ll,ll> ch = make_pair(price, quality);
	for (int i = 0; i < p.size(); i++)
	{
		if (ch == p[i])
			flag++;
	}
	if (flag > 0)
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor Alex" << "\n";

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include<math.h>
#include <thread>
#include <chrono>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;

#define MohamedKamil  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define ull unsigned long long

int main()
{
	MohamedKamil;
	map <int, int>m;
	int n, a, b, max_quality = -1 , min_price = 10000001;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		m[a] = b;
		if (min_price > a)
			min_price = a;

		if (max_quality < b)
			max_quality = b;
	}
	if (m[min_price] == max_quality)
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor Alex" << "\n";
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include<math.h>
#include <thread>
#include <chrono>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;

#define MohamedKamil  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define ull unsigned long long
typedef std::numeric_limits< double > dbl;

int main()
{
	int n , a , b , price = 1000 , quality = -1 , flag = 0;
	cin >> n;
	vector <pair<int, int>> p;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (a < price)
			price = a;
		if (b > quality)
			quality = b;
		p.push_back(make_pair(a, b));
	}
	pair<int,int> ch = make_pair(price, quality);
	for (int i = 0; i < p.size(); i++)
	{
		if (ch == p[i])
			flag++;
	}
	if (flag > 0)
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor Alex" << "\n";

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include<math.h>
#include <thread>
#include <chrono>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;

#define MohamedKamil  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define ull unsigned long long

int main()
{
	MohamedKamil;
	map <int, int>m;
	int n, a, b, max_quality = 0 , min_price = 100001;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		m[a] = b;
		if (min_price > a)
			min_price = a;

		if (max_quality < b)
			max_quality = b;
	}
	if (m[min_price] == max_quality)
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor Alex" << "\n";
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include<math.h>
#include <thread>
#include <chrono>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;

#define MohamedKamil  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define ull unsigned long long
typedef std::numeric_limits< double > dbl;

int main()
{
	ll n , a , b , price = 1000001 , quality = -1 , flag = 0;
	cin >> n;
	vector <pair<ll, ll>> p;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (a <= price)
			price = a;
		if (b >= quality)
			quality = b;
		p.push_back(make_pair(a, b));
	}
	pair<ll,ll> ch = make_pair(price, quality);
	sort(p.begin(), p.end());
	if (ch ==  p[0])
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor Alex" << "\n";

	return 0;
}


#include <iostream>
#include <string>
#include<algorithm>
#include<map>
#include <vector>
using namespace std;

int main()
{
	long long n, p, v, check = 0, len = 0;
	vector <pair<long long, long long >> vec;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> p >> v;
		vec.push_back(make_pair(p, v));
	}
	sort(vec.begin(), vec.end());
	vector <pair<long long, long long >>::iterator it, itnext = vec.begin();
	for (it = vec.begin(); it != vec.end(); ++it)
	{
		itnext++;
		if (itnext == vec.end())
			break;
		if (it->second > itnext->second)
		{
			cout << "Happy Alex" << "\n";
			len++;
			break;
		}
	}

	if (len == 0 )
		cout << "Poor  Alex" << "\n";

	/*if (check !=0)
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor  Alex" << "\n";*/

	return 0;

}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include<math.h>
#include <thread>
#include <chrono>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;

#define MohamedKamil  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define ull unsigned long long
typedef std::numeric_limits< double > dbl;

int main()
{
	ll n , a , b , price = 1000001 , quality = -1 , flag = 0;
	cin >> n;
	vector <pair<ll, ll>> p;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		p.push_back(make_pair(a, b));
	}
	sort(p.begin(), p.end());
	vector <pair<ll, ll>> ::iterator it, itnext = p.begin();
	itnext++;
	for (it = p.begin(); it != p.end(); ++it)
	{
		if (it->second > itnext->second)
		{
			flag++;
			break;
		}
		itnext++;
		if (itnext == p.end())
			break;
	}
	if (flag > 0)
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor Alex" << "\n";
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include<math.h>
#include <thread>
#include <chrono>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;

#define MohamedKamil  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define ull unsigned long long
typedef std::numeric_limits< double > dbl;

int main()
{
	ll n , a , b , price = 1000000 , quality = -1 , flag = 0;
	cin >> n;
	vector <pair<ll, ll>> p;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (a <= price)
			price = a;
		if (b >= quality)
			quality = b;
		p.push_back(make_pair(a, b));
	}
	pair<ll,ll> ch = make_pair(price, quality);
	for (int i = 0; i < p.size(); i++)
	{
		if (ch == p[i])
			flag++;
	}
	if (flag > 0)
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor Alex" << "\n";

	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include<math.h>
#include <thread>
#include <chrono>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;

#define MohamedKamil  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define ull unsigned long long

int main()
{
	MohamedKamil;
	int n, a, b; bool flag = true;
	set<pair<int,int>> s;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		s.insert(make_pair(a, b));
	}
	set<pair<int, int>>::iterator it, it_next = s.begin();
	it_next++;
	for (it = s.begin(); it != s.end(); ++it)
	{
		if (it_next == s.end())
			break;
		if (it_next->second < it->second)
		{
			flag = false;
			break;
		}
		it_next++;
	}
	if (!flag)
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor Alex" << "\n";
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include<math.h>
#include <thread>
#include <chrono>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;

#define MohamedKamil  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define ull unsigned long long

int main()
{
	MohamedKamil;
	map <int, int>m;
	int n, a, b, max_quality = -1 , min_price = 100001;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		m[a] = b;
		if (min_price > a)
			min_price = a;

		if (max_quality < b)
			max_quality = b;
	}
	if (m[min_price] == max_quality)
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor Alex" << "\n";
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include<math.h>
#include <thread>
#include <chrono>
#include <string>
#include <time.h>
#include <unordered_set>
using namespace std;

#define MohamedKamil  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ld long double
#define ull unsigned long long
typedef std::numeric_limits< double > dbl;

int main()
{
	ll n , a , b , price = 1000001 , quality = -1 , flag = 0;
	cin >> n;
	vector <pair<ll, ll>> p;
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (a <= price)
			price = a;
		if (b >= quality)
			quality = b;
		p.push_back(make_pair(a, b));
	}
	pair<ll,ll> ch = make_pair(price, quality);
	for (int i = 0; i < p.size(); i++)
	{
		if (ch == p[i])
			flag++;
	}
	if (flag > 0)
		cout << "Happy Alex" << "\n";
	else
		cout << "Poor Alex" << "\n";

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,c,a=0,b=0;
    cin>> c ;
    for( int i=0;i<c;i++ )
    {
     cin >> n >> m;
    }
 if(n!=m )
 {
     cout<<"Happy Alex";
     return 0;
 }

    {
        cout<<"Poor Alex";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c,a=0,b=0;
    cin>> c ;
    for( int i=0;i<c;i++ )
    {
        cin >> n >> m;

 if(n!=m)
 {
     cout<<"Happy Alex";
     return 0;
 }
    }

    {
        cout<<"Poor Alex";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c,a=0,b=0;
    cin>> c ;
     cin >> n >> m;
    for( int i=0;i<c;i++ )
    {

 if(n!=m || n==m)
 {
     cout<<"Happy Alex";
     return 0;
 }
    }

    {
        cout<<"Poor Alex";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c,a=0,b=0;
    cin>> c ;
     cin >> n >> m;
    for( int i=0;i<c;i++ )
    {

 if(n!=m)
 {
     cout<<"Happy Alex";
     return 0;
 }
    }

    {
        cout<<"Poor Alex";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,c;
    cin>> c >> n >> m;
    if(n>m)
    {
            cout<<"Poor Alex";
    }
    else
    {
cout<<"Happy Alex";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin >> n >> m;
    if(n>m)
    {
            cout<<"Poor Alex";
    }
    else
    {
cout<<"Happy Alex";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,n;
    cin>>n;
    for(int i=0; i<n;i++)
    {
        cin>>a>>b;
    }
        if(a==b)
        {
            cout<<"Happy Alex";
          return 0;

        }

            cout<<"Poor Alex";

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,a,b;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a>>b;
if(a!=b)
{
cout<<"Happy Alex";
return 0;
}
}
cout<<"Poor Alex";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
   long  long  int a,b,n;
    cin>>n;
    for(int i=0; i<n;i++)
    {
        cin>>a>>b;
    }
        if(a!=b)
        {

             cout<<"Happy Alex";
          return 0;
        }
    cout<<"Poor Alex";
    return 0;

}


#include <bits/stdc++.h>

using namespace std;

#define x  first
#define y  second
#define ll long long

const int maxn = 5005;

typedef pair<int, int> ii;

ii d[maxn];

int test;
char s[maxn], t[maxn];

void Solve()
{
        cin >> test;
        while( test -- )
        {
            cin >> (s + 1) >> (t + 1);
            int n = strlen(s + 1);
            int m = strlen(t + 1);

            d[n+1] = ii(50, 0);
            for(int i = n; i >= 1; -- i)
                d[i] = min(d[i+1], ii(s[i]-'A', i));

            int ok = 0;
            for(int i = 1; i <= min(m, n); ++ i)
            {
                if(s[i] < t[i]) break;
                if(s[i] > t[i]) {
                    if(i < n && d[i+1].x <= t[i]-'A')
                        swap(s[i], s[d[i+1].y]);
                    break;
                }
            }

            for(int i = 1; i <= min(m, n); ++ i)
                if(s[i] < t[i]) {ok = 1; break;}
                else if(s[i] > t[i]) {ok = 2; break;}

            if(ok == 1 || (!ok && n < m)) cout << (s+1) << endl;
            else cout << "---\n";
        }
}

//#define task "main"
int main()
{
        #ifdef task
            freopen(task".inp","r",stdin);
            freopen(task".out","w",stdout);
        #endif // task
            ios_base::sync_with_stdio(0);
            cin.tie(0);
            Solve();
}


#include <bits/stdc++.h>

using namespace std;

#define x  first
#define y  second
#define ll long long

const int maxn = 5005;

typedef pair<int, int> ii;

ii d[maxn];

int test;
char s[maxn], t[maxn];

void Solve()
{
        cin >> test;
        while( test -- )
        {
            cin >> (s + 1) >> (t + 1);
            int n = strlen(s + 1);
            int m = strlen(t + 1);

            d[n+1] = ii(50, 0);
            for(int i = n; i >= 1; -- i)
                d[i] = min(d[i+1], ii(s[i]-'A', i));

            int ok = 0;
            for(int i = 1; i <= min(m, n); ++ i)
            {
                if(s[i] < t[i]) {ok = 1; break;}
                if(i < n && d[i+1].x < t[i]-'A') {
                    ok = 1; swap(s[i], s[d[i+1].y]);
                    break;
                }
                if(s[i] > t[i]) break;
            }

            if(ok) cout << (s+1) << endl;
            else cout << "---\n";
        }
}

//#define task "main"
int main()
{
        #ifdef task
            freopen(task".inp","r",stdin);
            freopen(task".out","w",stdout);
        #endif // task
            ios_base::sync_with_stdio(0);
            cin.tie(0);
            Solve();
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;

                if (t > 100)
        cout << a << " " << c << "\n";

        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            int n = a.length();
            int m = c.length();
            unordered_set<int> freq[26];
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].insert(i);
            }

            bool done = false;
            for (int i = 0; i < n and i < m; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j <= c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        if (a < c) {
                            done = true;
                            break;
                        }
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                    }
                }
                if (done or a[i] > c[i])
                    break;
            }

                if (t <= 100) {
                    if (done) {
                    cout << a << "\n";
                } else {
                    cout << "---" << "\n";
                }
            }

        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;
        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            unordered_set<int> freq[26];
            for (int i = 0; i < a.length(); i++) {
                freq[a[i]-'A'].insert(i);
            }
            bool done = false;
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j <= c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        if (a < c) {
                            done = true;
                            break;
                        } else
                            swap(a[i], a[*(freq[j-'A'].begin())]);
                    }
                }
                if (done or a[i] > c[i])
                    break;
            }
            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }
        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;
        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            vector<bool> small(n, false);
            for (int i = 0; i < n and i < c.length(); i++) {
                if (a.substr(0, i+1) <= c.substr(0, i+1))
                    small[i] = true;
            }

            bool done = false;
            for (int i = 0; i < n and i < (int)c.length(); i++) {
                for (int j = i + 1; j < n and j < (int)c.length(); j++) {
                    if (a[i] > a[j]) {
                        swap(a[i], a[j]);
                        if (i == 0 and a[i] < c[i]) {
                            done = true;
                            break;
                        } else if (i != 0 and small[i-1] and a[i] < c[i]) {
                            done = true;
                            break;
                        } else if (i != 0 and small[i-1] and a[i] == c[i] and i + 1 == n and i + 1 < (int)c.length()) {
                            done = true;
                            break;
                        }
                        swap(a[i], a[j]);
                    }
                }
                if (done)
                    break;
            }

            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }
        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;

                if (t > 100 and tt == 255)
        cout << a << " " << c << "\n";

        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            int n = a.length();
            int m = c.length();
            unordered_set<int> freq[26];
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].insert(i);
            }

            bool done = false;
            for (int i = 0; i < n and i < m; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j <= c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        if (a < c) {
                            done = true;
                            break;
                        }
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                    }
                }
                if (done or a[i] > c[i])
                    break;
            }

                if (t <= 100) {
                    if (done) {
                    cout << a << "\n";
                } else {
                    cout << "---" << "\n";
                }
            }

        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;

        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            int n = a.length();
            int m = c.length();
            unordered_set<int> freq[26];
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].insert(i);
            }

            bool done = false;
            for (int i = 0; i < n and i < m; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j <= c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        for (auto x : freq[j-'A']) {
                            swap(a[i], a[x]);
                            if (a < c) {
                                done = true;
                                break;
                            }
                            swap(a[i], a[x]);
                        }
                    }
                    if (done)
                        break;
                }
                if (done or a[i] > c[i])
                    break;
            }

            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }

        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;
        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            unordered_set<int> freq[26];
            for (int i = 0; i < a.length(); i++) {
                freq[a[i]-'A'].insert(i);
            }
            bool done = false;
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j < c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        done = true;
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        break;
                    }
                }
                if (done or a[i] > c[i])
                    break;
            }
            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }
        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;

        if (t > 100 and tt == 255)
            cout << a << " " << c << "\n";

        int n = a.length();
        if (a < c) {
            //cout << a << "\n";
        } else {
            int n = a.length();
            int m = c.length();
            unordered_set<int> freq[26];
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].insert(i);
            }

            bool done = false;
            for (int i = 0; i < n and i < m; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j <= c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        if (a < c) {
                            done = true;
                            break;
                        }
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                    }
                }
                if (done or a[i] > c[i])
                    break;
            }

                if (t <= 100) {
                    if (done) {
                    cout << a << "\n";
                } else {
                    cout << "---" << "\n";
                }
            }

        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;
        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            bool done = false;
            for (int i = 0; i < n; i++) {
                for (int j = i + 1; j < n; j++) {
                    swap(a[i], a[j]);
                    if (a < c) {
                        done = true;
                        break;
                    }
                    swap(a[i], a[j]);
                }
                if (done)
                    break;
            }
            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }
        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;

        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            int n = a.length();
            int m = c.length();
            set<int> freq[26];
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].insert(i);
            }

            bool done = false;
            for (int i = 0; i < n and i < m; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j <= c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        int x = *(freq[j-'A'].rbegin());
                        swap(a[i], a[x]);
                        if (a < c) {
                            done = true;
                            break;
                        }
                        swap(a[i], a[x]);
                    }
                }
                if (done or a[i] > c[i])
                    break;
            }

            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }

        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;
        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            unordered_set<int> freq[26];
            for (int i = 0; i < a.length(); i++) {
                freq[a[i]-'A'].insert(i);
            }
            bool done = false;
            for (int i = 0; i < n; i++) {
                for (int j = 'A'; j < c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        done = true;
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        break;
                    }
                }
                freq[a[i]-'A'].erase(i);
                if (done or a[i] > c[i])
                    break;
            }
            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }
        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;
        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            int n = a.length();
            int m = c.length();
            unordered_set<int> freq[26];
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].insert(i);
            }

            bool done = false;
            for (int i = 0; i < n and i < m; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j <= c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        if (a < c) {
                            done = true;
                            break;
                        }
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                    }
                }
                if (done)
                    break;
            }

            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }
        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;

        if (t > 100 and tt == 255)
            cout << a << " " << c << "\n";

        int n = a.length();
        if (a < c) {
            if (t <= 100)
                cout << a << "\n";
        } else {
            int n = a.length();
            int m = c.length();
            unordered_set<int> freq[26];
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].insert(i);
            }

            bool done = false;
            for (int i = 0; i < n and i < m; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j <= c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        if (a < c) {
                            done = true;
                            break;
                        }
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                    }
                }
                if (done or a[i] > c[i])
                    break;
            }

                if (t <= 100) {
                    if (done) {
                    cout << a << "\n";
                } else {
                    cout << "---" << "\n";
                }
            }

        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;

                if (tt == 255)
        cout << a << " " << c << "\n";

        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            int n = a.length();
            int m = c.length();
            unordered_set<int> freq[26];
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].insert(i);
            }

            bool done = false;
            for (int i = 0; i < n and i < m; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j <= c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        if (a < c) {
                            done = true;
                            break;
                        }
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                    }
                }
                if (done or a[i] > c[i])
                    break;
            }

            /*if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }*/
        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;
        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            vector<bool> small(n, false);
            for (int i = 0; i < n and i < c.length(); i++) {
                if (a.substr(0, i+1) <= c.substr(0, i+1))
                    small[i] = true;
            }

            bool done = false;
            for (int i = 0; i < n and i < (int)c.length(); i++) {
                for (int j = i + 1; j < n and j < (int)c.length(); j++) {
                    if (a[i] > a[j]) {
                        swap(a[i], a[j]);
                        if (i == 0 and a[i] < c[i]) {
                            done = true;
                            break;
                        } else if (i != 0 and small[i-1] and a[i] < c[i]) {
                            done = true;
                            break;
                        } else if (i != 0 and small[i-1] and a[i] == c[i] and i + 1 == n) {
                            done = true;
                            break;
                        }
                        swap(a[i], a[j]);
                    }
                }
                if (done)
                    break;
            }

            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }
        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;

                if (tt == 255)
        cout << a << " " << c << "\n";

        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            int n = a.length();
            int m = c.length();
            unordered_set<int> freq[26];
            for (int i = 0; i < n; i++) {
                freq[a[i]-'A'].insert(i);
            }

            bool done = false;
            for (int i = 0; i < n and i < m; i++) {
                freq[a[i]-'A'].erase(i);
                for (int j = 'A'; j <= c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        if (a < c) {
                            done = true;
                            break;
                        }
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                    }
                }
                if (done or a[i] > c[i])
                    break;
            }

            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }
        }
    }
}


#include <bits/stdc++.h>

#define testcase(t) for (int tt = 1; tt <= t; tt++)

typedef long long int ll;

using namespace std;

int main() {
    int t;
    cin >> t;
    testcase(t) {
        string a, c;
        cin >> a >> c;
        int n = a.length();
        if (a < c) {
            cout << a << "\n";
        } else {
            unordered_set<int> freq[26];
            for (int i = 0; i < a.length(); i++) {
                freq[a[i]-'A'].insert(i);
            }
            bool done = false;
            for (int i = 0; i < n; i++) {
                for (int j = 'A'; j < c[i]; j++) {
                    if (freq[j-'A'].size() > 0) {
                        done = true;
                        swap(a[i], a[*(freq[j-'A'].begin())]);
                        break;
                    }
                }
                if (done or a[i] > c[i])
                    break;
            }
            if (done) {
                cout << a << "\n";
            } else {
                cout << "---" << "\n";
            }
        }
    }
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	for(long t=0;t<test;t++){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		   if(str1[i]==str2[i]){
	  		   	int flag=0,index;
	  			char temp='a',prevtemp='z';
	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  		   }
	  			}
	  		   if(flag==1){

	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			break;
	  			}

	  			}
	  		    else{
	  			int flag=0,index;
	  			char temp='a',prevtemp='z';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}

	  			if(flag==1){

	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			}

	  			break;

	  		    }
	  	}
	  }

	  	    int cnt=0,cnte=0;
	  	    for(int i=0;i<min;i++){
	  	        if(str2[i]<str1[i]){
	  	        cnt++;
	  	        break;
	  	        }
	  	        if(str2[i]==str1[i])
	  	        cnte++;
	  	        if(str2[i]>str1[i]){

	  	            break;

	  	            }

	  	    }
	  	    int z=min;
	  	    if(t==40){
	  	    	cout<<str1<<" "<<str2<<endl;
	  	    }
	  	    else{
	  	    if(cnt>0)
	  	    cout<<"---"<<endl;
	  	    else if((cnte==min)&&(str2.size()==min))
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;
	}

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	for(long t=0;t<test;t++){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
	   if(t==40){
	  	    	cout<<str1<<" "<<str2<<" ";
	  	    }
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		   if(str1[i]==str2[i]){
	  		   	int flag=0,index;
	  			char temp='a',prevtemp='z';
	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  		   }
	  			}
	  		   if(flag==1){

	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			break;
	  			}

	  			}
	  		    else{
	  			int flag=0,index;
	  			char temp='a',prevtemp='z';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}

	  			if(flag==1){

	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			}

	  			break;

	  		    }
	  	}
	  }

	  	    int cnt=0,cnte=0;
	  	    for(int i=0;i<min;i++){
	  	        if(str2[i]<str1[i]){
	  	        cnt++;
	  	        break;
	  	        }
	  	        if(str2[i]==str1[i])
	  	        cnte++;
	  	        if(str2[i]>str1[i]){

	  	            break;

	  	            }

	  	    }
	  	    int z=min;

	  	    if(cnt>0)
	  	    cout<<"---"<<endl;
	  	    else if((cnte==min)&&(str2.size()==min))
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
		long uflag=0;
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		if(str1[i]==str2[i]){
	  		continue;
	  		}
	  		else{
	  			int flag=0,index;
	  			char temp='a',prevtemp='z';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}

	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;

	  			break;

	  		}
	  	}
	  }

	  	    int cnt=0,cnte=0;
	  	    for(int i=0;i<min;i++){
	  	        if(str2[i]<str1[i])
	  	        cnt++;
	  	        if(str2[i]==str1[i])
	  	        cnte++;
	  	        if(str2[i]>str1[i]){

	  	            break;

	  	            }

	  	    }
	  	    int z=min;
	  	    if(cnt>0)
	  	    cout<<"---"<<endl;
	  	    else if((cnte==min)&&(str2.size()<=min))
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		if(str1[i]==str2[i]){
	  		continue;
	  		}
	  		else{
	  			int flag=0,index;
	  			char temp='a',prevtemp='z';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}

	  			if(flag==1){
	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			}

	  			break;

	  		}
	  	}
	  }

	  	    int cnt=0,cnte=0;
	  	    for(int i=0;i<min;i++){
	  	        if(str2[i]<str1[i]){
	  	        cnt++;
	  	        break;
	  	        }
	  	        if(str2[i]==str1[i])
	  	        cnte++;
	  	        if(str2[i]>str1[i]){

	  	            break;

	  	            }

	  	    }
	  	    int z=min;
	  	    if(cnt>0)
	  	    cout<<"---"<<endl;
	  	    else if((cnte==min)&&(str2.size()==min))
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
		long uflag=0;
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		if(str1[i]==str2[i]){
	  		continue;
	  		}
	  		else{
	  			int flag=0,index;
	  			char temp='z',prevtemp='@';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp>prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}
	  			if(flag==0){

	  			uflag=1;
	  			break;
	  			}
	  			else{
	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			if(str1[i]<str2[i])
	  			break;
	  			}

	  		}
	  	}
	  }
	  if(uflag==0){
	      if(str2.size()>str1.size())
	  	cout<<str1<<endl;
	  	else{
	  	    int cnt=0;
	  	    for(int i=0;i<str2.size();i++){
	  	        if(str2[i]==str1[i])
	  	        cnt++;
	  	    }
	  	    if(cnt==str2.size())
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;
	  	}
	  }
	  else
	  cout<<"---"<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
		long uflag=0;
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		if(str1[i]==str2[i]){
	  		continue;
	  		}
	  		else{
	  			int flag=0,index;
	  			char temp='z',prevtemp='@';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp>prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}
	  			if(flag==0){

	  			uflag=1;
	  			break;
	  			}
	  			else{
	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			}

	  		}
	  	}
	  }
	  if(uflag==0){
	      if(str2.size()>=str1.size())
	  	cout<<str1<<endl;
	  	else{
	  	    int cnt=0;
	  	    for(int i=0;i<str2.size();i++){
	  	        if(str2[i]==str1[i])
	  	        cnt++;
	  	    }
	  	    if(cnt==str2.size())
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;
	  	}
	  }
	  else
	  cout<<"---"<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
		long uflag=0;
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		if(str1[i]==str2[i]){
	  		continue;
	  		}
	  		else{
	  			int flag=0,index;
	  			char temp='a',prevtemp='z';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}
	  			if(flag==0){

	  			uflag=1;
	  			break;
	  			}
	  			else{
	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;

	  			break;
	  			}

	  		}
	  	}
	  }
	  if(uflag==0){

	  	    int cnt=0,cnte=0;
	  	    for(int i=0;i<min;i++){
	  	        if(str2[i]<str1[i])
	  	        cnt++;
	  	        if(str2[i]==str1[i])
	  	        cnte++;
	  	        if(str2[i]>str1[i]){

	  	            break;

	  	            }

	  	    }
	  	    int z=min;
	  	    if(cnt>0)
	  	    cout<<"---"<<endl;
	  	    else if((cnte==min)&&(str2.size()<=min))
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;

	  }
	  else
	  cout<<"---"<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
		long uflag=0;
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		if(str1[i]==str2[i]){
	  		continue;
	  		}
	  		else{
	  			int flag=0,index;
	  			char temp='z',prevtemp='@';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp>prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}
	  			if(flag==0){

	  			uflag=1;
	  			break;
	  			}
	  			else{
	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			}

	  		}
	  	}
	  }
	  if(uflag==0){
	      if(str2.size()>str1.size())
	  	cout<<str1<<endl;
	  	else{
	  	    int cnt=0;
	  	    for(int i=0;i<str2.size();i++){
	  	        if(str2[i]==str1[i])
	  	        cnt++;
	  	    }
	  	    if(cnt==str2.size())
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;
	  	}
	  }
	  else
	  cout<<"---"<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
		long uflag=0;
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		if(str1[i]==str2[i]){
	  		continue;
	  		}
	  		else{
	  			int flag=0,index;
	  			char temp='a',prevtemp='z';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}
	  			if(flag==0){

	  			uflag=1;
	  			break;
	  			}
	  			else{
	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;

	  			break;
	  			}

	  		}
	  	}
	  }
	  if(uflag==0){

	  	    int cnt=0,cnte=0;
	  	    for(int i=0;i<min;i++){
	  	        if(str2[i]<str1[i])
	  	        cnt++;
	  	        if(str2[i]==str1[i])
	  	        cnte++;
	  	        if(str2[i]>str1[i]){

	  	            break;

	  	            }

	  	    }
	  	    int z=str2.size();
	  	    if(cnt>0||cnte==z)
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;

	  }
	  else
	  cout<<"---"<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
		long uflag=0;
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		if(str1[i]==str2[i]){
	  		continue;
	  		}
	  		else{
	  			int flag=0,index;
	  			char temp='z',prevtemp='@';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp>prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}
	  			if(flag==0){

	  			uflag=1;
	  			break;
	  			}
	  			else{
	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;

	  			break;
	  			}

	  		}
	  	}
	  }
	  if(uflag==0){

	  	    int cnt=0,cnte=0;
	  	    for(int i=0;i<str2.size();i++){
	  	        if(str2[i]<str1[i])
	  	        cnt++;
	  	        if(str2[i]==str1[i])
	  	        cnte++;
	  	        if(str2[i]>str1[i]){

	  	            break;

	  	            }

	  	    }
	  	    int z=str2.size();
	  	    if(cnt>0||cnte==z)
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;

	  }
	  else
	  cout<<"---"<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
		long uflag=0;
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		if(str1[i]==str2[i]){
	  		continue;
	  		}
	  		else{
	  			int flag=0,index;
	  			char temp='a',prevtemp='z';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}

	  			if(flag==1){
	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			}

	  			break;

	  		}
	  	}
	  }

	  	    int cnt=0,cnte=0;
	  	    for(int i=0;i<min;i++){
	  	        if(str2[i]<str1[i])
	  	        cnt++;
	  	        if(str2[i]==str1[i])
	  	        cnte++;
	  	        if(str2[i]>str1[i]){

	  	            break;

	  	            }

	  	    }
	  	    int z=min;
	  	    if(cnt>0)
	  	    cout<<"---"<<endl;
	  	    else if((cnte==min)&&(str2.size()==min))
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	for(long t=0;t<test;t++){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();

	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		   if(str1[i]==str2[i]){
	  		   	int flag=0,index;
	  			char temp='a',prevtemp='z';
	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  		   }
	  			}
	  		   if(flag==1){

	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			break;
	  			}

	  			}
	  		    else{
	  			int flag=0,index;
	  			char temp='a',prevtemp='z';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }
	  				    if(temp==prevtemp)
	  				    index=j;

	  				}

	  			}

	  			if(flag==1){

	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			}

	  			break;

	  		    }
	  	}
	  }

	  	    int cnt=0,cnte=0;
	  	    for(int i=0;i<min;i++){
	  	        if(str2[i]<str1[i]){
	  	        cnt++;
	  	        break;
	  	        }
	  	        if(str2[i]==str1[i])
	  	        cnte++;
	  	        if(str2[i]>str1[i]){

	  	            break;

	  	            }

	  	    }
	  	    int z=min;

	  	    if(cnt>0)
	  	    cout<<"---"<<endl;
	  	    else if((cnte==min)&&(str2.size()==min))
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		   if(str1[i]==str2[i]){
	  		   	int flag=0,index;
	  			char temp='a',prevtemp='z';
	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  		   }
	  			}
	  		   if(flag==1){

	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			break;
	  			}

	  			}
	  		    else{
	  			int flag=0,index;
	  			char temp='a',prevtemp='z';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp<prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}

	  			if(flag==1){

	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			}

	  			break;

	  		    }
	  	}
	  }

	  	    int cnt=0,cnte=0;
	  	    for(int i=0;i<min;i++){
	  	        if(str2[i]<str1[i]){
	  	        cnt++;
	  	        break;
	  	        }
	  	        if(str2[i]==str1[i])
	  	        cnte++;
	  	        if(str2[i]>str1[i]){

	  	            break;

	  	            }

	  	    }
	  	    int z=min;
	  	    if(cnt>0)
	  	    cout<<"---"<<endl;
	  	    else if((cnte==min)&&(str2.size()==min))
	  	    cout<<"---"<<endl;
	  	    else
	  	    cout<<str1<<endl;

	}

	// your code goes here
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	long test;
	cin>>test;
	while(test--){
		string str1,str2;
		cin>>str1>>str2;
	   int	min=str1.size();
	   if(str2.size()<str1.size())
	   min=str2.size();
		long uflag=0;
	  for(int i=0;i<min;i++){
	  	if(str1[i]<str2[i]){
	  	break;

	  	}
	  	else{
	  		if(str1[i]==str2[i]){
	  		continue;
	  		}
	  		else{
	  			int flag=0,index;
	  			char temp='z',prevtemp='@';

	  			for(int j=i+1;j<str1.size();j++){
	  				if(str1[j]<=str2[i]){

	  				    temp=str1[j];
	  				    flag=1;
	  				    if(temp>prevtemp){
	  				        prevtemp=temp;

	  				    index=j;

	  				    }

	  				}

	  			}
	  			if(flag==0){

	  			uflag=1;
	  			break;
	  			}
	  			else{
	  			str1[index]=str1[i];
	  			str1[i]=prevtemp;
	  			}

	  		}
	  	}
	  }
	  if(uflag==0){
	      if(str2.size()>=str1.size())
	  	cout<<str1<<endl;
	  	else{
	  	    int cnt=0;
	  	    for(int i=0;i<str2.size();i++){
	  	        if(str2[i]==str1[i])
	  	        cnt++;
	  	    }
	  	    if(cnt==str2.size())
	  	    cout<<"..."<<endl;
	  	    else
	  	    cout<<str1<<endl;
	  	}
	  }
	  else
	  cout<<"..."<<endl;

	}

	// your code goes here
	return 0;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int pos = inf;
    	for (int k = 0; k < min(a.size(), b.size()); k++) {
    		if (a[k] == b[k])
    			continue;
        	if (a[k] != b[k]) {
        	 	pos = k;
        	 	break;
        	}
        }
        if (pos == inf && a.size() < b.size()) {
        	cout << a << endl;
        	continue;
        }
        for (int k = pos; k < a.size(); k++) {
        	if (a[k] < b[pos]) {
        		swap(a[k], a[pos]);
        		cout << a << endl;
        		goto here;
        	}
        }
        for (int k = pos; k < a.size(); k++) {
         	if (a[k] == b[pos]) {
         		string h = a;
         		swap(h[k], h[pos]);
         		if (h < b) {
         			cout << h << endl;
         			goto here;
         		}
         	}
        }
        cout << "---\n";
        here:;
    }

    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int pos = inf;
    	for (int k = 0; k < min(a.size(), b.size()); k++) {
    		if (a[k] == b[k])
    			continue;
        	if (a[k] != b[k]) {
        	 	pos = k;
        	 	break;
        	}
        }
        if (pos == inf && a.size() != b.size()) {
        	cout << a << endl;
        	continue;
        }
        for (int k = pos; k < a.size(); k++) {
        	if (a[k] < b[pos]) {
        		swap(a[k], a[pos]);
        		cout << a << endl;
        		goto here;
        	}
        }
        for (int k = pos; k < a.size(); k++) {
         	if (a[k] == b[pos]) {
         		string h = a;
         		swap(h[k], h[pos]);
         		if (h < b) {
         			cout << h << endl;
         			goto here;
         		}
         	}
        }
        cout << "---\n";
        here:;
    }

    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	if (a < b) {
    		cout << a << "\n";
    		continue;
    	}
    	if (b.size() > a.size()) {
        	string k = "";
        	for (int j = 0; j < a.size(); j++)
        		k += b[j];
       		b = k;
    	}
    	int pos = 0;
    	while (pos < min(a.size(), b.size())) {
    		int k = pos;
    		char mn = a[pos];
    	    for (int j = pos + 1; j < a.size(); j++) {
    	    	if (a[j] <= mn) {
                	mn = a[j];
                	k = j;
                }
    	    }
    	    if (a[k] < a[pos]) {
    	    	string p = a;
    	     	swap(p[k], p[pos]);
    	     	if (p < b) {
    	     		cout << p << "\n";
    	     		goto here;
    	     	}
    	    }
    		pos++;
    	}
    	cout << "---\n";
    	here:;
    }

    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int pos = inf;
    	for (int k = 0; k < min(a.size(), b.size()); k++) {
    		if (a[k] == b[k])
    			continue;
        	if (a[k] != b[k]) {
        	 	pos = k;
        	 	break;
        	}
        }
        if (pos == inf) {
        	cout << a << endl;
        	continue;
        }
        for (int k = pos; k < a.size(); k++) {
        	if (a[k] < b[pos]) {
        		swap(a[k], a[pos]);
        		cout << a << endl;
        		goto here;
        	}
        }
        for (int k = pos; k < a.size(); k++) {
         	if (a[k] == b[pos]) {
         		string h = a;
         		swap(h[k], h[pos]);
         		if (h < b) {
         			cout << h << endl;
         			goto here;
         		}
         	}
        }
        cout << "---\n";
        here:;
    }

    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int k = 0;
    	while (k < a.size()) {
    		int pos = 0;
    		char mn = 'Z';
    		for (int j = k; j < a.size(); j++) {
    	 		if (mn >= a[j]) {
    	 	  		mn = a[j];
    	 	  		pos = j;
    	 		}
    		}
    		if (pos != k) {
    			string p = a;
    		 	swap(p[pos], p[k]);
    		 	if (p <= b) {
    		 	 	cout << p << endl;
    		 	 	goto here;
    		 	}
    		}
    		k++;
    	}
    	cout << "---" << endl;
    	here:;
    }
    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int pos = inf;
    	for (int k = 0; k < min(a.size(), b.size()); k++) {
    		if (a[k] == b[k])
    			continue;
    		if (a[k] < b[k]) {
    			cout << a << endl;
    			goto here;
    		}
        	if (a[k] != b[k]) {
        	 	pos = k;
        	 	break;
        	}
        }
        if (pos == inf && a.size() < b.size()) {
        	cout << a << endl;
        	continue;
        }
        if (a < b) {
        	cout << a << endl;
        	continue;
        }
        for (int k = pos + 1; k < a.size(); k++) {
        	if (a[k] < b[pos]) {
        		swap(a[k], a[pos]);
        		cout << a << endl;
        		goto here;
        	}
        }
        for (int k = pos + 1; k < a.size(); k++) {
         	if (a[k] == b[pos]) {
         		string h = a;
         		swap(h[k], h[pos]);
         		if (h < b) {
         			cout << h << endl;
         			goto here;
         		}
         	}
        }
        cout << "---\n";
        here:;
    }

    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	if (a < b) {
    		cout << a << endl;
    		continue;
    	}

    	for (int j = 0; j < a.size(); j++)
    		for (int k = j + 1; k < a.size(); k++) {
    			if (a[k] >= a[j])
    				continue;
    			swap(a[j], a[k]);
    			if (a < b) {
    				cout << a << endl;
    				goto p;
    			}
    			swap(a[j], a[k]);
    		}
    	cout << "---\n";
   		p:;
    }

    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int k = 0;
    	if (b.size() > a.size()) {
    		string h = "";
    	 	for (int j = 0; j < a.size(); j++)
    	 		h  += b[j];
    	 	b = h;
    	}
    	if (a < b) {
    	 	cout << a << endl;
    	 	goto here;
    	}
    	while (k < a.size()) {
    		int pos = 0;
    		char mn = 'Z';
    		for (int j = k; j < a.size(); j++) {
    	 		if (mn >= a[j]) {
    	 	  		mn = a[j];
    	 	  		pos = j;
    	 		}
    		}
    		if (pos != k) {
    			string p = a;
    		 	swap(p[pos], p[k]);
    		 	if (p < b) {
    		 	 	cout << p << endl;
    		 	 	goto here;
    		 	}
    		}
    		k++;
    	}
    	cout << "---" << endl;
    	here:;
    }
    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int pos = a.size();
    	for (int k = 0; k < min(a.size(), b.size()); k++) {
    		if (a[k] == b[k])
    			continue;
        	if (a[k] != b[k]) {
        	 	pos = k;
        	 	break;
        	}
        }
        if (pos == a.size()) {
        	cout << a << endl;
        	continue;
        }
        for (int k = pos; k < a.size(); k++) {
        	if (a[k] < b[pos]) {
        		swap(a[k], a[pos]);
        		cout << a << endl;
        		goto here;
        	}
        }
        for (int k = pos; k < a.size(); k++) {
         	if (a[k] == b[pos]) {
         		string h = a;
         		swap(h[k], h[pos]);
         		if (h < b) {
         			cout << a << endl;
         			goto here;
         		}
         	}
        }
        cout << "---\n";
        here:;
    }

    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int k = 0;
    	if (a < b) {
    	 	cout << a << endl;
    	 	goto here;
    	}
    	if (b.size() > a.size()) {
    		string h = "";
    	 	for (int j = 0; j < a.size(); j++)
    	 		h  += b[j];
    	 	b = h;
    	}
    	while (k < a.size()) {
    		int pos = 0;
    		char mn = 'Z' + 1;
    		for (int j = k; j < a.size(); j++) {
    	 		if (mn >= a[j]) {
    	 	  		mn = a[j];
    	 	  		pos = j;
    	 		}
    		}
    		if (pos != k) {
    			string p = a;
    		 	swap(p[pos], p[k]);
    		 	if (p < b) {
    		 	 	cout << p << endl;
    		 	 	goto here;
    		 	}
    		}
    		k++;
    	}
    	cout << "---" << endl;
    	here:;
    }
    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int pos = a.size();
    	for (int k = 0; k < min(a.size(), b.size()); k++) {
    		if (a[k] == b[k])
    			continue;
        	if (a[k] != b[k]) {
        	 	pos = k;
        	 	break;
        	}
        }
        if (pos == a.size()) {
        	cout << a << endl;
        	continue;
        }
        for (int k = pos; k < a.size(); k++) {
        	if (a[k] < b[pos]) {
        		swap(a[k], a[pos]);
        		cout << a << endl;
        		goto here;
        	}
        }
        for (int k = pos; k < a.size(); k++) {
         	if (a[k] == b[pos]) {
         		string h = a;
         		swap(h[k], h[pos]);
         		if (a < b) {
         			cout << a << endl;
         			goto here;
         		}
         	}
        }
        cout << "---\n";
        here:;
    }

    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int pos = inf;
    	for (int k = 0; k < min(a.size(), b.size()); k++) {
    		if (a[k] == b[k])
    			continue;
        	if (a[k] != b[k]) {
        	 	pos = k;
        	 	break;
        	}
        }
        if (pos == inf && a.size() < b.size()) {
        	cout << a << endl;
        	continue;
        }
        for (int k = pos + 1; k < a.size(); k++) {
        	if (a[k] < b[pos]) {
        		swap(a[k], a[pos]);
        		cout << a << endl;
        		goto here;
        	}
        }
        for (int k = pos + 1; k < a.size(); k++) {
         	if (a[k] == b[pos]) {
         		string h = a;
         		swap(h[k], h[pos]);
         		if (h < b) {
         			cout << h << endl;
         			goto here;
         		}
         	}
        }
        cout << "---\n";
        here:;
    }

    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int pos = inf;
    	for (int k = 0; k < min(a.size(), b.size()); k++) {
    		if (a[k] == b[k])
    			continue;
        	if (a[k] != b[k]) {
        	 	pos = k;
        	 	break;
        	}
        }
        if (pos == inf && a.size() < b.size()) {
        	cout << a << endl;
        	continue;
        }
        if (a < b) {
        	cout << a << endl;
        	continue;
        }
        for (int k = pos + 1; k < a.size(); k++) {
        	if (a[k] < b[pos]) {
        		swap(a[k], a[pos]);
        		cout << a << endl;
        		goto here;
        	}
        }
        for (int k = pos + 1; k < a.size(); k++) {
         	if (a[k] == b[pos]) {
         		string h = a;
         		swap(h[k], h[pos]);
         		if (h < b) {
         			cout << h << endl;
         			goto here;
         		}
         	}
        }
        cout << "---\n";
        here:;
    }

    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	int k = 0;
    	if (b.size() > a.size()) {
    		string h = "";
    	 	for (int j = 0; j < a.size(); j++)
    	 		h  += b[j];
    	 	b = h;
    	}
    	if (a < b) {
    	 	cout << a << endl;
    	 	goto here;
    	}
    	while (k < a.size()) {
    		int pos = 0;
    		char mn = 'Z';
    		for (int j = k; j < a.size(); j++) {
    	 		if (mn >= a[j]) {
    	 	  		mn = a[j];
    	 	  		pos = j;
    	 		}
    		}
    		if (pos != k) {
    			string p = a;
    		 	swap(p[pos], p[k]);
    		 	if (p <= b) {
    		 	 	cout << p << endl;
    		 	 	goto here;
    		 	}
    		}
    		k++;
    	}
    	cout << "---" << endl;
    	here:;
    }
    return false;
}


#include <bits/stdc++.h>

#define file ""

#define all(x) x.begin(), x.end()

#define sc second
#define fr first

#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int inf = 1e9;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
    freopen(file".in", "r", stdin);
    freopen(file".out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
    	string a, b;
    	cin >> a >> b;
    	if (a < b) {
    		cout << a << endl;
    		continue;
    	}

    	for (int j = 0; j < a.size(); j++)
    		for (int k = j + 1; k < a.size(); k++) {
    			swap(a[j], a[k]);
    			if (a < b) {
    				cout << a << endl;
    				goto p;
    			}
    			swap(a[j], a[k]);
    		}
    	cout << "---\n";
   		p:;
    }

    return false;
}


#include <bits/stdc++.h>
using namespace std;
#define sc(x)            scanf("%d",&x)
#define scc(x)           scanf("%c",&x)
#define scl(x)           scanf("%lld",&x)
#define sz(v)	     	(v.size())
#define mem(v, d)		memset(v, d, sizeof(v))
#define oo				2000000100
#define OO				2000000000000000100
#define PI 3.14159265
#define s second
#define f first
#define Ceil(x,y) ((x+y-1)/y)
#define EPS 1e-8
#define IO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define LFT(x)  (x*2)
#define RGHT(x) (x*2+1)
const double pi=3.14159265358979323846264338327950288419716939937510582097494459;
typedef unsigned int uint;
typedef long long ll;
int dX[] = {0,1,0,-1,1,1,-1,-1};
int dY[] = {1,0,-1,0,1,-1,1,-1};
string alpha = "abcdefghijklmnopqrstuvwxyz";
const int N = 300100;
vector<int>adj[30];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
    IO;
    int t; cin>>t;
    while(t--){
        string a,b; cin>>a>>b;
        bool flag = 0;

        for(int i=0;i<sz(a);++i)
            adj[a[i]-'A'].push_back(i);

        if(a < b) flag = 1;

        for(int i = 0;i<min(sz(a),sz(b)) && !flag;++i){

            for(char j = 'A';j<=b[i] && !flag; ++j){
                int c = j-'A';
                auto it = upper_bound(adj[c].begin(),adj[c].end(),i);
                if(it != adj[c].end())
                    swap(a[i],a[*it]),flag = 1;
            }
            if(a[i]>b[i]) break;
        }

        if(flag) cout << a << endl;
        else cout << "---\n";

        for(int i = 0;i<26;++i)
            adj[i].clear();
    }
    return 0;

}