#include <bits/stdc++.h>
using namespace std;
void reduce(int &x) {
  if (x >= 1000000007) x -= 1000000007;
  if (x < 0) x += 1000000007;
}
char tmp[5010];
int a[5010], b[5010];
int f[5010][2][5010];
int n, m, ans;
int main() {
  scanf("%s\n", tmp);
  n = strlen(tmp);
  for (int i = 0; i < n; i++) a[i + 1] = tmp[i] - 'a';
  scanf("%s\n", tmp);
  m = strlen(tmp);
  for (int i = 0; i < m; i++) b[i + 1] = tmp[i] - 'a';
  for (int i = 1; i <= n; i++)
    for (int k = 0; k < 2; k++)
      for (int j = 1; j <= m; j++) {
        if (k == 0) {
          if (a[i] == b[j]) {
            f[i][k][j] = f[i - 1][0][j - 1] + 1;
            reduce(f[i][k][j]);
          }
          f[i][k][j] = f[i][k][j] + f[i][0][j - 1];
          reduce(f[i][k][j]);
        }
        if (k == 1) {
          f[i][k][j] = f[i - 1][0][j] + f[i - 1][1][j];
          reduce(f[i][k][j]);
        }
      }
  ans = f[n][0][m] + f[n][1][m];
  reduce(ans);
  cout << ans << endl;
}
