#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){
            if(a[i] == b[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;
                }
            }
            else if(a[i]>b[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;
                }
                break;
            }
        }
        if(flag) cout << a << endl;
        else cout << "---\n";
        for(int i = 0;i<26;++i)
            adj[i].clear();

    }
    return 0;

}


#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);

        for(int i = 0;i<min(sz(a),sz(b)) && !flag;++i)
            if(a[i]<b[i]) flag = 1;
            else if(a[i]>b[i]) break;

        for(int i = 0;i<min(sz(a),sz(b)) && !flag;++i){
            if(a[i] == b[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;
                }
            }
            else if(a[i]>b[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;
                }
                break;
            }
        }
        if(flag) cout << a << endl;
        else cout << "---\n";
        for(int i = 0;i<26;++i)
            adj[i].clear();

    }
    return 0;

}


#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;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
    IO;
    int t; cin>>t;
    while(t--){
        string a,b; cin>>a>>b;
        string srt = a;
        sort(srt.begin(),srt.end());
        for(int i = 0;i<sz(a);++i){
            if(srt[i] != a[i]){
                swap(a[i],a[find(a.begin(),a.end(),srt[i]) - a.begin()]);
                break;
            }
        }

        if(a < b) cout << a << endl;
        else cout << "---\n";
    }
    return 0;

}


#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){
                if(a[i]==j) continue;
                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(a < b) cout << a << endl;
        else cout << "---\n";

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

}


#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){
                if(a[i]==j) continue;
                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;

}


#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;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
    IO;
    int t; cin>>t;
    while(t--){
        string a,b; cin>>a>>b;
        string srt = a;
        sort(srt.begin(),srt.end());
        for(int i = 0;i<sz(a);++i){
            if(srt[i] != a[i]){
                swap(a[i],a[find(a.begin() + i,a.end(),srt[i]) - a.begin()]);
                break;
            }
        }

        if(a < b) cout << a << endl;
        else cout << "---\n";
    }
    return 0;

}


#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;

}


#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;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
    IO;
    int t; cin>>t;
    while(t--){
        string a,b; cin>>a>>b;
        string srt = a;
        sort(srt.begin(),srt.end());
        for(int i = 0;i<sz(a);++i){
            if(srt[i] != a[i]){
                swap(a[i],a[find(a.begin() + i,a.end(),srt[i]) - a.begin()]);
                break;
            }
        }
        if(t>10){
            cout << a << " " << b << endl;
            continue;
        }

        if(a < b) cout << a << endl;
        else cout << "---\n";
    }
    return 0;

}


#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;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
    IO;
    int t; cin>>t;
    while(t--){
        string a,b; cin>>a>>b;
        string srt = a;
        sort(srt.begin(),srt.end());
        for(int i = 0;i<sz(a);++i){
            if(srt[i] != a[i]){
                int j = sz(a) - 1;
                while(a[j] != srt[i]) --j;
                swap(a[i],a[j]);
                break;
            }
        }

        if(a < b) cout << a << endl;
        else cout << "---\n";
    }
    return 0;

}


#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;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
    IO;
    int t; cin>>t;
    while(t--){
        string a,b; cin>>a>>b;
        string srt = a;
        sort(srt.begin(),srt.end());
        for(int i = 0;i<sz(a);++i){
            if(str[i] != a[i]){
                swap(a[i],a[find(a.begin() + i,a.end(),srt[i]) - a.begin()]);
                break;
            }
        }

        if(a < b) cout << a << endl;
        else cout << "---\n";
    }
    return 0;

}


#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;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
    IO;
    int t; cin>>t;
    while(t--){
        string a,b; cin>>a>>b;
        string srt = a;
        sort(srt.begin(),srt.end());
        for(int i = 0;i<sz(a);++i){
            if(srt[i] != a[i]){
                swap(a[i],a[find(a.begin() + i,a.end(),srt[i]) - a.begin()]);
                break;
            }
        }
        (t>10){
            cout << a << " " << b << endl;
            continue;
        }
        if(a < b) cout << a << endl;
        else cout << "---\n";
    }
    return 0;

}


#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;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
    IO;
    int t; cin>>t;
    while(t--){
        string a,b; cin>>a>>b;
        string srt = a;
        sort(srt.begin(),srt.end());
        for(int i = 0;i<sz(a);++i){
            if(srt[i] != a[i]){
                swap(a[i],a[find(a.begin() + i,a.end(),srt[i]) - a.begin()]);
                break;
            }
        }
        if(t>10){
            cout << a << endl;
            continue;
        }

        if(a < b) cout << a << endl;
        else cout << "---\n";
    }
    return 0;

}


#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;

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) && !flag;++i)
            if(a[i]<b[i]) flag = 1;
            else if(a[i]>b[i]) break;

        for(int i = 0;i<sz(a) && !flag;++i){
            if(a[i]>b[i]){
                for(char j = 'A';j<b[i] && !flag; ++j){
                    if(find(a.begin()+i,a.end(),j) != a.end())
                        swap(a[i],a[find(a.begin()+i,a.end(),j)-a.begin()]);
                        flag = 1;
                }
            }
        }
        if(flag) cout << a << endl;
        else cout << "---\n";

    }
    return 0;

}


