#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1 >> s2;
    long long i, j, x;
    long long m = s1.size();
    for (i = 0; i < m; i++) {
      x = i;
      for (j = m - 1; j > i; j--) {
        if (s1[j] < s1[x]) {
          x = j;
        }
      }
      if (x != i) {
        swap(s1[x], s1[i]);
        break;
      }
    }
    if (s1 < s2) {
      cout << s1 << endl;
    } else {
      cout << "---" << endl;
    }
  }
}
