#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const double inf = 1e15;
long long int remp[1000005], rems[1000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    string s, c;
    cin >> s >> c;
    long long int ns = s.length();
    long long int nc = c.length();
    bool f = true;
    for (long long int i = 0; i < min(ns, nc); i++) {
      if (s[i] < c[i]) {
        f = false;
        break;
      } else if (s[i] >= c[i]) {
        for (long long int j = i + 1; j < ns; j++) {
          if (s[j] < c[i]) {
            char temp = s[j];
            s[j] = s[i];
            s[i] = temp;
            f = false;
            break;
          }
        }
        if (!f) break;
      }
    }
    if (f)
      cout << "---"
           << "\n";
    else
      cout << s << "\n";
  }
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
  return 0;
}
