#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 23, M = (1 << 20), mod = 1e9 + 7, inf = 3e18;
long long fact[N], total[26], fr[26], dp[27][N];
long long inv(long long id, long long key, long long base, long long pow) {
  if (pow == 0) return 1;
  long long &ret = dp[id][key];
  if (ret) return ret;
  ret = inv(id, key, base, pow / 2);
  ret = (ret * ret) % mod;
  if (pow % 2) ret = (ret * base) % mod;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string second, T;
  cin >> second >> T;
  long long n = second.size();
  fact[0] = 1;
  for (long long i = 1; i <= n; i++)
    fact[i] = (fact[i - 1] * i) % mod, total[second[i - 1] - 'a']++;
  long long ans = 0, flag = 0, mul = fact[n];
  for (long long i = 0; i < 26; i++)
    mul = (mul * inv(i, 0, fact[total[i]], mod - 2)) % mod;
  for (long long i = 0; i < n; i++) {
    long long x = (flag ? 26 : T[i] - 'a'), ch = second[i] - 'a';
    mul = (mul * inv(26, n - i, n - i, mod - 2)) % mod;
    for (long long j = ch + 1; j < x; j++) {
      if (total[j] - fr[j] == 0) continue;
      ans = (ans + (mul * fact[total[j] - fr[j]]) % mod *
                       inv(j, fr[j] + 1, fact[total[j] - fr[j] - 1], mod - 2)) %
            mod;
    }
    if (second[i] < T[i]) flag = 1;
    mul = (mul * fact[total[ch] - fr[ch]]) % mod;
    fr[ch]++;
    mul = (mul * inv(ch, fr[ch], fact[total[ch] - fr[ch]], mod - 2)) % mod;
  }
  memset(fr, 0, sizeof fr);
  flag = 0;
  mul = fact[n - 1];
  for (long long i = 0; i < 26; i++)
    mul = (mul * inv(i, 0, fact[total[i]], mod - 2)) % mod;
  for (long long i = 0; i < n - 1; i++) {
    if (second[i] < T[i]) flag = 1;
    long long x = (flag ? 0 : second[i + 1] - 'a' + 1), ch = T[i] - 'a';
    if (total[ch] - fr[ch] == 0) break;
    mul = (mul * inv(26, n - i - 1, n - i - 1, mod - 2)) % mod;
    mul = (mul * fact[total[ch] - fr[ch]]) % mod;
    fr[ch]++;
    mul = (mul * inv(ch, fr[ch], fact[total[ch] - fr[ch]], mod - 2)) % mod;
    for (long long j = x; j < T[i + 1] - 'a'; j++) {
      if (total[j] - fr[j] == 0) continue;
      ans = (ans + (mul * fact[total[j] - fr[j]]) % mod *
                       inv(j, fr[j] + 1, fact[total[j] - fr[j] - 1], mod - 2)) %
            mod;
    }
  }
  cout << ans << endl;
}