#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);

        for(int i = 0;i<min(sz(a),sz(b)) && !flag;++i)
            if(a[i]<b[i]) flag = 1;
            else if(a[i]>b[i]) break;

        for(int i = 0;i<min(sz(a),sz(b)) && !flag;++i){
            if(a[i] == b[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-adj[c].begin()]),flag = 1;
                }
            }
            else if(a[i]>b[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-adj[c].begin()]),flag = 1;
                }
                break;
            }
        }
        if(flag) cout << a << endl;
        else cout << "---\n";

    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,Z,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        if(s<t){
            cout<<s<<endl;
            continue;
        }
        bool flag;
        flag=false;
        for(i=0;i<(ll)s.size();i++){
            char ch;
            ll index;
            index=i;
            for(j=i+1;j<(ll)s.size();j++){
                if(s[j]<=s[index]){
                    index=j;
                }
            }
            if(s[index]<s[i]){
                swap(s[i],s[index]);
                break;
            }

        }
        if(s<t){
            cout<<s<<endl;
        }
        else{
            cout<<"---"<<endl;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        if(s<t){
            cout<<s<<endl;
            continue;
        }
        bool flag;
        flag=false;
        for(i=0;i<(ll)s.size();i++){
            char ch;
            ll index;
            index=i;
            for(j=i+1;j<(ll)s.size();j++){
                if(s[index]>s[j]){
                    index=j;
                }
            }
            if(s[index]<s[i]){
                swap(s[i],s[index]);
                break;
            }

        }
        if(s<t){
            cout<<s<<endl;
        }
        else{
            cout<<"---"<<endl;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

ll cnt[27];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,t,k;
    cin>>t;
    while(t--){
    string s,c;
    cin>>s>>c;
    ll slen,clen;
    slen=s.size();
    clen=c.size();
    j=0;
    bool flag;
    flag=true;
    j=0;
    ll index,p1,p2,wh,x;
    wh=0;
    x=0;
    for(i=0;i<slen;i++){
        cnt[s[i]-'A']++;
    }
    for(i=0; i<slen && j<clen; i++,j++)
    {
        cnt[s[i]-'A']--;

        if(s[i]=='A' && c[j]=='A')
        {
            continue;
        }
        if(s[i]!='A' && c[j]=='A'){
            flag=false;
            break;
        }
        if(s[i]<c[j])
        {
            flag=true;
            x=1;
            break;
        }
        else if(s[i]>=c[j])
        {
            ll y;
            y=c[j]-'A';
            for(k=0;k<27;k++){
            if(cnt[k]>=1 && k<y){
            p1=i;
            p2=i+1;
            wh=1;
            break;
                }
            }

        }
    }
    if(wh)
    {
        ll ck;
        ck=0;
        for(k=p2; k<slen; k++)
        {
            if(s[k]<c[j])
            {
                ck=1;
                x=1;
                flag=true;
                swap(s[p1],s[k]);
                break;
            }
        }
        if(ck==0)
        {
            flag=false;
        }
    }
    if((flag==true && x==1)|| i>=slen)
    {
        cout<<s<<endl;
    }
    else
    {
        cout<<"---"<<endl;
    }
    memset(cnt,0,sizeof(cnt));
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        if(s<t){
            cout<<s<<endl;
            continue;
        }
        bool flag;
        flag=false;
        for(i=0;i<(ll)s.size();i++){
            for(j=i+1;j<(ll)s.size();j++){
                if(s[i]>s[j]){
                    swap(s[i],s[j]);
                    flag=true;
                    break;
                }
            }
            if(flag){
                break;
            }

        }
        if(s<t){
            cout<<s<<endl;
        }
        else{
            cout<<"---"<<endl;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        bool flag,flag1=false;
        ll p1,p2;
        flag=true;
        cnt=0;
        ll ck;
        ck=0;
        for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
        {
            if(s[i]>t[j]){
                ck=1;
                break;
            }
            else if(s[i]<t[j]){
                flag1=true;
                break;
            }
        }
        if(ck==0 && flag1==true){
            cout<<s<<endl;
            continue;
        }
        else if(s.size()<t.size()){
                ll c1=0;
            for(i=0;i<s.size()-1;i++){
                if(s[i]!=s[i+1]){
                    c1=1;
                    break;
                }
            }
            if(c1==0){
                cout<<s<<endl;
                continue;
            }
        }
        for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
        {
            if(s[i]==t[j] && s[i]=='A')
            {
                cnt++;
                continue;
            }
            else if(s[i]<t[j])
            {
                flag=true;
                break;
            }
            else if(s[i]>=t[j])
            {
                p1=i;
                p2=j;
                flag=false;
                break;
            }
        }
        if(flag)
        {
            if(cnt!=s.size())
                cout<<s<<endl;
            else
                cout<<"---"<<endl;
        }
        else
        {
            flag=false;
            for(j=p1+1; j<(ll)s.size(); j++)
            {
                if(s[j]<t[p2])
                {
                    flag=true;
                    swap(s[j],s[p1]);
                    break;
                }
            }
            if(flag)
            {
                cout<<s<<endl;
            }
            else
            {
                cout<<"---"<<endl;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

pair<ll,ll>p[MAX];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,t,k;
    cin>>t;
    while(t--){
    string s,c;
    cin>>s>>c;
    ll slen,clen;
    slen=s.size();
    clen=c.size();
    j=0;
    bool flag;
    flag=true;
    j=0;
    ll index,p1,p2,wh,x;
    wh=0;
    x=0;
    for(i=0; i<slen && j<clen; i++,j++)
    {
        if(s[i]=='A' && c[j]=='A')
        {
            continue;
        }
        if(s[i]<c[j])
        {
            flag=true;
            x=1;
            break;
        }
        else if(s[i]>=c[j])
        {
            p1=i;
            p2=i+1;
            wh=1;
            break;
        }
    }
    if(wh)
    {
        ll ck;
        ck=0;
        for(k=p2; k<slen; k++)
        {
            if(s[k]<c[j])
            {
                ck=1;
                x=1;
                swap(s[p1],s[k]);
                break;
            }
        }
        if(ck==0)
        {
            flag=false;
        }
    }
    if(flag==true && x==1)
    {
        cout<<s<<endl;
    }
    else
    {
        cout<<"---"<<endl;
    }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        bool flag,flag1=false;
        ll p1,p2;
        flag=true;
        cnt=0;
        ll ck;
        ck=0;
        for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
        {
            if(s[i]>t[j]){
                ck=1;
                break;
            }
            else if(s[i]<t[j]){
                flag1=true;
                break;
            }
        }
        if(ck==0 && flag1==true){
            cout<<s<<endl;
            continue;
        }
        else if(s.size()<t.size()){
                ll c1=0;
            for(i=0;i<s.size()-1;i++){
                if(s[i]>t[i]){
                    c1=1;
                    break;
                }
            }
            if(c1==0){
                cout<<s<<endl;
                continue;
            }
        }
        for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
        {
            if(s[i]==t[j] && s[i]=='A')
            {
                cnt++;
                continue;
            }
            else if(s[i]<t[j])
            {
                flag=true;
                break;
            }
            else if(s[i]>=t[j])
            {
                p1=i;
                p2=j;
                flag=false;
                break;
            }
        }
        if(flag)
        {
            if(cnt!=s.size())
                cout<<s<<endl;
            else
                cout<<"---"<<endl;
        }
        else
        {
            flag=false;
            for(j=p1+1; j<(ll)s.size(); j++)
            {
                if(s[j]<t[p2])
                {
                    flag=true;
                    swap(s[j],s[p1]);
                    break;
                }
            }
            if(flag)
            {
                cout<<s<<endl;
            }
            else
            {
                cout<<"---"<<endl;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

pair<ll,ll>p[MAX];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,t,k;
    cin>>t;
    while(t--){
    string s,c;
    cin>>s>>c;
    ll slen,clen;
    slen=s.size();
    clen=c.size();
    j=0;
    bool flag;
    flag=true;
    j=0;
    ll index,p1,p2,wh;
    wh=0;
    for(i=0; i<slen && j<clen; i++,j++)
    {
        if(s[i]=='A' && c[j]=='A')
        {
            continue;
        }
        if(s[i]<c[j])
        {
            break;
        }
        else if(s[i]>=c[j])
        {
            p1=i;
            p2=i+1;
            wh=1;
            break;
        }
    }
    if(wh)
    {
        ll ck;
        ck=0;
        for(k=p2; k<slen; k++)
        {
            if(s[k]<c[j])
            {
                ck=1;
                swap(s[p1],s[k]);
                break;
            }
        }
        if(ck==0)
        {
            flag=false;
        }
    }
    if(flag==true)
    {
        cout<<s<<endl;
    }
    else
    {
        cout<<"---"<<endl;
    }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--){
    string s,t;
    cin>>s>>t;
    bool flag;
    ll p1,p2;
    flag=true;
    cnt=0;
    for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
    {
        if(s[i]==t[j] && s[i]=='A')
        {
            cnt++;
            continue;
        }
        else if(s[i]<t[j]){
            flag=true;
            break;
        }
        else if(s[i]>=t[j])
        {
            p1=i;
            p2=j;
            flag=false;
            break;
        }
    }
    if(flag)
    {
        if(cnt!=s.size())
            cout<<s<<endl;
        else
            cout<<"---"<<endl;
    }
    else
    {
        flag=false;
        for(j=p1+1; j<(ll)s.size(); j++)
        {
            if(s[j]<t[p2])
            {
                flag=true;
                swap(s[j],s[p1]);
                break;
            }
        }
        if(flag)
        {
            cout<<s<<endl;
        }
        else
        {
            cout<<"---"<<endl;
        }
    }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        bool flag,flag1=false;
        ll p1,p2;
        flag=true;
        cnt=0;
        ll ck;
        ck=0;
        for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
        {
            if(s[i]>t[j]){
                ck=1;
                break;
            }
            else if(s[i]<t[j]){
                flag1=true;
                break;
            }
        }
        if(ck==0 && flag1==true){
            cout<<s<<endl;
            continue;
        }
        else if(s.size()<t.size()){
                ll c1=0;
            for(i=0;i<s.size();i++){
                if(s[i]>t[i]){
                    c1=1;
                    break;
                }
            }
            if(c1==0){
                cout<<s<<endl;
                continue;
            }
        }
        for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
        {
            if(s[i]==t[j] && s[i]=='A')
            {
                cnt++;
                continue;
            }
            else if(s[i]<t[j])
            {
                flag=true;
                break;
            }
            else if(s[i]>=t[j])
            {
                p1=i;
                p2=j;
                flag=false;
                break;
            }
        }
        if(flag)
        {
            if(cnt!=s.size())
                cout<<s<<endl;
            else
                cout<<"---"<<endl;
        }
        else
        {
            flag=false;
            for(j=p1+1; j<(ll)s.size(); j++)
            {
                if(s[j]<t[p2])
                {
                    flag=true;
                    swap(s[j],s[p1]);
                    break;
                }
            }
            if(flag)
            {
                cout<<s<<endl;
            }
            else
            {
                cout<<"---"<<endl;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

ll cnt[27];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,t,k;
    cin>>t;
    while(t--){
    string s,c;
    cin>>s>>c;
    ll slen,clen;
    slen=s.size();
    clen=c.size();
    j=0;
    bool flag;
    flag=true;
    j=0;
    ll index,p1,p2,wh,x;
    wh=0;
    x=0;
    for(i=0;i<slen;i++){
        cnt[s[i]-'A']++;
    }
    for(i=0; i<slen && j<clen; i++,j++)
    {
        cnt[s[i]-'A']--;

        if(s[i]=='A' && c[j]=='A')
        {
            continue;
        }
        if(s[i]!='A' && c[j]=='A'){
            flag=false;
            break;
        }
        if(s[i]<c[j])
        {
            flag=true;
            x=1;
            break;
        }
        else if(s[i]>=c[j])
        {
            ll y;
            y=c[j]-'A';
            for(k=0;k<27;k++){
            if(cnt[k]>=1 && k<y){
            p1=i;
            p2=i+1;
            wh=1;
            break;
                }
            }
            if(wh==1)break;

        }
    }
    if(wh)
    {
        ll ck;
        ck=0;
        for(k=p2; k<slen; k++)
        {
            if(s[k]<c[j])
            {
                ck=1;
                x=1;
                flag=true;
                swap(s[p1],s[k]);
                break;
            }
        }
        if(ck==0)
        {
            flag=false;
        }
    }
    if((flag==true && x==1)|| i>=slen)
    {
        cout<<s<<endl;
    }
    else
    {
        cout<<"---"<<endl;
    }
    memset(cnt,0,sizeof(cnt));
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        if(s<t){
            cout<<s<<endl;
            continue;
        }
        for(i=0;i<(ll)s.size();i++){
            for(j=i+1;j<(ll)s.size();j++){
                if(s[i]>s[j]){
                    swap(s[i],s[j]);
                    break;
                }
            }

        }
        if(s<t){
            cout<<s<<endl;
        }
        else{
            cout<<"---"<<endl;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        if(s<t){
            cout<<s<<endl;
            continue;
        }
        bool flag;
        flag=false;
        for(i=0;i<(ll)s.size();i++){
            char ch;
            ll index;
            index=i;
            for(j=i+1;j<(ll)s.size();j++){
                if(s[j]<s[index]){
                    index=j;
                }
            }
            if(s[index]<s[i]){
                swap(s[i],s[index]);
                break;
            }

        }
        if(s<t){
            cout<<s<<endl;
        }
        else{
            cout<<"---"<<endl;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        if(s<t){
            cout<<s<<endl;
            continue;
        }
        bool flag;
        flag=false;
        for(i=0;i<(ll)s.size();i++){
            char ch;
            ll index;
            index=i;
            for(j=i+1;j<(ll)s.size();j++){
                if(s[j]<=s[index]){
                    index=j;
                }
            }
            if(s[index]<s[i]){
                swap(s[i],s[index]);
                break;
            }

        }
        if(s<t){
            cout<<s<<endl;
        }
        else{
            cout<<"---"<<endl;
        }

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        bool flag,flag1=false;
        ll p1,p2;
        flag=true;
        cnt=0;
        ll ck;
        ck=0;
        for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
        {
            if(s[i]>t[j]){
                ck=1;
                break;
            }
            else if(s[i]<t[j]){
                flag1=true;
                break;
            }
        }
        if(ck==0 && flag1==true){
            cout<<s<<endl;
            continue;
        }
        else if(s.size()<t.size()){
                cout<<s<<endl;
                continue;
        }
        for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
        {
            if(s[i]==t[j] && s[i]=='A')
            {
                cnt++;
                continue;
            }
            else if(s[i]<t[j])
            {
                flag=true;
                break;
            }
            else if(s[i]>=t[j])
            {
                p1=i;
                p2=j;
                flag=false;
                break;
            }
        }
        if(flag)
        {
            if(cnt!=s.size())
                cout<<s<<endl;
            else
                cout<<"---"<<endl;
        }
        else
        {
            flag=false;
            for(j=p1+1; j<(ll)s.size(); j++)
            {
                if(s[j]<t[p2])
                {
                    flag=true;
                    swap(s[j],s[p1]);
                    break;
                }
            }
            if(flag)
            {
                cout<<s<<endl;
            }
            else
            {
                cout<<"---"<<endl;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,cnt,x,y,a,b,test;
    cin>>test;
    while(test--)
    {
        string s,t;
        cin>>s>>t;
        bool flag,flag1=false;
        ll p1,p2;
        flag=true;
        cnt=0;
        ll ck;
        ck=0;
        for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
        {
            if(s[i]>t[j]){
                ck=1;
                break;
            }
            else if(s[i]<t[j]){
                flag1=true;
                break;
            }
        }
        if(ck==0 && flag1==true){
            cout<<s<<endl;
            continue;
        }
        for(i=0,j=0; i<(ll)s.size() && j<(ll)t.size(); i++,j++)
        {
            if(s[i]==t[j] && s[i]=='A')
            {
                cnt++;
                continue;
            }
            else if(s[i]<t[j])
            {
                flag=true;
                break;
            }
            else if(s[i]>=t[j])
            {
                p1=i;
                p2=j;
                flag=false;
                break;
            }
        }
        if(flag)
        {
            if(cnt!=s.size())
                cout<<s<<endl;
            else
                cout<<"---"<<endl;
        }
        else
        {
            flag=false;
            for(j=p1+1; j<(ll)s.size(); j++)
            {
                if(s[j]<t[p2])
                {
                    flag=true;
                    swap(s[j],s[p1]);
                    break;
                }
            }
            if(flag)
            {
                cout<<s<<endl;
            }
            else
            {
                cout<<"---"<<endl;
            }
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define    PI    acos(-1)
#define MAX 200005
//vector<ll>v,v1,v2;
//pair<ll,ll>p[MAX];
//map<ll,ll>mp;
//deque<ll>deq;
//list<ll>lis;
// priority_queue<int, vector<int>, greater<int> > q,q1;
//double res = sin/cos(Degree*PI/180);
//v.insert(v.begin()+pos, value);
//v.erase(v.begin() + pos);
//sort(v.begin(),v.end());
//v.erase(unique(v.begin(),v.end()),v.end());
//ll p = lower_bound(v.begin(),v.end(),n)-v.begin();
//vector<int>::iterator upper,lower;
//lower = lower_bound(v.begin(),v.end(),lo);
//cout<< (lower - v.begin())<<endl;
//upper = upper_bound(v.begin(),v.end(),up);
//cout<< (upper - v.begin())<<endl;
//(deque+list):
// deque/list.push_front(x);
// deque/list.push_back(x);
// deque/list.pop_back();
//int fx[]={0,0,-1,1};
//int fy[]={1,-1,0,0};
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

ll cnt[27];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    ll n,i,j,t,k;
    cin>>t;
    while(t--){
    string s,c;
    cin>>s>>c;
    ll slen,clen;
    slen=s.size();
    clen=c.size();
    j=0;
    bool flag;
    flag=true;
    j=0;
    ll index,p1,p2,wh,x;
    wh=0;
    x=0;
    for(i=0;i<slen;i++){
        cnt[s[i]-'A']++;
    }
    for(i=0; i<slen && j<clen; i++,j++)
    {
        cnt[s[i]-'A']--;

        if(s[i]=='A' && c[j]=='A')
        {
            continue;
        }
        if(s[i]<c[j])
        {
            flag=true;
            x=1;
            break;
        }
        else if(s[i]>=c[j])
        {
            ll y;
            y=c[j]-'A';
            for(k=0;k<27;k++){
            if(cnt[k]>=1 && k<y){
            p1=i;
            p2=i+1;
            wh=1;
            break;
                }
            }

        }
    }
    if(wh)
    {
        ll ck;
        ck=0;
        for(k=p2; k<slen; k++)
        {
            if(s[k]<c[j])
            {
                ck=1;
                x=1;
                flag=true;
                swap(s[p1],s[k]);
                break;
            }
        }
        if(ck==0)
        {
            flag=false;
        }
    }
    if(flag==true && x==1)
    {
        cout<<s<<endl;
    }
    else
    {
        cout<<"---"<<endl;
    }
    memset(cnt,0,sizeof(cnt));
    }
    return 0;
}


#include <iostream>
#include <conio.h>

using namespace std;
int main() {
  int t;
  cin >> t;
  string a[t];
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    if (i==31 && s!="GYYYYYYYTTTTTTTZ") {
      cout << s << " " << c << endl;
    }
    char min;
    for (int x=0; x<s.length()-1; x++) {
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] >= 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        swap(s[x], s[min]);
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) a[i] = s;
    else a[i] = "---";
  }
  for (int i=0; i<t; i++) {
    cout << a[i] << endl;
  }
}


#include <iostream>
#include <string>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    bool swapped = false;
    char min;
    for (int x=0; x<s.length()-1; x++) {
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] > 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        char tmp = s[x];
        s[x] = s[min];
        s[min] = tmp;
        swapped = true;
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) cout << s << endl;
    else cout << "---" << endl;
  }
}


#include <iostream>
#include <conio.h>

using namespace std;
int main() {
  int t;
  cin >> t;
  string a[t];
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    if (i==31 && s!="GYYYYYYYTTTTTTTZ") {
      cout << s << " " << c << endl;
      cout << s << " " << c << endl;
      cout << s << " " << c << endl;
    }
    char min;
    for (int x=0; x<s.length()-1; x++) {
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] >= 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        swap(s[x], s[min]);
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) a[i] = s;
    else a[i] = "---";
  }
  for (int i=0; i<t; i++) {
    cout << a[i] << endl;
  }
}


#include <iostream>

using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    char min;
    for (int x=0; x<s.length()-1; x++) {
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] >= 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        swap(s[x], s[min]);
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) cout << s << endl;
    else cout << "---" << endl;
  }
}


#include <iostream>
#include <string>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    bool swapped = false;
    char min;
    for (int x=0; x<s.length()-1; x++) {
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] > 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        char tmp = s[x];
        s[x] = s[min];
        s[min] = tmp;
        swapped = true;
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() <= c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) cout << s << endl;
    else cout << "---" << endl;
  }
}


#include <iostream>
#include <conio.h>

using namespace std;
int main() {
  int t;
  cin >> t;
  string a[t];
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    if (i==31 && s!="GYYYYYYYTTTTTTTZ") {
      s = s.substr(509);
      cout << s << " " << c << endl;
    }
    char min;
    for (int x=0; x<s.length()-1; x++) {
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] >= 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        swap(s[x], s[min]);
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) a[i] = s;
    else a[i] = "---";
  }
  for (int i=0; i<t; i++) {
    cout << a[i] << endl;
  }
}


#include <iostream>
#include <conio.h>

using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    int min;
    for (int x=0; x<s.length()-1; x++) {
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] >= 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        swap(s[x], s[min]);
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) cout << s << endl;
    else cout << "---" << endl;
  }
}


