#include <bits/stdc++.h>
int nxt[5005][26];
char st[5005], en[5005];
int dp[5005][5005];
int n, m;
int stg(int p1, int p2) {
  if (p1 == m || p2 == n) return 0;
  if (dp[p1][p2] != -1) return dp[p1][p2];
  dp[p1][p2] = 1;
  dp[p1][p2] += stg(p1, nxt[p2][st[p1] - 'a']);
  if (p1 != m - 1) dp[p1][p2] += stg(p1 + 1, nxt[p2][st[p1 + 1] - 'a']);
  dp[p1][p2] %= 1000000007;
  return dp[p1][p2];
}
FILE* f1 = stdin;
int main() {
  int i, j;
  fscanf(f1, "%s%s", st, en);
  m = strlen(st), n = strlen(en);
  int lst;
  for (i = 0; i < 26; i++) {
    lst = n;
    for (j = n - 1; j >= 0; j--) {
      nxt[j][i] = lst;
      if (en[j] - 'a' == i) lst = j;
    }
  }
  for (i = 0; i < m; i++)
    for (j = 0; j < n; j++) dp[i][j] = -1;
  int sm = 0;
  for (i = 0; i < m; i++) {
    if (st[i] == en[0])
      sm = (sm + stg(i, 0)) % 1000000007;
    else
      sm = (sm + stg(i, nxt[0][st[i] - 'a'])) % 1000000007;
  }
  printf("%d\n", sm);
  scanf("%*d");
}
