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