#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e6 + 10, mod = 1e9 + 7;
string a, b;
long long cnt[30], fact[maxn];
pair<long long, long long> gcd(long long a, long long b) {
  if (b == 0) return make_pair(a, 0);
  pair<long long, long long> p = gcd(b, a % b);
  return make_pair(p.second, p.first - ((a / b) * p.second));
}
long long varoon(long long a) {
  return (((gcd(a, mod).first) % mod) + mod) % mod;
}
long long safe(long long a, long long b, long long c) {
  return (((a * b) % mod) * c) % mod;
}
long long f(string &st) {
  long long ans = 0;
  long long tot = fact[a.size()];
  for (long long i = 0; i < 26; i++) cnt[i] = 0;
  for (long long i = 0; i < a.size(); i++) cnt[a[i] - 'a']++;
  for (long long i = 0; i < 26; i++) tot = (tot * varoon(fact[cnt[i]])) % mod;
  for (long long i = 0; i < st.size(); i++) {
    long long N = varoon(a.size() - i);
    for (long long j = 0; j < st[i] - 'a'; j++) {
      if (cnt[j] == 0) continue;
      ans += safe(tot, N, cnt[j]);
      ans %= mod;
    }
    if (cnt[st[i] - 'a'] == 0) break;
    tot = safe(tot, N, cnt[st[i] - 'a']);
    cnt[st[i] - 'a']--;
  }
  return ((ans % mod) + mod) % mod;
}
int main() {
  fact[0] = 1;
  for (long long i = 1; i < maxn; i++) fact[i] = (fact[i - 1] * i) % mod;
  cin >> a >> b;
  cout << (((f(b) - f(a) - 1) % mod) + mod) % mod;
}
