#include <bits/stdc++.h>
int min(int a, int b) {
  if (a <= b)
    return a;
  else
    return b;
}
int main() {
  int i, j, m, n, l, l1, l2, det, x, y, det2, possible, same;
  char str[5005], str1[5005], c, d, pri;
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%s%s", str, str1);
    l1 = strlen(str);
    l2 = strlen(str1);
    for (j = 0; j < l1; j++) {
      c = str[j];
      y = j;
      for (x = l1 - 1; x > j; x--) {
        if (str[x] < c) {
          c = str[x];
          y = x;
        }
      }
      if (y != j) {
        pri = str[j];
        d = str[y];
        str[y] = pri;
        str[j] = d;
        break;
      }
    }
    if (strcmp(str, str1) < 0)
      printf("%s\n", str);
    else
      printf("---\n");
  }
  return 0;
}
