#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1 >> s2;
    for (int i = 0; i < s1.length(); i++) {
      char ch = s1[i];
      int ans = i;
      for (int j = i + 1; j < s1.length(); j++) {
        if (s1[j] <= ch) {
          ch = s1[j];
          ans = j;
        }
      }
      if ((ans != i) && (ch != s1[i])) {
        swap(s1[i], s1[ans]);
        break;
      }
    }
    if (s1 < s2)
      cout << s1 << "\n";
    else
      cout << "---\n";
  }
}
