#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 1000 + 2, mod = 1LL * 1000 * 1000 * 1000 + 7;
int fact[N], factRev[N], cnt[30], n;
string s, t;
int Pow(int a, int b) {
  return b ? 1LL * (b & 1 ? a : 1) % mod * Pow(1LL * a * a % mod, b >> 1) % mod
           : 1;
}
void pre() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) fact[i] = 1LL * fact[i - 1] * i % mod;
  factRev[N - 1] = Pow(fact[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    factRev[i] = 1LL * factRev[i + 1] * (i + 1) % mod;
}
int Less(string &t) {
  int L = 1;
  for (int i = 0; i < 26; i++) cnt[i] = 0;
  for (int i = 0; i < n; i++) cnt[s[i] - 'a']++;
  for (int i = 0; i < n; i++) {
    int tmp = fact[n - i - 1];
    for (int j = 0; j < 26; j++) tmp = 1LL * tmp * factRev[cnt[j]] % mod;
    for (int j = 0; j < t[i] - 'a'; j++)
      if (cnt[j]) {
        tmp = 1LL * tmp * fact[cnt[j]] % mod;
        cnt[j]--;
        (L += 1LL * tmp * factRev[cnt[j]] % mod) %= mod;
        cnt[j]++;
        tmp = 1LL * tmp * factRev[cnt[j]] % mod;
      }
    if (!cnt[t[i] - 'a']) return L;
    cnt[t[i] - 'a']--;
  }
  return L;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  pre();
  cin >> s >> t;
  n = s.size();
  cout << ((Less(t) - Less(s) - 1) % mod + mod) % mod << '\n';
  return 0;
}
