#include <bits/stdc++.h>
using ll = long long;
ll exp(ll a, ll b) {
  if (b == 0) return 1;
  if (b == 1) return a % 1000000007;
  ll result;
  result = exp(a, b / 2);
  result = (result * result) % 1000000007;
  if (b % 2 != 0) result = (result * a) % 1000000007;
  return result;
}
std::unordered_map<ll, ll> inv_cache;
ll div_mod(ll a, ll b) {
  if (inv_cache.count(b) == 0) {
    inv_cache[b] = exp(b, 1000000007 - 2);
  }
  return (a * inv_cache[b]) % 1000000007;
}
ll calc(char str[], ll count[], ll factorial[]) {
  int len = strlen(str);
  ll result = 0;
  ll t = factorial[len];
  for (char chr = 'a'; chr <= 'z'; ++chr) {
    t = div_mod(t, factorial[count[chr]]);
  }
  for (int i = 0; i < len; ++i) {
    char last_char = '\0';
    for (char chr = 'a'; chr <= str[i]; ++chr) {
      if (count[chr] == 0) continue;
      last_char = chr;
      t = div_mod(t, len - i);
      t = (t * (count[chr])) % 1000000007;
      if (chr != str[i]) {
        result = (result + t) % 1000000007;
        t = div_mod(t, count[chr]);
        t = (t * (len - i)) % 1000000007;
      } else {
        --count[chr];
      }
    }
    if (last_char != str[i]) {
      break;
    }
  }
  return result;
}
void precompute_factorial(ll factorial[], int len) {
  factorial[0] = 1;
  for (ll i = 1; i <= len; ++i) {
    factorial[i] = (factorial[i - 1] * i) % 1000000007;
  }
}
char a[1000000 + 1], b[1000000 + 1];
ll factorial[1000000 + 1];
ll count[256];
int main() {
  precompute_factorial(factorial, 1000000 + 1);
  scanf("%s", a);
  scanf("%s", b);
  int len = strlen(a);
  for (int i = 0; i < len; ++i) ++count[a[i]];
  ll b_count = calc(b, count, factorial);
  std::memset(count, 0, sizeof(count));
  for (int i = 0; i < len; ++i) ++count[a[i]];
  ll a_count = calc(a, count, factorial);
  printf("%lld\n", ((b_count - a_count - 1) + 1000000007) % 1000000007);
}
