#include <bits/stdc++.h>
using namespace std;
string s, t;
vector<long long int> val[27], pre[27];
long long int update(int cur, int prv) {
  vector<long long int> upd(val[cur].size());
  vector<long long int>& v2 = val[cur];
  vector<long long int>& v1 = val[prv];
  long long int ans = 0;
  int l = (int)v1.size() - 1, r = (int)v2.size() - 1;
  if (r == -1) return 0;
  while (r >= 0) {
    if (l < 0) {
      ans++;
      upd[r] = 1;
      r--;
      continue;
    }
    if (v1[l] < v2[r]) {
      ans += pre[prv][l] + 1;
      upd[r--] = pre[prv][l] + 1;
      continue;
    }
    while (l >= 0 && v1[l] >= v2[r]) l--;
  }
  ans %= 1000000007;
  upd[0] %= 1000000007;
  for (int j = 1; j < (int)upd.size(); j++)
    upd[j] = (upd[j - 1] + upd[j]) % 1000000007;
  pre[cur] = upd;
  return ans;
}
inline void build() {
  cin >> s >> t;
  for (int j = 0; j < (int)t.length(); j++)
    val[t[j] - 'a' + 1].push_back(j), pre[t[j] - 'a' + 1].push_back(0);
}
long long int solve() {
  long long int ans = 0;
  for (int j = 0; j < (int)s.length(); j++) {
    if (j == 0)
      ans = (ans + update((s[j] - 'a' + 1), 0)) % 1000000007;
    else
      ans = (ans + update(s[j] - 'a' + 1, s[j - 1] - 'a' + 1)) % 1000000007;
  }
  return ans;
}
int main() {
  build();
  cout << solve() << endl;
  return 0;
}
