#include <bits/stdc++.h>
char S[5010], T[5010];
short next[5010][5010];
bool visited[5010][5010];
int n, m, dp[5010][5010];
int F(int i, int j) {
  if (i >= n || j >= m) return 0;
  if (visited[i][j]) return dp[i][j];
  unsigned int res = 0;
  if (next[i][j] != -1) {
    res = res + F(i + 1, next[i][j] + 1) + 1;
    if (res >= 1000000007) res -= 1000000007;
    res = res + F(i, next[i][j] + 1);
    if (res >= 1000000007) res -= 1000000007;
  }
  visited[i][j] = true;
  return (dp[i][j] = res);
}
int main() {
  int i, j, k;
  while (scanf("%s %s", S, T) != EOF) {
    memset(visited, 0, sizeof(visited));
    n = strlen(S), m = strlen(T);
    for (i = 0; i < n; i++) {
      for (j = m - 1; j >= 0; j--) {
        next[i][j] = -1;
        if (S[i] == T[j])
          next[i][j] = j;
        else if ((j + 1) != m)
          next[i][j] = next[i][j + 1];
      }
    }
    long long res = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (S[i] == T[j]) {
          res = res + F(i + 1, j + 1) + 1;
        }
      }
    }
    printf("%lld\n", res % 1000000007);
  }
  return 0;
}
