#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    for (int i = 0; i < a.length(); i++) {
      int r = i;
      for (int j = i; j < a.length(); j++) {
        if (a[r] >= a[j]) {
          r = j;
        }
      }
      if (a[r] != a[i]) {
        swap(a[i], a[r]);
        break;
      }
    }
    bool smaller = false;
    bool found = false;
    for (int i = 0; i < min(a.length(), b.length()); i++) {
      if (a[i] < b[i]) {
        found = true;
        smaller = true;
        break;
      } else if (a[i] > b[i]) {
        smaller = false;
        found = true;
        break;
      }
    }
    if (found) {
      if (smaller) {
        cout << a << endl;
      } else {
        cout << "---" << endl;
      }
    } else {
      if (a.length() < b.length()) {
        cout << a << endl;
      } else {
        cout << "---" << endl;
      }
    }
  }
}
