#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    string s, t;
    string ss;
    cin >> s >> t;
    if (s >= t) {
      ss = s;
      sort(ss.begin(), ss.end());
      char nows;
      int index = 0, index1 = 0;
      for (int i = 0; i < s.length(); i++) {
        if (s[i] != ss[i]) {
          index = i;
          nows = ss[i];
          break;
        }
      }
      for (int i = index + 1; i < s.length(); i++) {
        if (s[i] == nows) {
          index1 = i;
        }
      }
      swap(s[index], s[index1]);
    }
    if (s >= t) {
      printf("---\n");
    } else {
      cout << s << endl;
    }
  }
}
