#include <bits/stdc++.h>
using namespace std;
string a, b;
long long f[(int)1e6 + 5];
long long inv[(int)1e6 + 5];
long long power(long long a, long long k) {
  long long ans = 1;
  long long tmp = a % (long long)1000000007;
  while (k > 0) {
    if (k % 2 == 1) ans = ans * tmp % (long long)1000000007;
    tmp = tmp * tmp % (long long)1000000007;
    k >>= 1;
  }
  return ans;
}
void fact() {
  f[0] = 1;
  for (int i = 1; i < 1e6 + 5; i++)
    f[i] = (f[i - 1] * i) % (long long)1000000007;
  inv[(int)1e6 + 5 - 1] = power(f[(int)1e6 + 5 - 1], (long long)1000000007 - 2);
  for (int i = 1e6 + 5 - 2; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % (long long)1000000007;
}
long long getcount(long long x[], string y, long long n) {
  long long cnt = 0;
  for (int i = 0; i < y.length(); i++) {
    int p = y[i] - 97;
    long long k = f[n];
    for (int j = 0; j < 26; j++)
      k = (k % (long long)1000000007 * inv[x[j]] % (long long)1000000007) %
          (long long)1000000007;
    for (int j = 0; j < p; j++) {
      if (x[j] == 0) continue;
      long long q = (k % (long long)1000000007 * x[j] % (long long)1000000007) %
                    (long long)1000000007;
      cnt = (cnt % (long long)1000000007 + q % (long long)1000000007) %
            (long long)1000000007;
    }
    n--;
    if (x[p] == 0) break;
    x[p]--;
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  fact();
  cin >> a >> b;
  long long ca[26];
  long long cb[26];
  memset(ca, 0, sizeof(ca));
  memset(cb, 0, sizeof(cb));
  for (int i = 0; i < a.length(); i++) ca[a[i] - 97]++;
  for (int i = 0; i < b.length(); i++) cb[b[i] - 97]++;
  long long x = getcount(ca, b, a.length() - 1);
  memset(ca, 0, sizeof(ca));
  for (int i = 0; i < a.length(); i++) ca[a[i] - 97]++;
  long long y = getcount(ca, a, a.length() - 1);
  long long ans = (x % (long long)1000000007 - y % (long long)1000000007 +
                   (long long)1000000007) %
                  (long long)1000000007;
  ans = (ans - 1 + (long long)1000000007) % (long long)1000000007;
  cout << ans;
  return 0;
}