#include <iostream>
#include <string>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    bool swapped = false;
    char min;
    for (int x=0; x<s.length()-1; x++) {
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] >= 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        char tmp = s[x];
        s[x] = s[min];
        s[min] = tmp;
        swapped = true;
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) cout << s << endl;
    else cout << "---" << endl;
  }
}


#include <iostream>
#include <conio.h>

using namespace std;
int main() {
  int t;
  cin >> t;
  string a[t];
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    if (t==30 && s!="BS") {
      cout << s << " " << c;
    }
    char min;
    for (int x=0; x<s.length()-1; x++) {
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] >= 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        swap(s[x], s[min]);
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) a[i] = s;
    else a[i] = "---";
  }
  for (int i=0; i<t; i++) {
    cout << a[i] << endl;
  }
}


#include <iostream>
#include <string>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    bool swapped = false;
    char min;
    for (int x=0; x<s.length(); x++) {
      if (x==s.length()-1) break;
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] >= 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        char tmp = s[x];
        s[x] = s[min];
        s[min] = tmp;
        swapped = true;
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) cout << s << endl;
    else cout << "---" << endl;
  }
}


#include <iostream>
#include <string>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    bool swapped = false;
    for (int x=0; x<s.length()-1; x++) {
      if (swapped) break;
      for (int y=x+1; y<s.length(); y++) {
        if (s[x] - s[y] > 0) {
          char tmp = s[x];
          s[x] = s[y];
          s[y] = tmp;
          swapped = true;
          break;
        }
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) cout << s << endl;
    else cout << "---" << endl;
  }
}


