#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long int a, b, c, d, i, k, j;
  cin >> a;
  for (i = 0; i < a; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    long long int l1, l2;
    l1 = s1.length();
    l2 = s2.length();
    long long int st = 0;
    long long int ans = 0;
    for (j = 0; j < l1; j++) {
      char mi = s1[j];
      long long int p = j;
      for (k = j + 1; k < l1; k++) {
        if (mi >= s1[k]) {
          p = k;
          mi = s1[k];
        }
      }
      if (mi < s1[j]) {
        swap(s1[j], s1[p]);
        break;
      }
    }
    if (s1 < s2)
      cout << s1 << "\n";
    else
      cout << "---"
           << "\n";
  }
}
