#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n;
long long int dn[6010], dinamik2[6010];
int main() {
  string ar;
  string ar2;
  cin >> ar;
  cin >> ar2;
  n = ((int)(ar2.size()));
  long long res = 0;
  for (int k = 0; k < ((int)(ar.size())); k++) {
    for (int j = 0; j < ((int)(ar2.size())); j++) {
      if (ar2[j] == ar[k]) dinamik2[j] = (dinamik2[j] + dn[j - 1] + 1) % MOD;
      dinamik2[j + 1] = (dinamik2[j + 1] + dinamik2[j]) % MOD;
    }
    res = (res + dinamik2[n]) % MOD;
    for (int j = 0; j < ((int)(ar2.size())); j++) dn[j] = dinamik2[j];
    memset(dinamik2, 0, sizeof dinamik2);
  }
  cout << res << endl;
  return 0;
}
