#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-6;
inline void read(long long& x) {
  int f = 1;
  char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-')
    ;
  c == '-' ? (f = -1, x = 0) : (x = c - '0');
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  x *= f;
}
inline void read(int& x) {
  long long t;
  read(t);
  x = t;
}
const int maxn = 1000005;
long long inv[maxn], p[maxn];
char a[maxn], b[maxn];
void CNumberInit(int MAXNUM, long long mod) {
  inv[0] = inv[1] = p[0] = p[1] = 1;
  for (int i = 2; i <= MAXNUM; i++) {
    inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    p[i] = p[i - 1] * i % mod;
  }
  for (int i = 2; i <= MAXNUM; i++) inv[i] = inv[i - 1] * inv[i] % mod;
}
int add(int& x, int y) {
  if ((x += y) >= mod) x -= mod;
}
int cnt1[30], cnt2[30];
int ans, l;
void cal1(int i) {
  int ttmp = 1;
  for (int j = a[i] - 'a' + 1; j < b[i] - 'a'; j++)
    ttmp = 1LL * ttmp * inv[cnt1[j]] % mod;
  int tmp = 1;
  for (int j = 0; j <= a[i] - 'a'; j++) tmp = 1LL * tmp * inv[cnt1[j]] % mod;
  for (int j = b[i] - 'a'; j < 26; j++) tmp = 1LL * tmp * inv[cnt1[j]] % mod;
  for (int j = a[i] - 'a' + 1; j < b[i] - 'a'; j++) {
    if (!cnt1[j]) continue;
    add(ans, p[l - i - 1] * tmp % mod * ttmp % mod * p[cnt1[j]] % mod *
                 inv[cnt1[j] - 1] % mod);
  }
}
void cal2(int i) {
  int ttmp = 1;
  for (int j = a[i] - 'a' + 1; j < 26; j++)
    ttmp = 1LL * ttmp * inv[cnt1[j]] % mod;
  int tmp = 1;
  for (int j = 0; j <= a[i] - 'a'; j++) tmp = 1LL * tmp * inv[cnt1[j]] % mod;
  for (int j = a[i] - 'a' + 1; j < 26; j++) {
    if (!cnt1[j]) continue;
    add(ans, p[l - i - 1] * tmp % mod * ttmp % mod * p[cnt1[j]] % mod *
                 inv[cnt1[j] - 1] % mod);
  }
}
void cal3(int i) {
  int ttmp = 1;
  for (int j = 0; j < b[i] - 'a'; j++) ttmp = 1LL * ttmp * inv[cnt2[j]] % mod;
  int tmp = 1;
  for (int j = b[i] - 'a'; j < 26; j++) tmp = 1LL * tmp * inv[cnt2[j]] % mod;
  for (int j = 0; j < b[i] - 'a'; j++) {
    if (!cnt2[j]) continue;
    add(ans, p[l - i - 1] * tmp % mod * ttmp % mod * p[cnt2[j]] % mod *
                 inv[cnt2[j] - 1] % mod);
  }
}
int main() {
  CNumberInit(1000000, mod);
  scanf("%s%s", a, b);
  l = strlen(a);
  for (int i = 0; i < l; i++) cnt1[a[i] - 'a']++;
  for (int i = 0; i < 26; i++) cnt2[i] = cnt1[i];
  bool fg1 = 0, fg2 = 0, fg3 = 1, fg4 = 1;
  for (int i = 0; i < l; i++) {
    if (!fg1 && !fg2) {
      if (a[i] == b[i]) {
      } else if (a[i] > b[i])
        break;
      else {
        fg1 = 1;
        fg2 = 1;
        cal1(i);
      }
    } else {
      if (fg3) cal2(i);
      if (fg4) cal3(i);
    }
    !fg3 || !cnt1[a[i] - 'a'] ? fg3 = 0 : cnt1[a[i] - 'a']--;
    !fg4 || !cnt2[b[i] - 'a'] ? fg4 = 0 : cnt2[b[i] - 'a']--;
  }
  int pos = -1;
  for (int i = 0; i < l; i++) {
    if (a[i] == b[i]) continue;
    pos = i;
    break;
  }
  if (!(pos == l - 1) && !(ans + 1)) add(ans, mod - 1);
  printf("%d\n", ans);
  return 0;
}
