#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s, c;
    cin >> s >> c;
    if (s < c) {
      cout << s << endl;
      continue;
    }
    int mn = 'Z' + 1;
    int id = -1;
    int ls = -1, ls2 = -1;
    for (int i = s.size() - 1; i >= 0; i--) {
      if (mn < s[i]) {
        ls = i;
        ls2 = id;
      }
      if (s[i] < mn) {
        mn = s[i];
        id = i;
      }
    }
    if (ls == -1) {
      cout << "---" << endl;
      continue;
    }
    swap(s[ls2], s[ls]);
    if (s < c)
      cout << s << endl;
    else
      cout << "---" << endl;
  }
  return 0;
}
