#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int T;
char s[N], t[N];
int idx[N];
char minc[N];
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%s%s", s, t);
    int n = strlen(s), id = n - 1;
    char c = s[n - 1];
    for (int i = n - 1; i >= 0; i--) {
      if (c > s[i]) c = s[i], id = i;
      minc[i] = c;
      idx[i] = id;
    }
    for (int i = 0; i < n; i++)
      if (minc[i] != s[i]) {
        swap(s[i], s[idx[i]]);
        break;
      }
    if (strcmp(s, t) < 0)
      puts(s);
    else
      puts("---");
  }
  return 0;
}
