#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10, p = 1e9 + 7;
int n, cnt[26], inv[N], fac[N], finv[N];
char a[N], b[N];
inline int solve(char *s) {
  int ans = 0, noans = fac[n];
  memset(cnt, 0, sizeof cnt);
  for (int i = 1; i <= n; ++i) ++cnt[a[i] - 'a'];
  for (int i = 0; i < 26; ++i) noans = 1ll * noans * finv[cnt[i]] % p;
  for (int i = 1; i <= n; ++i) {
    int v = s[i] - 'a';
    noans = 1ll * noans * inv[n - i + 1] % p;
    for (int c = 0; c < v; ++c)
      if (cnt[c]) {
        noans = 1ll * noans * cnt[c] % p;
        ans = (ans + noans) % p;
        noans = 1ll * noans * inv[cnt[c]] % p;
      }
    if (!cnt[v]) return ans;
    noans = 1ll * noans * cnt[v] % p;
    --cnt[v];
  }
  return ans;
}
int main() {
  scanf("%s%s", a + 1, b + 1);
  n = strlen(a + 1);
  fac[0] = 1;
  for (int i = 1; i <= n; ++i) fac[i] = 1ll * fac[i - 1] * i % p;
  inv[0] = inv[1] = 1;
  for (int i = 2; i <= n; ++i) inv[i] = 1ll * inv[p % i] * (p - p / i) % p;
  finv[0] = 1;
  for (int i = 1; i <= n; ++i) finv[i] = 1ll * inv[i] * finv[i - 1] % p;
  printf("%d", (solve(b) - solve(a) - 1 + p) % p);
  return 0;
}
