#include <bits/stdc++.h>
using namespace std;
inline void R(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
void Redirect() {
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
}
const int mod = 1e9 + 7;
char a[1000500], b[1004000];
int frac[1000500];
int inv[1000500];
int cnt[26];
int n;
int l = 1;
long long qpow(long long b, long long k) {
  long long ret = 1;
  while (k) {
    if (k & 1) ret = ret * b % mod;
    b = b * b % mod;
    k >>= 1;
  }
  return ret;
}
long long Calc(char s[]) {
  memset(cnt, 0, sizeof cnt);
  for (int i = 1; i <= n; i += 1) cnt[a[i] - 'a']++;
  long long comb = frac[n];
  for (int i = 0; i <= 25; i += 1) comb = comb * inv[cnt[i]] % mod;
  long long ret = 0;
  for (int i = 1; i <= n; ++i) {
    comb = comb * qpow(n + 1 - i, mod - 2) % mod;
    for (int j = 0; j < (s[i] - 'a'); ++j) {
      if (cnt[j]) ret = (ret + comb * cnt[j] % mod) % mod;
    }
    comb = comb * cnt[s[i] - 'a'] % mod;
    cnt[s[i] - 'a']--;
    if (cnt[s[i] - 'a'] < 0) return ret;
  }
  cerr << ret << endl;
  return ret;
}
int main() {
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  n = strlen(a + 1);
  frac[0] = 1;
  for (int i = 1; i <= n; ++i) {
    frac[i] = (long long)frac[i - 1] * i % mod;
  }
  inv[n] = qpow(frac[n], mod - 2);
  for (int i = n; i; --i) {
    inv[i - 1] = (long long)inv[i] * i % mod;
  }
  long long ans = Calc(b) - Calc(a);
  ans = (ans - 1 + mod) % mod;
  printf("%d\n", ans);
}
