#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1 >> s2;
    int n1 = s1.length();
    int n2 = s2.length();
    if (s1 < s2)
      cout << s1;
    else {
      for (int i = 0; i < n1 - 1; i++) {
        char c = s1[i];
        int pos = i;
        for (int j = i + 1; j < n1; j++) {
          if (s1[j] <= c) {
            pos = j;
            c = s1[j];
          }
        }
        if (c != s1[i]) {
          swap(s1[pos], s1[i]);
          break;
        }
      }
      int pos = 1;
      if (s1 < s2) {
        cout << s1;
      } else
        cout << "---";
    }
    cout << "\n";
  }
}
