#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
const int maxn = 5010;
char ss[maxn], cc[maxn];
int t;
int dp[maxn];
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%s%s", ss + 1, cc + 1);
    int n = strlen(ss + 1);
    int m = strlen(cc + 1);
    dp[n] = n;
    for (int i = n - 1; i >= 1; i--) {
      if (ss[i] < ss[dp[i + 1]])
        dp[i] = i;
      else
        dp[i] = dp[i + 1];
    }
    for (int i = 1; i <= n; i++)
      if (ss[i] == ss[dp[i]]) dp[i] = i;
    for (int i = 1; i <= n; i++)
      if (dp[i] != i) {
        char temp;
        temp = ss[dp[i]];
        ss[dp[i]] = ss[i];
        ss[i] = temp;
        break;
      }
    int tmp = min(n, m);
    int flag = 0;
    for (int i = 1; i <= tmp; i++)
      if (ss[i] > cc[i]) {
        flag = -1;
        break;
      } else if (ss[i] < cc[i]) {
        flag = 1;
        break;
      }
    if (flag == -1) {
      printf("---\n");
      continue;
    }
    if (flag == 1) {
      printf("%s\n", ss + 1);
      continue;
    }
    if (n < m) {
      printf("%s\n", ss + 1);
      continue;
    }
    printf("---\n");
  }
}
