#include <bits/stdc++.h>
using namespace std;
const int oo = 0x7fffffff;
const long long OO = 0x7fffffffffffffff;
using namespace std;
template <class T>
T pow(T a, int p) {
  T r(1);
  while (p) {
    if (p % 2) r *= a;
    a *= a;
    p /= 2;
  }
  return r;
}
class mint {
 public:
  const static int MOD;
  int x;
  mint() : x(0) {}
  mint(int _x) : x(_x) {}
  mint(const mint& that) : x(that.x) {}
  mint& operator=(const mint& that) {
    x = that.x;
    return *this;
  }
  mint& operator+=(const mint& that) {
    x = (x + that.x) % MOD;
    return *this;
  }
  const mint& operator++() { return x = (x + 1) % MOD, *this; }
  const mint& operator--() { return x = (MOD + x - 1) % MOD, *this; }
  const mint operator++(int) {
    mint temp(*this);
    return x = (x + 1) % MOD, temp;
  }
  const mint operator--(int) {
    mint temp(*this);
    return x = (x + MOD - 1) % MOD, temp;
  }
  mint& operator-=(const mint& t) { return x = (MOD + x - t.x) % MOD, *this; }
  mint& operator*=(const mint& t) { return x = (x * 1LL * t.x) % MOD, *this; }
  mint inverse() const {
    if (x == 1) return *this;
    return pow(*this, mint::MOD - 2);
  }
  mint& operator/=(const mint& that) {
    x = (x * 1LL * (that.inverse()).x) % MOD;
    return *this;
  }
  mint operator+(const mint& that) const { return mint(*this) += that; }
  mint operator-(const mint& that) const { return mint(*this) -= that; }
  mint operator*(const mint& that) const { return mint(*this) *= that; }
  mint operator/(const mint& that) const { return mint(*this) /= that; }
};
const int mint::MOD = 1e9 + 7;
ostream& operator<<(ostream& os, const mint& that) { return os << that.x; }
template <class T>
bool sorted(T first, T last) {
  auto a = *first;
  for (++first; first != last; first++) {
    auto b = *first;
    if (a > b) return false;
    a = b;
  }
  return true;
}
string lower_bound_permutation(string& A, string& B) {
  vector<int> ct(256, 0);
  string T(B);
  for (auto c : A) ct[c]++;
  int p(0);
  for (; p < T.size(); p++)
    if (ct[T[p]] > 0)
      ct[T[p]]--;
    else
      break;
  if (p == T.size()) return T;
  char down, up;
  for (down = T[p]; down >= 'a' && ct[down] == 0; down--)
    ;
  for (up = T[p]; up <= 'z' && ct[up] == 0; up++)
    ;
  if (down >= 'a') {
    T[p] = down;
    ct[T[p++]]--;
    for (; p < T.size(); p++) {
      char& c = T[p];
      for (c = 'z'; ct[c] == 0; c--)
        ;
      ct[c]--;
    }
  } else {
    T[p] = up;
    ct[T[p++]]--;
    for (; p < T.size(); p++) {
      char& c = T[p];
      for (c = 'a'; ct[c] == 0; c++)
        ;
      ct[c]--;
    }
    if (!sorted(T.begin(), T.end())) prev_permutation(T.begin(), T.end());
  }
  return T;
}
template <class INT>
INT index_of_permutation(string& S) {
  INT ans(0), M = 1;
  vector<int> ct(256, 0);
  for (int i = 1; i <= S.size(); i++) {
    char c = S[S.size() - i];
    M /= INT(++ct[c]);
    for (char a = 'a'; a < c; a++) ans += M * INT(ct[a]);
    M *= INT(i);
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  vector<int> ct(256, 0);
  string A, B, temp;
  cin >> A >> B;
  temp = lower_bound_permutation(A, B);
  mint ans = index_of_permutation<mint>(temp) - index_of_permutation<mint>(A);
  if (temp == B) ans--;
  cout << ans << "\n";
  return 0;
}