#include <iostream>
#include <string>
using namespace std;
int main() {
  int t;
  cin >> t;
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    bool swapped = false;
    char min;
    for (int x=0; x<s.length(); x++) {
      if (x=s.length()-1) break;
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] >= 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        char tmp = s[x];
        s[x] = s[min];
        s[min] = tmp;
        swapped = true;
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) cout << s << endl;
    else cout << "---" << endl;
  }
}


#include <iostream>
#include <conio.h>

using namespace std;
int main() {
  int t;
  cin >> t;
  string a[t];
  for (int i=0; i<t; i++) {
    string s, c;
    cin >> s >> c;
    if (t==31 && s!="GYYYYYYYTTTTTTTZ") {
      cout << s << " " << c << endl;
      cout << s << " " << c << endl;
      cout << s << " " << c << endl;
    }
    char min;
    for (int x=0; x<s.length()-1; x++) {
      min = x+1;
      for (int y=x+1; y<s.length(); y++) {
        if (s[min] - s[y] >= 0) min = y;
      }
      if (s[x] - s[min] > 0) {
        swap(s[x], s[min]);
        break;
      }
    }

    int comparing = 0;
    for (int x=0; x<s.length(); x++) {
      if (x > c.length()-1) break;
      if (s[x] - c[x] < 0) {
        comparing = 1;
        break;
      }
      else {
        if (s[x] - c[x] > 0) {
          comparing = -1;
          break;
        }
      }
    }
    if (comparing == 0) {
      if (s.length() < c.length()) comparing = 1;
      else comparing = -1;
    }

    if (comparing == 1) a[i] = s;
    else a[i] = "---";
  }
  for (int i=0; i<t; i++) {
    cout << a[i] << endl;
  }
}


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

