#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e6;
int N;
string a, b;
int ctA[26], ctB[26];
long long fact[mxN + 5];
long long invMemo[mxN + 5];
long long multicopy = 1;
long long inv(long long a, long long b) {
  return 1 < a ? b - inv(b % a, a) * b / a : 1;
}
long long solve(string x) {
  int ctLeft[26] = {};
  for (char c : a) ctLeft[c - 'a']++;
  long long mult = multicopy;
  long long ret = 0;
  for (int i = 0; i < N; i++) {
    int c = x[i] - 'a';
    mult = (mult * inv(N - i, 1000000007)) % 1000000007;
    for (int j = 0; j < c; j++) {
      if (ctLeft[j] == 0) continue;
      ret = (ret + (mult * ctLeft[j]) % 1000000007) % 1000000007;
    }
    if (ctLeft[c] == 0) break;
    mult = (mult * ctLeft[c]) % 1000000007;
    ctLeft[c]--;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  fact[0] = 1;
  for (long long i = 1; i < mxN + 5; i++)
    fact[i] = (fact[i - 1] * i) % 1000000007;
  cin >> a >> b;
  N = a.size();
  int ctLeft[26] = {};
  for (char c : a) ctLeft[c - 'a']++;
  multicopy = fact[N];
  for (int i = 0; i < 26; i++)
    multicopy = (multicopy * (inv(fact[ctLeft[i]], 1000000007))) % 1000000007;
  for (char c : a) ctA[c - 'a']++;
  for (char c : b) ctB[c - 'a']++;
  long long numA = solve(a), numB = solve(b);
  long long ans = (numB - numA + 1000000007) % 1000000007;
  ans = (ans - 1 + 1000000007) % 1000000007;
  cout << ans << endl;
  return 0;
}
