#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
const long long INF = 1e18;
void rua() {
  string a, b;
  cin >> a >> b;
  if (a < b) {
    cout << a << endl;
    return;
  }
  for (int i = 0; i < a.length(); i++) {
    int c = i;
    for (int j = a.length() - 1; j > i; j--)
      if (a[j] < a[c]) c = j;
    if (c != i) {
      swap(a[i], a[c]);
      break;
    }
  }
  if (a < b)
    cout << a << endl;
  else
    cout << "---" << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) rua();
  return 0;
}
