#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 10;
long long res, ex, g[maxn];
int n, m, c[maxn], f[maxn], cnt[30], times = 1, d[30];
char ch;
string s, t;
map<string, bool> M;
void trau() {
  for (int i = 1; i <= n; i++) c[i] = i;
  while (next_permutation(c + 1, c + n + 1))
    ;
  do {
    string tg = "";
    for (int i = 1; i <= n; i++) tg += s[c[i] - 1];
    if (tg < t && tg > s) {
      if (!M[tg]) {
        res++;
        M[tg] = 1;
      }
    }
  } while (next_permutation(c + 1, c + n + 1));
  cout << res;
}
long long Pow(int a, int n) {
  if (n == 0) return 1;
  if (n == 1) return a;
  long long x = Pow(a, n / 2);
  x = (x * x) % mod;
  if (n % 2) return (x * a) % mod;
  return x;
}
long long pw(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    x = (x * x) % mod;
    y /= 2;
  }
  return res;
}
long long xl(string x) {
  for (int i = 0; i <= n - 1; i++) cnt[s[i] - 'a'] = d[s[i] - 'a'];
  long long res = 0, sum, ex = 1;
  for (int i = 0; i <= n - 1; i++) {
    int c = x[i] - 'a';
    sum = 0;
    for (int j = 1; j <= c; j++) sum += cnt[j - 1];
    res = (res + sum * f[n - i - 1] % mod * ex % mod) % mod;
    if (!cnt[c]) break;
    ex = ex * cnt[c] % mod;
    cnt[c]--;
  }
  for (int i = 0; i <= 25; i++) res = (res * pw(f[d[i]], mod - 2)) % mod;
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s >> t;
  n = s.size();
  for (int i = 0; i <= n - 1; i++) d[s[i] - 'a']++;
  f[0] = f[1] = 1;
  for (int i = 2; i <= n; i++) f[i] = (1LL * f[i - 1] * i) % mod;
  cout << ((xl(t) - xl(s) - 1) % mod + mod) % mod;
}
