#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e6 + 9, mod = (int)1e9 + 7;
int n, cnt[26], f[26];
string a, b, c;
long long fact[N] = {1};
void init() {
  for (int i = 1; i < N; ++i) fact[i] = (fact[i - 1] * i) % mod;
}
long long pw(long long x, int b) {
  long long ans = 1, tmp = x;
  while (b > 0) {
    if (b & 1) (ans *= tmp) %= mod;
    (tmp *= tmp) %= mod;
    b >>= 1;
  }
  return ans;
}
int calc(string str) {
  for (int i = 0; i < 26; ++i) f[i] = cnt[i];
  long long ans = 0, k = 1, p;
  for (int i = 0, cur; i < n; ++i) {
    cur = str[i] - 'a';
    p = 0;
    for (int j = 0; j < cur; ++j) p += f[j];
    (p *= fact[n - i - 1]) %= mod;
    (p *= k) %= mod;
    (ans += p) %= mod;
    if (f[cur] == 0) break;
    (k *= f[cur]) %= mod;
    --f[cur];
  }
  for (int i = 0; i < 26; ++i) ans = pw(fact[cnt[i]], mod - 2) * ans % mod;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  init();
  cin >> a >> b;
  n = a.size();
  for (char c : a) ++cnt[c - 'a'];
  int ans = calc(b) - calc(a) - 1;
  if (ans < 0) ans += mod;
  cout << ans;
}
