#include <bits/stdc++.h>
using namespace std;
string s, s1;
int main() {
  int n;
  scanf("%d", &n);
  while (n--) {
    cin >> s >> s1;
    if (s < s1)
      cout << s << endl;
    else {
      int len = s.size();
      int id, f = 0;
      for (int i = 0; i < len; i++) {
        int tt = s[i];
        for (int j = len - 1; j > i; j--) {
          if (tt > s[j]) {
            tt = s[j];
            f = 1;
            id = j;
          }
        }
        if (f) {
          swap(s[i], s[id]);
          break;
        }
      }
      if (s < s1)
        cout << s << endl;
      else
        cout << "---" << endl;
    }
  }
}
