#include <bits/stdc++.h>
const int mod = 1e9 + 7;
inline int addmod(int a, int b) { return (a + b) % mod; }
inline int mulmod(long long a, int b) { return a * b % mod; }
int extend_gcd(int a, int b, int &x, int &y) {
  int ans;
  if (b == 0)
    x = 1, y = 0, ans = a;
  else {
    ans = extend_gcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
  return ans;
}
inline int revmod(int a) {
  int x, y;
  extend_gcd(a, mod, x, y);
  return (x % mod + mod) % mod;
}
const int maxn = 1e6 + 5;
int fac[maxn], rfac[maxn], rev[maxn];
char a[maxn], b[maxn];
int cnt_[26], len;
int f(char *s) {
  int cnt[26];
  memcpy(cnt, cnt_, sizeof(cnt));
  int cur = fac[len];
  for (int i = 0; i < 26; i++)
    if (cnt[i]) cur = mulmod(cur, rfac[cnt[i]]);
  int res = 0;
  for (int i = 0; i < len; i++) {
    for (int j = 0; j < s[i] - 'a'; j++) {
      int t = mulmod(cur, cnt[j]);
      t = mulmod(t, rev[len - i]);
      res = addmod(res, t);
    }
    if (cnt[s[i] - 'a']) {
      cur = mulmod(cur, cnt[s[i] - 'a']);
      cur = mulmod(cur, rev[len - i]);
      cnt[s[i] - 'a']--;
    } else
      break;
  }
  return res;
}
int main() {
  fac[0] = rfac[0] = 1, rev[0] = 0;
  for (int i = 1; i < maxn; i++) {
    rev[i] = revmod(i);
    fac[i] = mulmod(fac[i - 1], i);
    rfac[i] = mulmod(rfac[i - 1], rev[i]);
  }
  scanf("%s%s", a, b);
  len = strlen(a);
  for (int i = 0; i < len; i++) cnt_[a[i] - 'a']++;
  int ans = addmod(f(b), mod - f(a));
  printf("%d\n", addmod(ans, mod - 1));
  return 0;
}
