#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const double EPS = 1e-6;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int tt = 0; tt < t; ++tt) {
    string a, b;
    cin >> a >> b;
    char s[5001]{}, t[5001]{};
    strcpy(s, a.c_str());
    strcpy(t, b.c_str());
    for (int i = 0; i < a.length(); ++i) {
      char best = s[i];
      int bi = i;
      for (int j = a.length() - 1; j > i; --j) {
        if (s[j] < best) {
          best = s[j];
          bi = j;
        }
      }
      if (bi != i) {
        char temp = s[i];
        s[i] = s[bi];
        s[bi] = temp;
        break;
      }
    }
    if (string(s).compare(b) < 0) {
      cout << string(s) << '\n';
    } else {
      cout << "---\n";
    }
  }
  return 0;
}
