#include <bits/stdc++.h>
using namespace std;
char s[6000], t[6000];
long long ans;
int T, S;
long long sum[6000], p[6000];
int main() {
  cin >> s;
  cin >> t;
  S = strlen(s);
  T = strlen(t);
  for (int i = 1; i <= S; ++i) {
    for (int j = 0; j <= T; ++j) p[j] = 0;
    for (int j = 1; j <= T; ++j)
      if (s[i - 1] == t[j - 1]) {
        ans += sum[j - 1] + 1;
        if (ans > 1000000007) ans -= 1000000007;
        p[j] = sum[j - 1] + 1;
      }
    for (int j = 1; j <= T; ++j) {
      sum[j] = sum[j - 1] + p[j];
      if (sum[j] > 1000000007) sum[j] -= 1000000007;
    }
  }
  cout << ans << endl;
  return 0;
}
