#include <bits/stdc++.h>
using namespace std;
const int N = 6010;
const int mod = 1000000007;
int n, len1, len2;
long long k[N], k2[N];
char asd[N], asd2[N];
int main() {
  scanf("%s", asd);
  getchar();
  scanf("%s", asd2);
  len2 = n = ((int)(strlen(asd2))), len1 = ((int)(strlen(asd)));
  long long res = 0;
  for (int i = 0; i < len1; i++) {
    for (int j = 0; j < len2; j++) {
      if (asd2[j] == asd[i]) {
        k2[j] = (k2[j] + k[j - 1] + 1) % mod;
      }
      k2[j + 1] = (k2[j + 1] + k2[j]) % mod;
    }
    res = (res + k2[n]) % mod;
    for (int j = 0; j < len2; j++) k[j] = k2[j];
    memset(k2, 0, sizeof k2);
  }
  cout << res << endl;
  return 0;
}
