#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long fp(long long base, long long exp) {
  long long t;
  if (exp == 0) return 1;
  return (exp % 2 == 1 ? (base * fp(base, exp - 1)) % mod
                       : (t * (t = fp(base, exp / 2))) % mod);
}
int cnt[130];
long long get_fac(int n) {
  long long res = 1;
  for (int i = 2; i <= n; i++) {
    res = (res * i) % mod;
  }
  return res;
}
long long getres(string a, string k) {
  long long res = 0;
  fill(cnt, cnt + 130, 0);
  for (int i = 0; i < a.length(); i++) cnt[a[i]]++;
  long long mtplr = 1;
  mtplr *= get_fac(a.length());
  for (int i = 'a'; i <= 'z'; i++) {
    if (cnt[i] == 0) continue;
    long long dvdnd = get_fac(cnt[i]);
    mtplr = (mtplr * fp(dvdnd, mod - 2)) % mod;
  }
  for (int i = 0; i < a.length(); i++) {
    long long sum = 0, j = 'a';
    while (j <= 'z' && j < k[i]) {
      sum += cnt[j];
      j++;
    }
    long long addid = (mtplr * sum) % mod;
    addid = (addid * fp(a.length() - i, mod - 2)) % mod;
    res = (res + addid) % mod;
    if (cnt[k[i]] <= 0) break;
    cnt[k[i]]--;
    mtplr = (mtplr * (cnt[k[i]] + 1)) % mod;
    mtplr = (mtplr * fp(a.length() - i, mod - 2)) % mod;
  }
  return res;
}
int main() {
  string a, b;
  getline(cin, a);
  getline(cin, b);
  long long res = getres(a, b) - getres(a, a) - 1;
  cout << (res + mod) % mod;
}
