#include <bits/stdc++.h>
using namespace std;
long long a, s, d[5002][5002], f[26], g, h, j, k, l, i, n, m, mod = 1000000007;
string x, z;
vector<int> v[26];
int main() {
  cin >> x >> z;
  n = x.size();
  m = z.size();
  for (i = 0; i < m; i++) {
    v[z[i] - 97].push_back(i);
  }
  for (i = 0; i < 26; i++) {
    v[i].push_back(m);
  }
  for (i = 0; i < n; i++) {
    memset(f, 0, sizeof f);
    for (a = 0; a < m; a++) {
      if (x[i] != z[a]) {
        continue;
      }
      d[i][a]++;
      k += d[i][a];
      if (k >= mod) k %= mod;
      if (d[i][a] >= mod) d[i][a] %= mod;
      l = x[i] - 97;
      while (v[l][f[l]] <= a) {
        f[l]++;
      }
      d[i][v[l][f[l]]] += d[i][a] - 1;
      if (i == n - 1) continue;
      l = x[i + 1] - 97;
      while (v[l][f[l]] <= a) {
        f[l]++;
      }
      d[i + 1][v[l][f[l]]] += d[i][a];
    }
  }
  cout << k;
}
