#include <bits/stdc++.h>
using namespace std;
int e[5010][5010] = {};
int main() {
  string s, t;
  long long cnt, sum = 0;
  cin >> s >> t;
  for (int i = 0; i < s.length(); i++) e[0][i + 1] = s[i] - 'a';
  for (int i = 0; i < t.length(); i++) e[i + 1][0] = t[i] - 'a';
  for (int r = 1; r <= t.length(); r++)
    if (e[0][1] == e[r][0]) {
      e[r][1]++;
      sum++;
    }
  for (int c = 2; c <= s.length(); c++) {
    cnt = 0;
    for (int r = 1; r <= t.length(); r++) {
      if (e[0][c] == e[r][0]) {
        e[r][c] = cnt + 1;
        sum = (sum + e[r][c]) % 1000000007LL;
      }
      cnt = (cnt + e[r][c - 1]) % 1000000007LL;
    }
  }
  cout << sum << endl;
}
