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