#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
  string s, c;
  cin >> s >> c;
  if (s < c) {
    cout << s << '\n';
    return;
  }
  string qwe = s;
  int n = s.size();
  for (int i = 0; i < int(n); i++) {
    for (int j = i + 1; j < n; j++)
      if (s[i] != s[j]) {
        swap(qwe[i], qwe[j]);
        if (qwe < c) {
          cout << qwe << '\n';
          return;
        }
        swap(qwe[i], qwe[j]);
      }
  }
  cout << "---" << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  for (int i = 0; i < int(q); i++) {
    solve();
  }
}