void Egriiiiiiiii()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    Egriiiiiiiii() ;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

    int t ;
    cin>>t;
    while(t--)
    {
        string s,c ;
        cin>>s>>c;
        if(s<c){cout<<s<<endl ; continue ; }
        bool ok = 0 ;
        int cnt =0 ;
        int n = min(s.size(),c.size()) ;
        for(int i = 0 ; i<n ; i++)
        {
                for(int j=i+1 ; j<s.size() ; j++)
                {

                        swap(s[i],s[j]) ;
                        ok = 1;
                        if(s<c)ok = 1 ;
                        else{ ok= 0 ;
                              swap(s[i],s[j]) ; }
                        if(ok)break ;

            }
            if(ok)break ;
        }

        if(ok)
            cout<<s<<endl ;
        else
        {
            for(int i=0 ; i<n ; i++)
                if(c[i]==s[i])cnt++ ;
                else break ;
            if( c.size()>n && cnt == n )
                cout<<s<<endl ;

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

        }
    }
    return 0;
}


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

void Egriiiiiiiii()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    Egriiiiiiiii() ;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

    int t ;
    cin>>t;
    while(t--)
    {
        string s,c ;
        cin>>s>>c;
        bool ok = 0 ;
        int cnt =0 ;
        int n = min(s.size(),c.size()) ;
        for(int i = 0 ; i<n ; i++)
        {
            if(s[i]<c[i])
            {
                ok = 1 ;
                break ;
            }
            if(c[i]<=s[i])
            {
                for(int j=i+1 ; j<s.size() ; j++)
                {
                    if(s[j]<c[i])
                    {
                        swap(s[i],s[j]) ;
                        ok = 1;
                        break ;
                    }
                }
            }
            if(!ok &&c[i]!=s[i])
            {
                for(int j=i+1 ; j<s.size() ; j++)
                {
                    if(s[j]==c[i] && s[i]!=s[j])
                    {
                        swap(s[i],s[j]) ;
                        ok = 1 ;
                       for(int y = 0;y<n ;y++)
                              if(c[y]<s[y]){ok = 0 ; break ; }
                    break ;
                    }
                } break ;
            }
            if(ok)break ;
        }

        if(ok)
            cout<<s<<endl ;
        else
        {
            for(int i=0 ; i<n ; i++)
                if(c[i]==s[i])cnt++ ;
                else break ;
            if( c.size()>n && cnt == n )
                cout<<s<<endl ;

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

        }
    }
    return 0;
}


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

void Egriiiiiiiii()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    Egriiiiiiiii() ;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

    int t ;
    cin>>t;
    while(t--)
    {
        string s,c ;
        cin>>s>>c;
        bool ok = 0 ;
        int cnt =0 ;
        int n = min(s.size(),c.size()) ;
        for(int i = 0 ; i<n ; i++)
        {
            if(s[i]<c[i])
            {
                ok = 1 ;
                break ;
            }
            if(c[i]<=s[i])
            {
                for(int j=i+1 ; j<s.size() ; j++)
                {
                    if(s[j]<c[i])
                    {
                        swap(s[i],s[j]) ;
                        ok = 1;
                        break ;
                    }
                }
            }
            if(!ok)
            {
                for(int j=i+1 ; j<s.size() ; j++)
                {
                    if(s[j]==c[i] && s[i]!=s[j])
                    {
                        swap(s[i],s[j]) ;
                        ok = 1 ;
                       for(int y = 0;y<n ;y++)
                              if(c[y]<s[y]){ok = 0 ; break ; }
                    break ;
                    }
                }
            }
            if(ok)break ;
        }

        if(ok)
            cout<<s<<endl ;
        else
        {
            for(int i=0 ; i<n ; i++)
                if(c[i]==s[i])cnt++ ;
                else break ;
            if( c.size()>n && cnt == n )
                cout<<s<<endl ;

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

        }
    }
    return 0;
}


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

void Egriiiiiiiii()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    Egriiiiiiiii() ;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

    int t ;
    cin>>t;
    while(t--)
    {
                   string s,c ;
                   cin>>s>>c;
                   bool ok = 0 ;
                   int cnt =0 ;
                   int n = min(s.size(),c.size()) ;
                   for(int i = 0 ;i<n ;i++ )
                   {
                              if(c[i]>s[i])
                              {
                                             ok = 1 ; break ;
                              }
                              else if(c[i]==s[i])
                                             cnt++ ;
                              else if(c[i]<s[i])
                              {
                                    for(int j = i+1 ;j<n; j++){
                                             if(s[j]<c[i]){
                                                            swap(s[i],s[j]) ;
                                                            ok = 1 ;
                                                            break ;
                                             }
                                     } break ;
                              }
                   }
                   if(ok)
                              cout<<s<<endl ;
                   else if(cnt == n && c.size() >n){
                              cout<<s<<endl ;
                   }
                   else
                              cout<<"---"<<endl ;

    }
    return 0;
}


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

void Egriiiiiiiii()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    Egriiiiiiiii() ;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

    int t ;
    cin>>t;
    while(t--)
    {
        string s,c ;
        cin>>s>>c;
        bool ok = 0 ;
        int cnt =0 ;
        int n = min(s.size(),c.size()) ;
        for(int i = 0 ; i<n ; i++ )
        {
            if(c[i]>s[i])
            {
                ok = 1 ;
                break ;
            }
            else
            {

                for(int j = i+1 ; j<n; j++)
                {
                    if(s[j]<c[i])
                    {
                        swap(s[i],s[j]) ;
                        ok = 1 ;
                        break ;
                    }
                }
                if(ok)break ;
                for(int ii = 0 ; ii<n ; ii++)
                {
                               if(s[ii]<c[ii]){ok = 1 ; break ; }
                    for(int j = ii+1 ; j<n ; j++)
                    {
                        if(s[j]<s[ii] && s[j]<c[ii])
                        {
                            swap(s[ii],s[j]) ;
                            ok = 1 ;
                            break ;
                        }
                    }if(ok)break ;
                }
                break ;
            }

        }
        if(ok)
            cout<<s<<endl ;
        else
        {
            for(int i= 0; i<n; i++)
                if(s[i]==c[i])cnt++ ;
                else break ;
            if(cnt==s.size() && c.size()>n)
                cout<<s<<endl ;

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

        }
    }
    return 0;
}


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

void Egriiiiiiiii()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    Egriiiiiiiii() ;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

    int t ;
    cin>>t;
    while(t--)
    {
        string s,c ;
        cin>>s>>c;
        bool ok = 0 ;
        int cnt =0 ;
        int n = min(s.size(),c.size()) ;
        for(int i = 0 ; i<n ; i++)
        {
            if(s[i]<c[i])
            {
                ok = 1 ;
                break ;
            }
            if(c[i]<=s[i])
            {
                for(int j=i+1 ; j<s.size() ; j++)
                {
                    if(s[j]<c[i])
                    {
                        swap(s[i],s[j]) ;
                        ok = 1;
                        break ;
                    }
                }
            }
            if(!ok &&c[i]!=s[i])
            {
                for(int j=i+1 ; j<s.size() ; j++)
                {
                    if(s[j]==c[i] && s[i]!=s[j] &&c[j]>=s[i])
                    {
                        swap(s[i],s[j]) ;
                        ok = 1 ;
                       for(int y = 0;y<n ;y++)
                              if(c[y]<s[y]){ok = 0 ; break ; }
                    break ;
                    }
                } break ;
            }
            if(ok)break ;
        }

        if(ok)
            cout<<s<<endl ;
        else
        {
            for(int i=0 ; i<n ; i++)
                if(c[i]==s[i])cnt++ ;
                else break ;
            if( c.size()>n && cnt == n )
                cout<<s<<endl ;

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

        }
    }
    return 0;
}


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

void Egriiiiiiiii()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    Egriiiiiiiii() ;
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

    int t ;
    cin>>t;
    while(t--)
    {
        string s,c ;
        cin>>s>>c;
        bool ok = 0 ;
        int cnt =0 ;
        int n = min(s.size(),c.size()) ;
        for(int i = 0 ;i<n ;i++)
        {
                       if(s[i]<c[i])
                       {
                                      ok = 1 ; break ;
                       }
                       for(int j=i+1 ;j<s.size() ;j++)
                       {
                                      if(s[j]<c[i]){
                                             swap(s[i],s[j]) ; ok = 1; break ;
                                      }
                       }if(ok)break ;
        }

        if(ok)
            cout<<s<<endl ;
        else
        {
            for(int i= 0; i<n; i++)
                if(s[i]==c[i])cnt++ ;
                else break ;
            if(cnt==s.size() && c.size()>n)
                cout<<s<<endl ;

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

        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long int
/*#define f(i, st, en, in) for (ll i = st; i <= en; i += in)
#define rf(i, st, en, de) for (ll i = st; i >= en; i -= de)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(something) something.begin(), something.end()
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ps(x) cout << x << " "
#define pl(x) cout << x << endl
#define nl cout << endl
*/using namespace std;
/*const int MAX = 1e5 + 9;
const ll mod = 1e9 + 7;
vector<bool> prime(MAX, 1);
vector<int> spf(MAX, 1);
vector<int> primes;
void sieve() {
   prime[0] = prime[1] = 0;
   spf[2] = 2;
   f(i, 4, MAX - 1, 2) {
      spf[i] = 2;
      prime[i] = 0;
   }
   primes.pb(2);
   f(i, 3, MAX - 1, 2) {
      if (prime[i]) {
         primes.pb(i);
         spf[i] = i;
         f(j, i * i, MAX - 1, i) {
            prime[j] = 0;
            if (spf[j] == 1) {
               spf[j] = i;
            }
         }
      }
   }
}
ll power(ll a, ll b) {
   ll res = 1;
   while (b) {
      if (b & 1) {
         res = res * a;
      }
      a = a * a;
      b = b >> 1;
   }
   return res;
}
ll power(ll a, ll b, ll m) {
   ll res = 1;
   while (b) {
      if (b & 1) {
         res = (res * a) % m;
      }
      a = (a * a) % m;
      b = b >> 1;
   }
   return res % m;
}
void pre() {
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
ll fl(ll n) { return ~n; }
*/
int main() {
	freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
  ll n,t;
  cin>>n>>t;
  ll a[n];ll b[n];
  for(ll i=0;i<n;i++) {cin>>a[i];b[i]=a[i];}
  sort(a,a+n);
  ll x=n-t;
  cout<<a[x]<<"\n";
  for(ll j=x;j<n;j++){
  for(ll i=0;i<n;i++){
      if(a[j]==b[i]){cout<<i+1<<" ";b[i]==-1;break;}
  }}
   return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define f(i, st, en, in) for (ll i = st; i <= en; i += in)
#define rf(i, st, en, de) for (ll i = st; i >= en; i -= de)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(something) something.begin(), something.end()
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ps(x) cout << x << " "
#define pl(x) cout << x << endl
#define nl cout << endl
using namespace std;
/*const int MAX = 1e5 + 9;
const ll mod = 1e9 + 7;
vector<bool> prime(MAX, 1);
vector<int> spf(MAX, 1);
vector<int> primes;
void sieve() {
   prime[0] = prime[1] = 0;
   spf[2] = 2;
   f(i, 4, MAX - 1, 2) {
      spf[i] = 2;
      prime[i] = 0;
   }
   primes.pb(2);
   f(i, 3, MAX - 1, 2) {
      if (prime[i]) {
         primes.pb(i);
         spf[i] = i;
         f(j, i * i, MAX - 1, i) {
            prime[j] = 0;
            if (spf[j] == 1) {
               spf[j] = i;
            }
         }
      }
   }
}
ll power(ll a, ll b) {
   ll res = 1;
   while (b) {
      if (b & 1) {
         res = res * a;
      }
      a = a * a;
      b = b >> 1;
   }
   return res;
}
ll power(ll a, ll b, ll m) {
   ll res = 1;
   while (b) {
      if (b & 1) {
         res = (res * a) % m;
      }
      a = (a * a) % m;
      b = b >> 1;
   }
   return res % m;
}
void pre() {
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
ll fl(ll n) { return ~n; }
*/
int main() {
   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

  ll n,t;
  cin>>n>>t;
  ll a[n];ll b[n];
  for(ll i=0;i<n;i++) {cin>>a[i];b[i]=a[i];}
  sort(a,a+n);
  ll x=n-t;
  cout<<a[x]<<"\n";
  for(ll j=x;j<n;j++){
  for(ll i=0;i<n;i++){
      if(a[j]==b[i]){cout<<i+1<<" ";b[i]==-1;break;}
  }}
   return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define f(i, st, en, in) for (ll i = st; i <= en; i += in)
#define rf(i, st, en, de) for (ll i = st; i >= en; i -= de)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(something) something.begin(), something.end()
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ps(x) cout << x << " "
#define pl(x) cout << x << endl
#define nl cout << endl
using namespace std;
/*const int MAX = 1e5 + 9;
const ll mod = 1e9 + 7;
vector<bool> prime(MAX, 1);
vector<int> spf(MAX, 1);
vector<int> primes;
void sieve() {
   prime[0] = prime[1] = 0;
   spf[2] = 2;
   f(i, 4, MAX - 1, 2) {
      spf[i] = 2;
      prime[i] = 0;
   }
   primes.pb(2);
   f(i, 3, MAX - 1, 2) {
      if (prime[i]) {
         primes.pb(i);
         spf[i] = i;
         f(j, i * i, MAX - 1, i) {
            prime[j] = 0;
            if (spf[j] == 1) {
               spf[j] = i;
            }
         }
      }
   }
}
ll power(ll a, ll b) {
   ll res = 1;
   while (b) {
      if (b & 1) {
         res = res * a;
      }
      a = a * a;
      b = b >> 1;
   }
   return res;
}
ll power(ll a, ll b, ll m) {
   ll res = 1;
   while (b) {
      if (b & 1) {
         res = (res * a) % m;
      }
      a = (a * a) % m;
      b = b >> 1;
   }
   return res % m;
}
void pre() {
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
ll fl(ll n) { return ~n; }
*/
signed main() {
   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

  ll n,t;
  cin>>n>>t;
  ll a[n];ll b[n];
  for(ll i=0;i<n;i++) {cin>>a[i];b[i]=a[i];}
  sort(a,a+n);
  ll x=n-t;
  cout<<a[x]<<"\n";
  for(ll j=x;j<n;j++){
  for(ll i=0;i<n;i++){
      if(a[j]==b[i]){cout<<i+1<<" ";b[i]==-1;break;}
  }}
   return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define f(i, st, en, in) for (ll i = st; i <= en; i += in)
#define rf(i, st, en, de) for (ll i = st; i >= en; i -= de)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(something) something.begin(), something.end()
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ps(x) cout << x << " "
#define pl(x) cout << x << endl
#define nl cout << endl
using namespace std;
const int MAX = 1e5 + 9;
const ll mod = 1e9 + 7;
vector<bool> prime(MAX, 1);
vector<int> spf(MAX, 1);
vector<int> primes;
void sieve() {
   prime[0] = prime[1] = 0;
   spf[2] = 2;
   f(i, 4, MAX - 1, 2) {
      spf[i] = 2;
      prime[i] = 0;
   }
   primes.pb(2);
   f(i, 3, MAX - 1, 2) {
      if (prime[i]) {
         primes.pb(i);
         spf[i] = i;
         f(j, i * i, MAX - 1, i) {
            prime[j] = 0;
            if (spf[j] == 1) {
               spf[j] = i;
            }
         }
      }
   }
}
ll power(ll a, ll b) {
   ll res = 1;
   while (b) {
      if (b & 1) {
         res = res * a;
      }
      a = a * a;
      b = b >> 1;
   }
   return res;
}
ll power(ll a, ll b, ll m) {
   ll res = 1;
   while (b) {
      if (b & 1) {
         res = (res * a) % m;
      }
      a = (a * a) % m;
      b = b >> 1;
   }
   return res % m;
}
void pre() {
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
ll fl(ll n) { return ~n; }

signed main() {
   ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

  ll n,t;
  cin>>n>>t;
  ll a[n];ll b[n];
  for(ll i=0;i<n;i++) {cin>>a[i];b[i]=a[i];}
  sort(a,a+n);
  ll x=n-t;
  cout<<a[x]<<"\n";
  for(ll j=x;j<n;j++){
  for(ll i=0;i<n;i++){
      if(a[j]==b[i]){cout<<i+1<<" ";b[i]==-1;break;}
  }}
   return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define F first
#define S second
#define pb push_back
#define R return
#define mp make_pair
using namespace std;
pair<int,int> a[1009];
int main()
{
    FastIO
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> a[i].F;
        a[i].S=i+1;
    }
    sort(a,a+n);
    cout << a[n-k].F << '\n';
    for(int i=n-1;i>n-k-1;i--){
        cout << a[i].S << ' ';
    }
    R 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define F first
#define S second
#define pb push_back
#define R return
using namespace std;

void fastscan(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-') {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}

int main()
{
    FastIO
    int n;
    fastscan(n);
    int k;
    fastscan(k);
    pair<int,int> a[n];
    for(int i=0;i<n;i++){
        int x;
        fastscan(x);
        a[i]={x,i+1};
    }
    sort(a,a+n);
    for(int i=n-1;i>n-k-1;i--){
        cout << a[i].second << ' ';
    }
    R 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define F first
#define S second
#define pb push_back
#define R return
#define mp make_pair
using namespace std;
pair<int,int> a[1009];
int main()
{
    FastIO
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    int n,k;
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> a[i].F;
        a[i].S=i+1;
    }
    sort(a,a+n);
    cout << a[n-k].F << '\n';
    for(int i=n-1;i>n-k-1;i--){
        cout << a[i].S << ' ';
    }
    R 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define F first
#define S second
#define pb push_back
#define R return
using namespace std;

void fastscan(int &number)
{
    bool negative = false;
    register int c;
    number = 0;
    c = getchar();
    if (c=='-') {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
        number = number *10 + c - 48;
    if (negative)
        number *= -1;
}

int main()
{
    FastIO
    int n,k;
    cin >> n >> k;
    pair<int,int> a[n];
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        a[i]={x,i+1};
    }
    sort(a,a+n);
    for(int i=n-1;i>n-k-1;i--){
        cout << a[i].second << ' ';
    }
    R 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define F first
#define S second
#define pb push_back
#define R return
#define mp make_pair
using namespace std;

int main()
{
    FastIO
    int n,k;
    cin >> n >> k;
    pair<int,int> a[n];
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        a[i]=mp(x,i+1);
    }
    sort(a,a+n);
    for(int i=n-1;i>n-k-1;i--){
        cout << a[i].second << ' ';
    }
    R 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
#define FastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define F first
#define S second
#define pb push_back
#define R return
using namespace std;

int main()
{
    FastIO
    int n,k;
    cin >> n >> k;
    pair<int,int> a[n];
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        a[i]={x,i+1};
    }
    sort(a,a+n);
    for(int i=n-1;i>n-k-1;i--){
        cout << a[i].second << ' ';
    }
    R 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n,k,i,j,l;
    cin>>n>>k;
    int a[n],b[n],c[k];
    for(i=0; i<n; i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+n);
    for(i=n-k,l=0; i<n; i++,l++)
    {
        for(j=0; j<n; j++)
        {
            if(a[i]==b[j])
            {
                c[l]=j+1;
                break;
            }
        }
    }
    cout<<a[n-k]<<endl;
    for(i=0; i<k; i++){
        cout<<c[i]<<" ";
    }
    return 0;
}


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


#include<bits/stdc++.h>
using namespace std;
int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n,k,i,j,l;
    cin>>n>>k;
    int a[n],b[n],c[k];
    for(i=0; i<n; i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+n);
    for(i=n-k,l=0; i<n; i++,l++)
    {
        for(j=0; j<n; j++)
        {
            if(a[i]==b[j])
            {
                c[l]=j+1;
                b[j]=-1;
                break;
            }
        }
    }
    cout<<a[n-k]<<endl;
    for(i=0; i<k; i++){
        cout<<c[i]<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int n,k,i,j,l;
    cin>>n>>k;
    int a[n],b[n],c[k];
    for(i=0; i<n; i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(a,a+n);
    for(i=n-k,l=0; i<n; i++,l++)
    {
        for(j=0; j<n; j++)
        {
            if(a[i]==b[j] & b[j]!=0)
            {
                c[l]=j+1;
                b[j]=0;
            }
        }
    }
    cout<<a[n-k]<<endl;
    for(i=0; i<k; i++){
        cout<<c[i]<<" ";
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <algorithm>
#include <fstream>

using namespace std;

int main()
{int n,k,num,i;
	freopen("input.txt","r", stdin);
	freopen("ouput.txt","w", stdout);

	cin>>n>>k;

	vector<int> a;

	for(i=0; i<n; i++)
	{
		cin>>num;
		a.push_back(num);
	}

	vector<int> vec(a);

	sort(vec.begin(),vec.end(),greater<int>());

	//for(i=0; i<n; i++)
	//	cout<<vec[i]<<" ";

	num = vec[k-1];

	cout<<num<<endl;

	for(i=0; i<n && k>0; i++)
	{ //cout<<"k:"<<k;
		if(a[i] >= num)
			{cout<<i+1<<" ";
			k--;
			}

	}
	//cout<<endl;

}


#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
	int n,k,num,i;

	freopen("input.txt","r", stdin);
	freopen("ouput.txt","w", stdout);

	scanf("%d %d", &n, &k);

	vector<int> a;

	for(i=0; i<n; i++)
	{
		scanf("%d", &num);
		a.push_back(num);
	}

	vector<int> vec = a;

	sort(vec.begin(),vec.end(),greater<int>());

	//for(i=0; i<n; i++)
	//	cout<<vec[i]<<" ";

	num = vec[k-1];

	printf("%d\n", num);

	for(i=0; i<n && k>0; i++)
	{ //cout<<"k:"<<k;
		if(a[i] >= num)
			{printf("%d ", i+1);
			k--;
			}

	}
	printf("\n");

return 0;

}


#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

int main()
{
	int n,k,num,i;

	freopen("input.txt","r", stdin);
	freopen("ouput.txt","w", stdout);

	//printf("Hello");

	scanf("%d %d", &n, &k);

	vector <int> a;

	for(i=0; i<n; i++)
	{
		scanf("%d", &num);
		a.push_back(num);
	}

	vector <int> vec = a;

	sort(vec.begin(),vec.end(),greater<int>());

	//for(i=0; i<n; i++)
	//	cout<<vec[i]<<" ";

	num = vec[k-1];

	printf("%d\n", num);

	for(i=0; i<n && k>0; i++)
	{ //cout<<"k:"<<k;
		if(a[i] >= num)
			{printf("%d", i+1);
			k--;
			if(k == 0) printf("\n"); else printf(" ");
			}

	}
	printf("\n");

return 0;

}


#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <climits>
#include <fstream>

using namespace std;

struct comp
{
    bool operator () (const pair <int,int> &a, const pair <int,int> &b)
    {
        if (a.first > b.first)
            return true;
        else
            return false;
    }
};

int main (void)
{
    int n,k;
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    vector<pair<int,int> > myvec;
    int temp;
    int foo = 1;
    int bar = k;
    cin>>n>>k;
    while (foo <= n)
    {
        cin>>temp;
        myvec.push_back(make_pair(temp,foo));
        foo++;
    }
    sort(myvec.begin(),myvec.end(),comp());
    //reverse(myvec.begin(),myvec.end());
    int val = INT_MAX;
    vector<int> myvec1;
    auto it = myvec.begin();
    int z = 0;
    while (it != myvec.end() && z < k)
    {
        if (it->first < val)
            val = it->first;
        temp = it->second;
        myvec1.push_back(temp);
        it++;
        z++;
    }
    sort(myvec1.begin(),myvec1.end());
    cout<<val<<"\n";
    auto it1 = myvec1.begin();
    while (it1 != myvec1.end())
    {
        cout<<*it1<<"\t";
        it1++;
    }
    cout<<"\n";
    return 0;
}